Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging developmental snapshot tagged 0.14.6dev2 to gold/2021 #1337

Merged
merged 53 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c5fe314
Changed behavior of __array_namespace__
oleksandr-pavlyk Aug 2, 2023
4555bf1
Corrected text of exception message
oleksandr-pavlyk Aug 2, 2023
964db08
Corrected operator true_divide with divide
oleksandr-pavlyk Aug 2, 2023
78aa99b
Fixed test per change in dpctl implementation
oleksandr-pavlyk Aug 3, 2023
51bf9e1
Fixed _slice_len for vacuous slices
oleksandr-pavlyk Aug 3, 2023
f4a31bb
Fixed issue discovered by array API tests
oleksandr-pavlyk Aug 3, 2023
05aa952
Corrected remaining operators in _usmarray.pyx
ndgrigorian Aug 3, 2023
25547e7
Fixed bug in contiguity flag computation found by array-api-tests
oleksandr-pavlyk Aug 3, 2023
22c95b6
Fixed flags test case for changes to contiguity flag computation
ndgrigorian Aug 3, 2023
4803f13
unpacked chained method calls
oleksandr-pavlyk Aug 3, 2023
cc08b5d
Fixed Cython warning
oleksandr-pavlyk Aug 6, 2023
5c1a961
Fixed array API test failure by adding validation
oleksandr-pavlyk Aug 6, 2023
07faf2b
Use bitwise_invert for __invert__
oleksandr-pavlyk Aug 6, 2023
3ddf51c
Corrected order='K' support in astype
oleksandr-pavlyk Aug 6, 2023
440872d
Merge remote-tracking branch 'origin/master' into enable-operators
oleksandr-pavlyk Aug 6, 2023
51e3f15
Moved 2 tests from test_type_utils to elementwise/test_type_utils
oleksandr-pavlyk Aug 7, 2023
e5785ca
Fixed bug in concat uncovered by array API tests
oleksandr-pavlyk Aug 7, 2023
a3c00bc
Closes gh-1325
oleksandr-pavlyk Aug 7, 2023
80eae6e
Corrected order="K" support in copy
ndgrigorian Aug 7, 2023
ff1081a
Fixed logaddexp for mixed nan and number operands
ndgrigorian Aug 7, 2023
1b5419f
logaddexp now handles both NaNs and infinities correctly per array API
ndgrigorian Aug 7, 2023
3c87433
Broke up 'or' conditional in logaddexp logic for inf and NaN
ndgrigorian Aug 7, 2023
3c0aeed
Modularized logic implementing logaddexp
oleksandr-pavlyk Aug 7, 2023
cf7d9bf
Change to test_complex_special_cases
oleksandr-pavlyk Aug 7, 2023
8343edc
Array-API conformance testing can start as soon as build_linux jobs f…
oleksandr-pavlyk Aug 7, 2023
ebd1faf
Fixed log-add-exp per review feedback
oleksandr-pavlyk Aug 8, 2023
df8eb5f
Merge pull request #1328 from IntelPython/fix-some-array-api-test-cases
oleksandr-pavlyk Aug 8, 2023
7c94a33
Simplified flags_ computation in to_device method
oleksandr-pavlyk Aug 7, 2023
b989d36
impl_minimum_maximum_elementwise_funcs
vtavana Jul 31, 2023
f77f7a4
Support stream keyword in usm_ndarray.to_device per array API
oleksandr-pavlyk Aug 9, 2023
c368034
Fix for gh-1330
oleksandr-pavlyk Aug 9, 2023
ef5fe17
Fixed grammar in exception message text
oleksandr-pavlyk Aug 9, 2023
f65e225
address reviewer's comments
vtavana Aug 8, 2023
341d4da
Merge pull request #1324 from IntelPython/enable-operators
oleksandr-pavlyk Aug 9, 2023
53315a9
Fixed bug introduced in 5c1a961afee913e675c92a7ecc7d15ab308f61d8
oleksandr-pavlyk Aug 9, 2023
8b03642
Added tests for examples fixed in prev. commit
oleksandr-pavlyk Aug 9, 2023
b055ff9
Merge pull request #1316 from IntelPython/impl_minimum_maximum_elemen…
vtavana Aug 10, 2023
346200e
Fixed example for @antonwolfy, added tests based on it
oleksandr-pavlyk Aug 10, 2023
0787d13
Implement DPCTLPlatform_AreEq(PRef1, PRef1), DPCTLPlatform_Hash(PRef)
oleksandr-pavlyk Aug 10, 2023
358fc5d
Corrected declaration of DPCLTContext_Hash
oleksandr-pavlyk Aug 10, 2023
0bfc6f8
Implemented SyclPlatform.__eq__ and SyclPlatform.__hash__
oleksandr-pavlyk Aug 10, 2023
b40d357
Added tests for equality testing and hashing of SyclPlatform
oleksandr-pavlyk Aug 10, 2023
e54aaa0
Exercise default_sycl_platform on Linux only
oleksandr-pavlyk Aug 10, 2023
597cd4b
Refactor complex comparison functions (#1320)
ndgrigorian Aug 10, 2023
ed93e02
Fix expm1 for complex special cases (#1332)
ndgrigorian Aug 11, 2023
e28bd88
Add default_device_index_type(queue_or_dev) utility
oleksandr-pavlyk Aug 11, 2023
bf22a28
dpt.nonzero should use default index type
oleksandr-pavlyk Aug 11, 2023
e70891b
Adjusted test_nonzero_dtype to use default index type as reference
oleksandr-pavlyk Aug 11, 2023
f5b96b7
Fixes gh-1334
oleksandr-pavlyk Aug 11, 2023
706d80f
Adds tests based on examples in issue gh-1334
oleksandr-pavlyk Aug 11, 2023
a8d97f3
Merge pull request #1333 from IntelPython/sycl-platform-equal
oleksandr-pavlyk Aug 11, 2023
6f0969c
Merge pull request #1336 from IntelPython/fix-nonzero-result-dtype-win
oleksandr-pavlyk Aug 11, 2023
074ec3a
Merge pull request #1331 from IntelPython/to_device-stream-support
oleksandr-pavlyk Aug 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ jobs:
done

array-api-conformity:
needs: test_linux
needs: build_linux
runs-on: ${{ matrix.runner }}

strategy:
Expand Down
2 changes: 2 additions & 0 deletions dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ cdef extern from "syclinterface/dpctl_sycl_platform_manager.h":


cdef extern from "syclinterface/dpctl_sycl_platform_interface.h":
cdef bool DPCTLPlatform_AreEq(const DPCTLSyclPlatformRef, const DPCTLSyclPlatformRef)
cdef DPCTLSyclPlatformRef DPCTLPlatform_Copy(const DPCTLSyclPlatformRef)
cdef DPCTLSyclPlatformRef DPCTLPlatform_Create()
cdef DPCTLSyclPlatformRef DPCTLPlatform_CreateFromSelector(
Expand All @@ -308,6 +309,7 @@ cdef extern from "syclinterface/dpctl_sycl_platform_interface.h":
cdef const char *DPCTLPlatform_GetName(const DPCTLSyclPlatformRef)
cdef const char *DPCTLPlatform_GetVendor(const DPCTLSyclPlatformRef)
cdef const char *DPCTLPlatform_GetVersion(const DPCTLSyclPlatformRef)
cdef size_t DPCTLPlatform_Hash(const DPCTLSyclPlatformRef)
cdef DPCTLPlatformVectorRef DPCTLPlatform_GetPlatforms()
cdef DPCTLSyclContextRef DPCTLPlatform_GetDefaultContext(
const DPCTLSyclPlatformRef)
Expand Down
3 changes: 3 additions & 0 deletions dpctl/_sycl_platform.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
SYCL platform-related helper functions.
"""

from libcpp cimport bool

from ._backend cimport DPCTLSyclDeviceSelectorRef, DPCTLSyclPlatformRef


Expand All @@ -40,6 +42,7 @@ cdef class SyclPlatform(_SyclPlatform):
cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef)
cdef int _init_from__SyclPlatform(self, _SyclPlatform other)
cdef DPCTLSyclPlatformRef get_platform_ref(self)
cdef bool equals(self, SyclPlatform)


cpdef list get_platforms()
40 changes: 40 additions & 0 deletions dpctl/_sycl_platform.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
""" Implements SyclPlatform Cython extension type.
"""

from libcpp cimport bool

from ._backend cimport ( # noqa: E211
DPCTLCString_Delete,
DPCTLDeviceSelector_Delete,
DPCTLFilterSelector_Create,
DPCTLPlatform_AreEq,
DPCTLPlatform_Copy,
DPCTLPlatform_Create,
DPCTLPlatform_CreateFromSelector,
Expand All @@ -35,6 +38,7 @@ from ._backend cimport ( # noqa: E211
DPCTLPlatform_GetPlatforms,
DPCTLPlatform_GetVendor,
DPCTLPlatform_GetVersion,
DPCTLPlatform_Hash,
DPCTLPlatformMgr_GetInfo,
DPCTLPlatformMgr_PrintInfo,
DPCTLPlatformVector_Delete,
Expand Down Expand Up @@ -274,6 +278,42 @@ cdef class SyclPlatform(_SyclPlatform):
else:
return SyclContext._create(CRef)

cdef bool equals(self, SyclPlatform other):
"""
Returns true if the :class:`dpctl.SyclPlatform` argument has the
same underlying ``DPCTLSyclPlatformRef`` object as this
:class:`dpctl.SyclPlatform` instance.

Returns:
:obj:`bool`: ``True`` if the two :class:`dpctl.SyclPlatform` objects
point to the same ``DPCTLSyclPlatformRef`` object, otherwise
``False``.
"""
return DPCTLPlatform_AreEq(self._platform_ref, other.get_platform_ref())

def __eq__(self, other):
"""
Returns True if the :class:`dpctl.SyclPlatform` argument has the
same underlying ``DPCTLSyclPlatformRef`` object as this
:class:`dpctl.SyclPlatform` instance.

Returns:
:obj:`bool`: ``True`` if the two :class:`dpctl.SyclPlatform` objects
point to the same ``DPCTLSyclPlatformRef`` object, otherwise
``False``.
"""
if isinstance(other, SyclPlatform):
return self.equals(<SyclPlatform> other)
else:
return False

def __hash__(self):
"""
Returns a hash value by hashing the underlying ``sycl::platform`` object.

"""
return DPCTLPlatform_Hash(self._platform_ref)


def lsplatform(verbosity=0):
"""
Expand Down
2 changes: 1 addition & 1 deletion dpctl/_sycl_queue.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ from ._sycl_event cimport SyclEvent
from .program._program cimport SyclKernel


cdef void default_async_error_handler(int) nogil except *
cdef void default_async_error_handler(int) except * nogil

cdef public api class _SyclQueue [
object Py_SyclQueueObject, type Py_SyclQueueType
Expand Down
4 changes: 4 additions & 0 deletions dpctl/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
logical_not,
logical_or,
logical_xor,
maximum,
minimum,
multiply,
negative,
not_equal,
Expand Down Expand Up @@ -274,6 +276,8 @@
"log1p",
"log2",
"log10",
"maximum",
"minimum",
"multiply",
"negative",
"not_equal",
Expand Down
188 changes: 147 additions & 41 deletions dpctl/tensor/_copy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import builtins
import operator

import numpy as np
Expand Down Expand Up @@ -245,6 +246,23 @@ def _broadcast_shapes(sh1, sh2):
).shape


def _broadcast_strides(X_shape, X_strides, res_ndim):
"""
Broadcasts strides to match the given dimensions;
returns tuple type strides.
"""
out_strides = [0] * res_ndim
X_shape_len = len(X_shape)
str_dim = -X_shape_len
for i in range(X_shape_len):
shape_value = X_shape[i]
if not shape_value == 1:
out_strides[str_dim] = X_strides[i]
str_dim += 1

return tuple(out_strides)


def _copy_from_usm_ndarray_to_usm_ndarray(dst, src):
if any(
not isinstance(arg, dpt.usm_ndarray)
Expand All @@ -267,7 +285,7 @@ def _copy_from_usm_ndarray_to_usm_ndarray(dst, src):
except ValueError as exc:
raise ValueError("Shapes of two arrays are not compatible") from exc

if dst.size < src.size:
if dst.size < src.size and dst.size < np.prod(common_shape):
raise ValueError("Destination is smaller ")

if len(common_shape) > dst.ndim:
Expand All @@ -278,17 +296,127 @@ def _copy_from_usm_ndarray_to_usm_ndarray(dst, src):
common_shape = common_shape[ones_count:]

if src.ndim < len(common_shape):
new_src_strides = (0,) * (len(common_shape) - src.ndim) + src.strides
new_src_strides = _broadcast_strides(
src.shape, src.strides, len(common_shape)
)
src_same_shape = dpt.usm_ndarray(
common_shape, dtype=src.dtype, buffer=src, strides=new_src_strides
)
elif src.ndim == len(common_shape):
new_src_strides = _broadcast_strides(
src.shape, src.strides, len(common_shape)
)
src_same_shape = dpt.usm_ndarray(
common_shape, dtype=src.dtype, buffer=src, strides=new_src_strides
)
else:
src_same_shape = src
src_same_shape.shape = common_shape
# since broadcasting succeeded, src.ndim is greater because of
# leading sequence of ones, so we trim it
n = len(common_shape)
new_src_strides = _broadcast_strides(
src.shape[-n:], src.strides[-n:], n
)
src_same_shape = dpt.usm_ndarray(
common_shape,
dtype=src.dtype,
buffer=src.usm_data,
strides=new_src_strides,
offset=src._element_offset,
)

_copy_same_shape(dst, src_same_shape)


def _empty_like_orderK(X, dt, usm_type=None, dev=None):
"""Returns empty array like `x`, using order='K'

For an array `x` that was obtained by permutation of a contiguous
array the returned array will have the same shape and the same
strides as `x`.
"""
if not isinstance(X, dpt.usm_ndarray):
raise TypeError(f"Expected usm_ndarray, got {type(X)}")
if usm_type is None:
usm_type = X.usm_type
if dev is None:
dev = X.device
fl = X.flags
if fl["C"] or X.size <= 1:
return dpt.empty_like(
X, dtype=dt, usm_type=usm_type, device=dev, order="C"
)
elif fl["F"]:
return dpt.empty_like(
X, dtype=dt, usm_type=usm_type, device=dev, order="F"
)
st = list(X.strides)
perm = sorted(
range(X.ndim), key=lambda d: builtins.abs(st[d]), reverse=True
)
inv_perm = sorted(range(X.ndim), key=lambda i: perm[i])
st_sorted = [st[i] for i in perm]
sh = X.shape
sh_sorted = tuple(sh[i] for i in perm)
R = dpt.empty(sh_sorted, dtype=dt, usm_type=usm_type, device=dev, order="C")
if min(st_sorted) < 0:
sl = tuple(
slice(None, None, -1)
if st_sorted[i] < 0
else slice(None, None, None)
for i in range(X.ndim)
)
R = R[sl]
return dpt.permute_dims(R, inv_perm)


def _empty_like_pair_orderK(X1, X2, dt, res_shape, usm_type, dev):
if not isinstance(X1, dpt.usm_ndarray):
raise TypeError(f"Expected usm_ndarray, got {type(X1)}")
if not isinstance(X2, dpt.usm_ndarray):
raise TypeError(f"Expected usm_ndarray, got {type(X2)}")
nd1 = X1.ndim
nd2 = X2.ndim
if nd1 > nd2 and X1.shape == res_shape:
return _empty_like_orderK(X1, dt, usm_type, dev)
elif nd1 < nd2 and X2.shape == res_shape:
return _empty_like_orderK(X2, dt, usm_type, dev)
fl1 = X1.flags
fl2 = X2.flags
if fl1["C"] or fl2["C"]:
return dpt.empty(
res_shape, dtype=dt, usm_type=usm_type, device=dev, order="C"
)
if fl1["F"] and fl2["F"]:
return dpt.empty(
res_shape, dtype=dt, usm_type=usm_type, device=dev, order="F"
)
st1 = list(X1.strides)
st2 = list(X2.strides)
max_ndim = max(nd1, nd2)
st1 += [0] * (max_ndim - len(st1))
st2 += [0] * (max_ndim - len(st2))
perm = sorted(
range(max_ndim),
key=lambda d: (builtins.abs(st1[d]), builtins.abs(st2[d])),
reverse=True,
)
inv_perm = sorted(range(max_ndim), key=lambda i: perm[i])
st1_sorted = [st1[i] for i in perm]
st2_sorted = [st2[i] for i in perm]
sh = res_shape
sh_sorted = tuple(sh[i] for i in perm)
R = dpt.empty(sh_sorted, dtype=dt, usm_type=usm_type, device=dev, order="C")
if max(min(st1_sorted), min(st2_sorted)) < 0:
sl = tuple(
slice(None, None, -1)
if (st1_sorted[i] < 0 and st2_sorted[i] < 0)
else slice(None, None, None)
for i in range(nd1)
)
R = R[sl]
return dpt.permute_dims(R, inv_perm)


def copy(usm_ary, order="K"):
"""copy(ary, order="K")

Expand Down Expand Up @@ -334,28 +462,15 @@ def copy(usm_ary, order="K"):
"Unrecognized value of the order keyword. "
"Recognized values are 'A', 'C', 'F', or 'K'"
)
c_contig = usm_ary.flags.c_contiguous
f_contig = usm_ary.flags.f_contiguous
R = dpt.usm_ndarray(
usm_ary.shape,
dtype=usm_ary.dtype,
buffer=usm_ary.usm_type,
order=copy_order,
buffer_ctor_kwargs={"queue": usm_ary.sycl_queue},
)
if order == "K" and (not c_contig and not f_contig):
original_strides = usm_ary.strides
ind = sorted(
range(usm_ary.ndim),
key=lambda i: abs(original_strides[i]),
reverse=True,
)
new_strides = tuple(R.strides[ind[i]] for i in ind)
if order == "K":
R = _empty_like_orderK(usm_ary, usm_ary.dtype)
else:
R = dpt.usm_ndarray(
usm_ary.shape,
dtype=usm_ary.dtype,
buffer=R.usm_data,
strides=new_strides,
buffer=usm_ary.usm_type,
order=copy_order,
buffer_ctor_kwargs={"queue": usm_ary.sycl_queue},
)
_copy_same_shape(R, usm_ary)
return R
Expand Down Expand Up @@ -432,26 +547,15 @@ def astype(usm_ary, newdtype, order="K", casting="unsafe", copy=True):
"Unrecognized value of the order keyword. "
"Recognized values are 'A', 'C', 'F', or 'K'"
)
R = dpt.usm_ndarray(
usm_ary.shape,
dtype=target_dtype,
buffer=usm_ary.usm_type,
order=copy_order,
buffer_ctor_kwargs={"queue": usm_ary.sycl_queue},
)
if order == "K" and (not c_contig and not f_contig):
original_strides = usm_ary.strides
ind = sorted(
range(usm_ary.ndim),
key=lambda i: abs(original_strides[i]),
reverse=True,
)
new_strides = tuple(R.strides[ind[i]] for i in ind)
if order == "K":
R = _empty_like_orderK(usm_ary, target_dtype)
else:
R = dpt.usm_ndarray(
usm_ary.shape,
dtype=target_dtype,
buffer=R.usm_data,
strides=new_strides,
buffer=usm_ary.usm_type,
order=copy_order,
buffer_ctor_kwargs={"queue": usm_ary.sycl_queue},
)
_copy_from_usm_ndarray_to_usm_ndarray(R, usm_ary)
return R
Expand Down Expand Up @@ -492,6 +596,8 @@ def _extract_impl(ary, ary_mask, axis=0):
dst = dpt.empty(
dst_shape, dtype=ary.dtype, usm_type=ary.usm_type, device=ary.device
)
if dst.size == 0:
return dst
hev, _ = ti._extract(
src=ary,
cumsum=cumsum,
Expand All @@ -517,7 +623,7 @@ def _nonzero_impl(ary):
mask_nelems, dtype=cumsum_dt, sycl_queue=exec_q, order="C"
)
mask_count = ti.mask_positions(ary, cumsum, sycl_queue=exec_q)
indexes_dt = ti.default_device_int_type(exec_q.sycl_device)
indexes_dt = ti.default_device_index_type(exec_q.sycl_device)
indexes = dpt.empty(
(ary.ndim, mask_count),
dtype=indexes_dt,
Expand Down
Loading