Skip to content

Commit a7e3478

Browse files
Merge pull request #886 from IntelPython/master
Merge master to gold
2 parents 45940b8 + 52f8655 commit a7e3478

File tree

7 files changed

+53
-42
lines changed

7 files changed

+53
-42
lines changed

dpnp/config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@
4343
Explicitly use NumPy.ndarray as return type for creation functions
4444
'''
4545

46-
__DPNP_DPCTL_AVAILABLE__ = False
46+
__DPNP_OUTPUT_DPCTL__ = int(os.getenv('DPNP_OUTPUT_DPCTL', 0))
4747
'''
48-
Availability of the DPCtl package in the environment
48+
Explicitly use DPCtl package container as return type for creation functions
49+
'''
50+
51+
__DPNP_OUTPUT_DPCTL_DEFAULT_SHARED__ = int(os.getenv('DPNP_OUTPUT_DPCTL_DEFAULT_SHARED', 0))
52+
'''
53+
Explicitly use SYCL shared memory parameter in DPCtl array constructor for creation functions
4954
'''

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ from libc.time cimport time, time_t
3636
import dpnp
3737
import dpnp.config as config
3838
import dpnp.dpnp_utils as utils_py
39+
from dpnp.dpnp_container import container_copy
40+
3941
import numpy
4042

4143
cimport cpython
@@ -118,7 +120,7 @@ cpdef utils.dpnp_descriptor dpnp_array(object obj, object dtype=None):
118120
else:
119121
result = utils_py.create_output_descriptor_py(obj_shape, obj_dtype, None)
120122

121-
utils.container_copy(result.get_pyobj(), obj)
123+
container_copy(result.get_pyobj(), obj)
122124

123125
return result
124126

dpnp/dpnp_container.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,18 @@
4040
import numpy
4141

4242

43-
try:
44-
"""
45-
Detect DPCtl availability to use data container
46-
"""
47-
import dpctl.tensor as dpctl
48-
49-
config.__DPNP_DPCTL_AVAILABLE__ = True
50-
51-
except ImportError:
52-
"""
53-
No DPCtl data container available
54-
"""
55-
config.__DPNP_DPCTL_AVAILABLE__ = False
43+
if config.__DPNP_OUTPUT_DPCTL__:
44+
try:
45+
"""
46+
Detect DPCtl availability to use data container
47+
"""
48+
import dpctl.tensor as dpctl
5649

57-
# config.__DPNP_DPCTL_AVAILABLE__ = False
50+
except ImportError:
51+
"""
52+
No DPCtl data container available
53+
"""
54+
config.__DPNP_OUTPUT_DPCTL__ = 0
5855

5956

6057
__all__ = [
@@ -67,11 +64,38 @@ def create_output_container(shape, type):
6764
""" Create NumPy ndarray """
6865
# TODO need to use "buffer=" parameter to use SYCL aware memory
6966
result = numpy.ndarray(shape, dtype=type)
70-
elif config.__DPNP_DPCTL_AVAILABLE__:
67+
elif config.__DPNP_OUTPUT_DPCTL__:
7168
""" Create DPCTL array """
72-
result = dpctl.usm_ndarray(shape, dtype=numpy.dtype(type).name)
69+
if config.__DPNP_OUTPUT_DPCTL_DEFAULT_SHARED__:
70+
"""
71+
From DPCtrl documentation:
72+
'buffer can be strings ('device'|'shared'|'host' to allocate new memory)'
73+
"""
74+
result = dpctl.usm_ndarray(shape, dtype=numpy.dtype(type).name, buffer='shared')
75+
else:
76+
"""
77+
Can't pass 'None' as buffer= parameter to allow DPCtrl uses it's default
78+
"""
79+
result = dpctl.usm_ndarray(shape, dtype=numpy.dtype(type).name)
7380
else:
7481
""" Create DPNP array """
7582
result = dparray(shape, dtype=type)
7683

7784
return result
85+
86+
87+
def container_copy(dst_obj, src_obj, dst_idx = 0):
88+
"""
89+
Copy values to `dst` by iterating element by element in `input_obj`
90+
"""
91+
92+
for elem_value in src_obj:
93+
if isinstance(elem_value, (list, tuple)):
94+
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
95+
elif issubclass(type(elem_value), (numpy.ndarray, dparray)):
96+
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
97+
else:
98+
dst_obj.flat[dst_idx] = elem_value
99+
dst_idx += 1
100+
101+
return dst_idx

dpnp/dpnp_iface_arraycreation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def array(x1, dtype=None, copy=True, order='C', subok=False, ndmin=0, like=None)
195195

196196
if not dpnp.is_type_supported(dtype) and dtype is not None:
197197
pass
198-
elif config.__DPNP_DPCTL_AVAILABLE__:
198+
elif config.__DPNP_OUTPUT_DPCTL__:
199199
# TODO this is workaround becasue
200200
# usm_array has no element wise assignment (aka []) and
201201
# has no "flat" property and

dpnp/dpnp_utils/dpnp_algo_utils.pxd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ cpdef find_common_type(object x1_obj, object x2_obj)
9898
Find common type of 2 input objects
9999
"""
100100

101-
cdef long container_copy(object dst_obj, object src_obj, size_t dst_idx=*) except -1
102-
"""
103-
Copy values to `dst` by iterating element by element in `input_obj`
104-
"""
105101

106102
cpdef long _get_linear_index(key, tuple shape, int ndim)
107103
"""

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ import numpy
3535
import dpnp.config as config
3636
import dpnp
3737
from dpnp.dpnp_algo cimport dpnp_DPNPFuncType_to_dtype, dpnp_dtype_to_DPNPFuncType, get_dpnp_function_ptr
38-
from dpnp.dpnp_container import create_output_container
38+
from dpnp.dpnp_container import create_output_container, container_copy
3939
from libcpp cimport bool as cpp_bool
4040
from libcpp.complex cimport complex as cpp_complex
4141

42-
from dpnp.dparray import dparray
43-
4442
cimport cpython
4543
cimport cython
4644
cimport numpy
@@ -194,21 +192,6 @@ cpdef dpnp_descriptor create_output_descriptor_py(shape_type_c output_shape, obj
194192
return create_output_descriptor(output_shape, c_type, requested_out)
195193

196194

197-
cdef long container_copy(object dst_obj, object src_obj, size_t dst_idx = 0) except -1:
198-
cdef elem_dtype = dst_obj.dtype
199-
200-
for elem_value in src_obj:
201-
if isinstance(elem_value, (list, tuple)):
202-
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
203-
elif issubclass(type(elem_value), (numpy.ndarray, dparray)):
204-
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
205-
else:
206-
dst_obj.flat[dst_idx] = elem_value
207-
dst_idx += 1
208-
209-
return dst_idx
210-
211-
212195
cpdef tuple get_axis_indeces(idx, shape):
213196
"""
214197
Compute axis indices of an element in array from array linear index

tests/skipped_tests_gpu.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpctl_memory
12
tests/test_arraymanipulation.py::TestHstack::test_generator
23
tests/test_arraymanipulation.py::TestVstack::test_generator
34
tests/test_fft.py::test_fft[complex128]

0 commit comments

Comments
 (0)