Skip to content

Commit 3202856

Browse files
Merge origin into tests_cuda
2 parents a0219b3 + 3f737be commit 3202856

File tree

17 files changed

+160
-12
lines changed

17 files changed

+160
-12
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ project(dpnp
66
DESCRIPTION "NumPy-like API accelerated by SYCL."
77
)
88

9-
option(DPNP_GENERATE_COVERAGE "Enable build DPNP with coverage instrumentation" FALSE)
10-
option(DPNP_BACKEND_TESTS "Enable building of DPNP backend test suite" FALSE)
9+
option(DPNP_GENERATE_COVERAGE "Enable build DPNP with coverage instrumentation" OFF)
10+
option(DPNP_BACKEND_TESTS "Enable building of DPNP backend test suite" OFF)
11+
option(DPNP_WITH_REDIST "Build DPNP assuming DPC++ redistributable is installed into Python prefix" OFF)
1112

1213
set(CMAKE_CXX_STANDARD 17)
1314
set(CMAKE_CXX_STANDARD_REQUIRED True)

conda-recipe/bld.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if DEFINED OVERRIDE_INTEL_IPO (
1616
set "SKBUILD_ARGS=%SKBUILD_ARGS% -DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=FALSE"
1717
)
1818

19-
FOR %%V IN (14.0.0 14 15.0.0 15 16.0.0 16 17.0.0 17) DO @(
19+
FOR %%V IN (17.0.0 17 18.0.0 18 19.0.0 19) DO @(
2020
REM set DIR_HINT if directory exists
2121
IF EXIST "%BUILD_PREFIX%\Library\lib\clang\%%V\" (
2222
SET "SYCL_INCLUDE_DIR_HINT=%BUILD_PREFIX%\Library\lib\clang\%%V"

conda-recipe/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# This is necessary to help DPC++ find Intel libraries such as SVML, IRNG, etc in build prefix
4-
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${BUILD_PREFIX}/lib"
4+
export LIBRARY_PATH="$LIBRARY_PATH:${BUILD_PREFIX}/lib"
55

66
# Intel LLVM must cooperate with compiler and sysroot from conda
77
echo "--gcc-toolchain=${BUILD_PREFIX} --sysroot=${BUILD_PREFIX}/${HOST}/sysroot -target ${HOST}" > icpx_for_conda.cfg
@@ -18,6 +18,7 @@ export DPL_ROOT_HINT=$PREFIX
1818
export MKL_ROOT_HINT=$PREFIX
1919
SKBUILD_ARGS=(-- "-DCMAKE_C_COMPILER:PATH=icx" "-DCMAKE_CXX_COMPILER:PATH=icpx" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")
2020
SKBUILD_ARGS=("${SKBUILD_ARGS[@]}" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")
21+
SKBUILD_ARGS=("${SKBUILD_ARGS[@]}" "-DDPNP_WITH_REDIST:BOOL=ON")
2122

2223
# Build wheel package
2324
WHEELS_BUILD_ARGS=("-p" "manylinux_2_28_x86_64")

dpnp/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
function(build_dpnp_cython_ext _trgt _src _dest)
22
set(options SYCL)
3-
cmake_parse_arguments(BUILD_DPNP_EXT "${options}" "" "" ${ARGN})
43
add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src)
54
message(STATUS "Using ${_trgt}")
65

@@ -41,15 +40,19 @@ function(build_dpnp_cython_ext _trgt _src _dest)
4140
VERBATIM COMMENT "Copying Cython-generated source for target ${_trgt} to dpnp source layout"
4241
)
4342
endif()
43+
44+
set(_rpath_value "$ORIGIN/..")
45+
if (DPNP_WITH_REDIST)
46+
set(_rpath_value "${_rpath_value}:$ORIGIN/../../../../")
47+
endif()
48+
set_target_properties(${_trgt} PROPERTIES INSTALL_RPATH ${_rpath_value})
49+
4450
install(TARGETS ${_trgt} LIBRARY DESTINATION ${_dest})
4551
endfunction()
4652

4753
function(build_dpnp_cython_ext_with_backend _trgt _src _dest)
4854
build_dpnp_cython_ext(${_trgt} ${_src} ${_dest})
4955
target_link_libraries(${_trgt} PRIVATE dpnp_backend_library)
50-
if (UNIX)
51-
set_target_properties(${_trgt} PROPERTIES INSTALL_RPATH "$ORIGIN/..")
52-
endif()
5356
endfunction()
5457

5558
add_subdirectory(backend)

dpnp/backend/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ add_library(dpnp_backend_library INTERFACE IMPORTED GLOBAL)
100100
target_include_directories(dpnp_backend_library BEFORE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src)
101101
target_link_libraries(dpnp_backend_library INTERFACE ${_trgt})
102102

103+
if (DPNP_WITH_REDIST)
104+
set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../")
105+
endif()
106+
103107
if (DPNP_BACKEND_TESTS)
104108
add_subdirectory(tests)
105109
endif()

dpnp/backend/extensions/blas/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ else()
9393
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::BLAS)
9494
endif()
9595

96+
if (DPNP_WITH_REDIST)
97+
set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../")
98+
endif()
99+
96100
install(TARGETS ${python_module_name}
97101
DESTINATION "dpnp/backend/extensions/blas"
98102
)

dpnp/backend/extensions/fft/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ else()
8989
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::DFT)
9090
endif()
9191

