From 08a915e65c14b989b9f941569baf951c2df7d8a5 Mon Sep 17 00:00:00 2001 From: Alexander-Makaryev Date: Tue, 22 Mar 2022 08:32:21 -0500 Subject: [PATCH 1/2] Using device or sycl_queue keyword, not both --- dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx | 2 +- dpnp/dpnp_array.py | 6 +----- dpnp/dpnp_container.py | 11 ++++++----- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx b/dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx index 33eb55e5dcef..aa81b7fd0829 100644 --- a/dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx +++ b/dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx @@ -286,7 +286,7 @@ cpdef utils.dpnp_descriptor dpnp_matmul(utils.dpnp_descriptor in_array1, utils.d cdef utils.dpnp_descriptor result = utils.create_output_descriptor(shape_result, kernel_data.return_type, out, - device=result_sycl_device, + device=None, usm_type=result_usm_type, sycl_queue=result_sycl_queue) if result.size == 0: diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index c0bd122aea18..28b3ceac7acf 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -61,12 +61,8 @@ def __init__(self, "".format(shape, buffer.shape) ) self._array_obj = dpt.asarray(buffer, - dtype=buffer.dtype, copy=False, - order=order, - device=buffer.sycl_device, - usm_type=buffer.usm_type, - sycl_queue=buffer.sycl_queue) + order=order) else: sycl_queue_normalized = normalize_queue_device(sycl_queue=sycl_queue, device=device) self._array_obj = dpt.usm_ndarray(shape, diff --git a/dpnp/dpnp_container.py b/dpnp/dpnp_container.py index a983b1971615..efb5d67128cf 100644 --- a/dpnp/dpnp_container.py +++ b/dpnp/dpnp_container.py @@ -41,7 +41,7 @@ import numpy import dpctl.tensor as dpt - +from dpctl.tensor._device import normalize_queue_device if config.__DPNP_OUTPUT_DPCTL__: try: @@ -76,13 +76,13 @@ def asarray(x1, else: x1_obj = x1 + sycl_queue_normalized = normalize_queue_device(sycl_queue=sycl_queue, device=device) array_obj = dpt.asarray(x1_obj, dtype=dtype, copy=copy, order=order, - device=device, usm_type=usm_type, - sycl_queue=sycl_queue) + sycl_queue=sycl_queue_normalized) return dpnp_array(array_obj.shape, buffer=array_obj, order=order) @@ -94,11 +94,12 @@ def empty(shape, usm_type="device", sycl_queue=None): """Creates `dpnp_array` from uninitialized USM allocation.""" + sycl_queue_normalized = normalize_queue_device(sycl_queue=sycl_queue, device=device) + array_obj = dpt.empty(shape, dtype=dtype, order=order, - device=device, usm_type=usm_type, - sycl_queue=sycl_queue) + sycl_queue=sycl_queue_normalized) return dpnp_array(array_obj.shape, buffer=array_obj, order=order) From ad712e5a644997570d3917d2ff0afef9b41159b1 Mon Sep 17 00:00:00 2001 From: Alexander-Makaryev Date: Tue, 22 Mar 2022 09:08:39 -0500 Subject: [PATCH 2/2] hotfix --- dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx | 2 +- dpnp/dpnp_utils/dpnp_algo_utils.pyx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx b/dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx index aa81b7fd0829..33eb55e5dcef 100644 --- a/dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx +++ b/dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx @@ -286,7 +286,7 @@ cpdef utils.dpnp_descriptor dpnp_matmul(utils.dpnp_descriptor in_array1, utils.d cdef utils.dpnp_descriptor result = utils.create_output_descriptor(shape_result, kernel_data.return_type, out, - device=None, + device=result_sycl_device, usm_type=result_usm_type, sycl_queue=result_sycl_queue) if result.size == 0: diff --git a/dpnp/dpnp_utils/dpnp_algo_utils.pyx b/dpnp/dpnp_utils/dpnp_algo_utils.pyx index 2eba38cff59a..86a670c13601 100644 --- a/dpnp/dpnp_utils/dpnp_algo_utils.pyx +++ b/dpnp/dpnp_utils/dpnp_algo_utils.pyx @@ -399,6 +399,8 @@ cdef dpnp_descriptor create_output_descriptor(shape_type_c output_shape, if requested_out is None: result = None + if sycl_queue is not None: + device = None result_dtype = dpnp_DPNPFuncType_to_dtype(< size_t > c_type) result_obj = dpnp_container.empty(output_shape, dtype=result_dtype, @@ -541,6 +543,9 @@ cdef tuple get_common_usm_allocation(dpnp_descriptor x1, dpnp_descriptor x2): "".format(array1_obj.usm_type, array2_obj.usm_type)) common_sycl_queue = dpctl.utils.get_execution_queue((array1_obj.sycl_queue, array2_obj.sycl_queue)) + # TODO: refactor, remove when CFD is implemented in all array constructors + if common_sycl_queue is None and array1_obj.sycl_context == array2_obj.sycl_context: + common_sycl_queue = array1_obj.sycl_queue if common_sycl_queue is None: raise ValueError( "could not recognize common SYCL queue for inputs in SYCL queues {} and {}"