Skip to content

Commit

Permalink
Merge branch 'master' into impl_vecdot
Browse files Browse the repository at this point in the history
  • Loading branch information
vtavana authored Oct 28, 2024
2 parents 2576446 + 257ee51 commit be88a7c
Show file tree
Hide file tree
Showing 18 changed files with 365 additions and 68 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build-sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ jobs:
- name: Install Intel OneAPI
run: |
sudo apt-get install intel-oneapi-mkl \
intel-oneapi-mkl-devel \
intel-oneapi-tbb-devel \
intel-oneapi-libdpstd-devel \
intel-oneapi-compiler-dpcpp-cpp
sudo apt-get install intel-oneapi-mkl-2024.2* \
intel-oneapi-mkl-devel-2024.2* \
intel-oneapi-tbb-devel-2021.13* \
intel-oneapi-libdpstd-devel-2022.6* \
intel-oneapi-compiler-dpcpp-cpp-2024.2*
# required by sphinxcontrib-spelling extension
- name: Install enchant package
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ env:
test_copy.py
test_counting.py
test_fft.py
test_fill.py
test_flat.py
test_histogram.py
test_indexing.py
Expand Down Expand Up @@ -63,6 +64,7 @@ env:
third_party/cupy/statistics_tests/test_histogram.py
third_party/cupy/statistics_tests/test_meanvar.py
third_party/cupy/test_ndim.py
third_party/cupy/test_type_routines.py
VER_JSON_NAME: 'version.json'
VER_SCRIPT1: "import json; f = open('version.json', 'r'); j = json.load(f); f.close(); "
VER_SCRIPT2: "d = j['dpnp'][0]; print('='.join((d[s] for s in ('version', 'build'))))"
Expand Down Expand Up @@ -142,6 +144,8 @@ jobs:
- name: Build conda package
run: conda build --no-test --python ${{ matrix.python }} --numpy 2.0 ${{ env.CHANNELS }} conda-recipe
env:
MAX_BUILD_CMPL_MKL_VERSION: '2024.3a0'

- name: Upload artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/generate_coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ jobs:
- name: Install latest Intel OneAPI
if: env.INSTALL_ONE_API == 'yes'
run: |
sudo apt-get install intel-oneapi-mkl \
intel-oneapi-mkl-devel \
intel-oneapi-tbb-devel \
intel-oneapi-libdpstd-devel \
intel-oneapi-compiler-dpcpp-cpp
sudo apt-get install intel-oneapi-mkl-2024.2* \
intel-oneapi-mkl-devel-2024.2* \
intel-oneapi-tbb-devel-2021.13* \
intel-oneapi-libdpstd-devel-2022.6* \
intel-oneapi-compiler-dpcpp-cpp-2024.2*
- name: Install Lcov
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

- name: Set up python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: '3.12'

Expand Down
7 changes: 4 additions & 3 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% set max_compiler_and_mkl_version = environ.get("MAX_BUILD_CMPL_MKL_VERSION", "2026.0a0") %}
{% set required_compiler_and_mkl_version = "2024.2" %}
{% set required_dpctl_version = "0.18.0*" %}
{% set required_dpctl_version = "0.18.1" %}

package:
name: dpnp
Expand All @@ -17,14 +18,14 @@ requirements:
- ninja
- git
- dpctl >={{ required_dpctl_version }}
- mkl-devel-dpcpp >={{ required_compiler_and_mkl_version }}
- mkl-devel-dpcpp >={{ required_compiler_and_mkl_version }},<{{ max_compiler_and_mkl_version }}
- onedpl-devel
- tbb-devel
- wheel
- scikit-build
build:
- {{ compiler('cxx') }}
- {{ compiler('dpcpp') }} >={{ required_compiler_and_mkl_version }}
- {{ compiler('dpcpp') }} >={{ required_compiler_and_mkl_version }},<{{ max_compiler_and_mkl_version }}
- sysroot_linux-64 >=2.28 # [linux]
run:
- python
Expand Down
26 changes: 26 additions & 0 deletions dpnp/dpnp_algo/dpnp_arraycreation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (c) 2016-2024, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

import math
import operator

Expand Down
78 changes: 78 additions & 0 deletions dpnp/dpnp_algo/dpnp_fill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (c) 2016-2024, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

from numbers import Number

import dpctl.tensor as dpt
import dpctl.utils as dpu
from dpctl.tensor._ctors import _cast_fill_val
from dpctl.tensor._tensor_impl import (
_copy_usm_ndarray_into_usm_ndarray,
_full_usm_ndarray,
_zeros_usm_ndarray,
)

import dpnp


def dpnp_fill(arr, val):
arr = dpnp.get_usm_ndarray(arr)
exec_q = arr.sycl_queue

# if val is an array, process it
if dpnp.is_supported_array_type(val):
val = dpnp.get_usm_ndarray(val)
if val.shape != ():
raise ValueError("`val` must be a scalar or 0D-array")
if dpu.get_execution_queue((exec_q, val.sycl_queue)) is None:
raise dpu.ExecutionPlacementError(
"Input arrays have incompatible queues."
)
a_val = dpt.astype(val, arr.dtype)
a_val = dpt.broadcast_to(a_val, arr.shape)
_manager = dpu.SequentialOrderManager[exec_q]
dep_evs = _manager.submitted_events
h_ev, c_ev = _copy_usm_ndarray_into_usm_ndarray(
src=a_val, dst=arr, sycl_queue=exec_q, depends=dep_evs
)
_manager.add_event_pair(h_ev, c_ev)
return
elif not isinstance(val, (Number, dpnp.bool)):
raise TypeError(
f"array cannot be filled with `val` of type {type(val)}"
)
val = _cast_fill_val(val, arr.dtype)