92+
if (DPNP_WITH_REDIST)
93+
set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../")
94+
endif()
95+
9296
install(TARGETS ${python_module_name}
9397
DESTINATION "dpnp/backend/extensions/fft"
9498
)

dpnp/backend/extensions/lapack/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ else()
107107
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::LAPACK)
108108
endif()
109109

110+
if (DPNP_WITH_REDIST)
111+
set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../")
112+
endif()
113+
110114
install(TARGETS ${python_module_name}
111115
DESTINATION "dpnp/backend/extensions/lapack"
112116
)

dpnp/backend/extensions/statistics/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ if (DPNP_GENERATE_COVERAGE)
8484
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
8585
endif()
8686

87+
if (DPNP_WITH_REDIST)
88+
set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../")
89+
endif()
90+
8791
install(TARGETS ${python_module_name}
8892
DESTINATION "dpnp/backend/extensions/statistics"
8993
)

dpnp/backend/extensions/ufunc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ if (DPNP_GENERATE_COVERAGE)
103103
target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
104104
endif()
105105

106+
if (DPNP_WITH_REDIST)
107+
set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../")
108+
endif()
109+
106110
install(TARGETS ${python_module_name}
107111
DESTINATION "dpnp/backend/extensions/ufunc"
108112
)

dpnp/backend/extensions/vm/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ else()
120120
target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::VM)
121121
endif()
122122

123+
if (DPNP_WITH_REDIST)
124+
set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../")
125+
endif()
126+
123127
install(TARGETS ${python_module_name}
124128
DESTINATION "dpnp/backend/extensions/vm"
125129
)

dpnp/backend/kernels/dpnp_krnl_common.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,23 @@
3535
#include "queue_sycl.hpp"
3636
#include <dpnp_iface.hpp>
3737

38+
/**
39+
* Version of SYCL DPC++ 2025.1 compiler where support of
40+
* sycl::ext::oneapi::experimental::properties was added.
41+
*/
42+
#ifndef __SYCL_COMPILER_REDUCTION_PROPERTIES_SUPPORT
43+
#define __SYCL_COMPILER_REDUCTION_PROPERTIES_SUPPORT 20241129
44+
#endif
45+
3846
namespace mkl_blas = oneapi::mkl::blas;
3947
namespace mkl_blas_cm = oneapi::mkl::blas::column_major;
4048
namespace mkl_blas_rm = oneapi::mkl::blas::row_major;
4149
namespace mkl_lapack = oneapi::mkl::lapack;
4250

51+
#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_REDUCTION_PROPERTIES_SUPPORT
52+
namespace syclex = sycl::ext::oneapi::experimental;
53+
#endif
54+
4355
template <typename _KernelNameSpecialization1,
4456
typename _KernelNameSpecialization2,
4557
typename _KernelNameSpecialization3>
@@ -78,8 +90,13 @@ sycl::event dot(sycl::queue &queue,
7890
cgh.parallel_for(
7991
sycl::range<1>{size},
8092
sycl::reduction(
81-
result_out, std::plus<_DataType_output>(),
82-
sycl::property::reduction::initialize_to_identity{}),
93+
result_out, sycl::plus<_DataType_output>(),
94+
#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_REDUCTION_PROPERTIES_SUPPORT
95+
syclex::properties(syclex::initialize_to_identity)
96+
#else
97+
sycl::property::reduction::initialize_to_identity {}
98+
#endif
99+
),
83100
[=](sycl::id<1> idx, auto &sum) {
84101
sum += static_cast<_DataType_output>(
85102
input1_in[idx * input1_strides]) *

dpnp/dpnp_array.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,11 @@ def __isub__(self, other):
434434
dpnp.subtract(self, other, out=self)
435435
return self
436436

437-
# '__iter__',
437+
def __iter__(self):
438+
"""Return ``iter(self)``."""
439+
if self.ndim == 0:
440+
raise TypeError("iteration over a 0-d array")
441+
return (self[i] for i in range(self.shape[0]))
438442

439443
def __itruediv__(self, other):
440444
"""Return ``self/=value``."""

dpnp/dpnp_iface_indexing.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"fill_diagonal",
7070
"flatnonzero",
7171
"indices",
72+
"iterable",
7273
"ix_",
7374
"mask_indices",
7475
"ndindex",
@@ -1039,6 +1040,47 @@ def indices(
10391040
return res
10401041

10411042

1043+
def iterable(y):
1044+
"""
1045+
Check whether or not an object can be iterated over.
1046+
1047+
For full documentation refer to :obj:`numpy.iterable`.
1048+
1049+
Parameters
1050+
----------
1051+
y : object
1052+
Input object.
1053+
1054+
Returns
1055+
-------
1056+
out : bool
1057+
Return ``True`` if the object has an iterator method or is a sequence
1058+
and ``False`` otherwise.
1059+
1060+
Examples
1061+
--------
1062+
>>> import dpnp as np
1063+
>>> np.iterable([1, 2, 3])
1064+
True
1065+
>>> np.iterable(2)
1066+
False
1067+
1068+
In most cases, the results of ``np.iterable(obj)`` are consistent with
1069+
``isinstance(obj, collections.abc.Iterable)``. One notable exception is
1070+
the treatment of 0-dimensional arrays:
1071+
1072+
>>> from collections.abc import Iterable
1073+
>>> a = np.array(1.0) # 0-dimensional array
1074+
>>> isinstance(a, Iterable)
1075+
True
1076+
>>> np.iterable(a)
1077+
False
1078+
1079+
"""
1080+
1081+
return numpy.iterable(y)
1082+
1083+
10421084
def ix_(*args):
10431085
"""Construct an open mesh from multiple sequences.
10441086

dpnp/tests/test_indexing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@ def test_ix_error(self, xp, shape):
337337
assert_raises(ValueError, xp.ix_, xp.ones(shape))
338338

339339

340+
class TestIterable:
341+
@pytest.mark.parametrize("data", [[1.0], [2, 3]])
342+
def test_basic(self, data):
343+
a = numpy.array(data)
344+
ia = dpnp.array(a)
345+
assert dpnp.iterable(ia) == numpy.iterable(a)
346+
347+
340348
@pytest.mark.parametrize(
341349
"shape", [[1, 2, 3], [(1, 2, 3)], [(3,)], [3], [], [()], [0]]
342350
)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import unittest
2+
3+
import numpy
4+
import pytest
5+
6+
import dpnp as cupy
7+
from dpnp.tests.third_party.cupy import testing
8+
9+
10+
@testing.parameterize(
11+
*testing.product(
12+
{"shape": [(3,), (2, 3, 4), (0,), (0, 2), (3, 0)]},
13+
)
14+
)
15+
class TestIter(unittest.TestCase):
16+
17+
@testing.for_all_dtypes()
18+
@testing.numpy_cupy_array_equal()
19+
def test_list(self, xp, dtype):
20+
x = testing.shaped_arange(self.shape, xp, dtype)
21+
return list(x)
22+
23+
@testing.for_all_dtypes()
24+
@testing.numpy_cupy_equal()
25+
def test_len(self, xp, dtype):
26+
x = testing.shaped_arange(self.shape, xp, dtype)
27+
return len(x)
28+
29+
30+
class TestIterInvalid(unittest.TestCase):
31+
32+
@testing.for_all_dtypes()
33+
def test_iter(self, dtype):
34+
for xp in (numpy, cupy):
35+
x = testing.shaped_arange((), xp, dtype)
36+
with pytest.raises(TypeError):
37+
iter(x)
38+
39+
@testing.for_all_dtypes()
40+
def test_len(self, dtype):
41+
for xp in (numpy, cupy):
42+
x = testing.shaped_arange((), xp, dtype)
43+
with pytest.raises(TypeError):
44+
len(x)

dpnp/tests/third_party/cupy/creation_tests/test_ranges.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_linspace_float_overflow(self, xp):
172172
dtype = cupy.default_float_type()
173173
return xp.linspace(0.0, xp.finfo(dtype).max / 5, 10, dtype=dtype)
174174

175-
@testing.numpy_cupy_allclose()
175+
@testing.numpy_cupy_allclose(rtol={numpy.float32: 1e-6, "default": 1e-7})
176176
def test_linspace_float_underflow(self, xp):
177177
# find minimum subnormal number
178178
dtype = cupy.default_float_type()

0 commit comments

Comments
 (0)