_manager = dpu.SequentialOrderManager[exec_q]
dep_evs = _manager.submitted_events

# can leverage efficient memset when val is 0
if arr.flags["FORC"] and val == 0:
h_ev, zeros_ev = _zeros_usm_ndarray(arr, exec_q, depends=dep_evs)
_manager.add_event_pair(h_ev, zeros_ev)
else:
h_ev, fill_ev = _full_usm_ndarray(val, arr, exec_q, depends=dep_evs)
_manager.add_event_pair(h_ev, fill_ev)
11 changes: 8 additions & 3 deletions dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,13 +928,16 @@ def fill(self, value):
"""
Fill the array with a scalar value.
For full documentation refer to :obj:`numpy.ndarray.fill`.
Parameters
----------
value : scalar
value : {dpnp.ndarray, usm_ndarray, scalar}
All elements of `a` will be assigned this value.
Examples
--------
>>> import dpnp as np
>>> a = np.array([1, 2])
>>> a.fill(0)
>>> a
Expand All @@ -946,8 +949,10 @@ def fill(self, value):
"""

for i in range(self.size):
self.flat[i] = value
# lazy import avoids circular imports
from .dpnp_algo.dpnp_fill import dpnp_fill

dpnp_fill(self, value)

@property
def flags(self):
Expand Down
71 changes: 71 additions & 0 deletions dpnp/dpnp_iface_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"iscomplex",
"iscomplexobj",
"isfinite",
"isfortran",
"isinf",
"isnan",
"isneginf",
Expand Down Expand Up @@ -991,6 +992,76 @@ def iscomplexobj(x):
)


def isfortran(a):
"""
Check if the array is Fortran contiguous but *not* C contiguous.
This function is obsolete. If you only want to check if an array is Fortran
contiguous use ``a.flags.f_contiguous`` instead.
For full documentation refer to :obj:`numpy.isfortran`.
Parameters
----------
a : {dpnp.ndarray, usm_ndarray}
Input array.
Returns
-------
isfortran : bool
Returns ``True`` if the array is Fortran contiguous
but *not* C contiguous.
Examples
--------
:obj:`dpnp.array` allows to specify whether the array is written in
C-contiguous order (last index varies the fastest), or FORTRAN-contiguous
order in memory (first index varies the fastest).
>>> import dpnp as np
>>> a = np.array([[1, 2, 3], [4, 5, 6]], order='C')
>>> a
array([[1, 2, 3],
[4, 5, 6]])
>>> np.isfortran(a)
False
>>> b = np.array([[1, 2, 3], [4, 5, 6]], order='F')
>>> b
array([[1, 2, 3],
[4, 5, 6]])
>>> np.isfortran(b)
True
The transpose of a C-ordered array is a FORTRAN-ordered array.
>>> a = np.array([[1, 2, 3], [4, 5, 6]], order='C')
>>> a
array([[1, 2, 3],
[4, 5, 6]])
>>> np.isfortran(a)
False
>>> b = a.T
>>> b
array([[1, 4],
[2, 5],
[3, 6]])
>>> np.isfortran(b)
True
C-ordered arrays evaluate as ``False`` even if they are also
FORTRAN-ordered.
>>> np.isfortran(np.array([1, 2], order='F'))
False
"""

dpnp.check_supported_arrays_type(a)

return a.flags.fnc


_ISINF_DOCSTRING = """
Test if each element of input array is an infinity.
Expand Down
2 changes: 1 addition & 1 deletion dpnp/dpnp_iface_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def correlate(x1, x2, mode="valid"):
-----------
Input arrays are supported as :obj:`dpnp.ndarray`.
Size and shape of input arrays are supported to be equal.
Parameter `mode` is supported only with default value ``"valid``.
Parameter `mode` is supported only with default value ``"valid"``.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`.
Expand Down
16 changes: 7 additions & 9 deletions dpnp/dpnp_utils/dpnp_utils_einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
from dpctl.utils import ExecutionPlacementError

import dpnp
from dpnp.dpnp_utils import get_usm_allocations

from ..dpnp_array import dpnp_array
from dpnp.dpnp_array import dpnp_array
from dpnp.dpnp_utils import get_usm_allocations, map_dtype_to_device

_einsum_symbols = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Expand Down Expand Up @@ -1027,17 +1026,16 @@ def dpnp_einsum(
"Input and output allocation queues are not compatible"
)

result_dtype = dpnp.result_type(*arrays) if dtype is None else dtype
for id, a in enumerate(operands):
if dpnp.isscalar(a):
scalar_dtype = map_dtype_to_device(type(a), exec_q.sycl_device)
operands[id] = dpnp.array(
a, dtype=result_dtype, usm_type=res_usm_type, sycl_queue=exec_q
a, dtype=scalar_dtype, usm_type=res_usm_type, sycl_queue=exec_q
)
arrays.append(operands[id])
result_dtype = dpnp.result_type(*arrays) if dtype is None else dtype
if order in ["a", "A"]:
order = (
"F" if not any(arr.flags.c_contiguous for arr in arrays) else "C"
)
if order in "aA":
order = "F" if all(arr.flags.fnc for arr in arrays) else "C"

input_subscripts = [
_parse_ellipsis_subscript(sub, idx, ndim=arr.ndim)
Expand Down
Loading

0 comments on commit be88a7c

Please sign in to comment.