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

Sycl to cython fft test #7

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ jobs:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-

- name: Install dpnp
run: conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} dpctl=${{ matrix.dpctl }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
run: conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
env:
TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}'

Expand All @@ -239,9 +239,15 @@ jobs:
- name: Smoke test
run: python -c "import dpnp, dpctl; dpctl.lsplatform()"

- name: Run fft tests with debug
run: python -m pytest -q -ra --disable-warnings -vv test_fft.py -s
env:
SYCL_ENABLE_HOST_DEVICE: '1'
working-directory: ${{ env.tests-path }}

# TODO: run the whole scope once the issues on CPU are resolved
- name: Run tests
run: python -m pytest -q -ra --disable-warnings -vv test_arraycreation.py test_dparray.py test_mathematical.py test_special.py
run: python -m pytest -q -ra --disable-warnings -vv test_arraycreation.py test_dparray.py test_fft.py test_mathematical.py test_special.py
env:
SYCL_ENABLE_HOST_DEVICE: '1'
working-directory: ${{ env.tests-path }}
Expand Down Expand Up @@ -416,7 +422,7 @@ jobs:

# TODO: run the whole scope once the issues on CPU are resolved
- name: Run tests
run: python -m pytest -q -ra --disable-warnings -vv test_arraycreation.py test_dparray.py test_mathematical.py test_special.py
run: python -m pytest -q -ra --disable-warnings -vv test_arraycreation.py test_dparray.py test_fft.py test_mathematical.py test_special.py
working-directory: ${{ env.tests-path }}

upload_linux:
Expand Down
14 changes: 14 additions & 0 deletions dpnp/backend/kernels/dpnp_krnl_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,11 +1112,25 @@ void func_map_init_linalg(func_map_t& fmap)
fmap[DPNPFuncName::DPNP_FN_EIG][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_eig_default_c<float, float>};
fmap[DPNPFuncName::DPNP_FN_EIG][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_eig_default_c<double, double>};

fmap[DPNPFuncName::DPNP_FN_EIG_EXT][eft_INT][eft_INT] = {eft_DBL, (void*)dpnp_eig_ext_c<int32_t, double>};
fmap[DPNPFuncName::DPNP_FN_EIG_EXT][eft_LNG][eft_LNG] = {eft_DBL, (void*)dpnp_eig_ext_c<int64_t, double>};
fmap[DPNPFuncName::DPNP_FN_EIG_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_eig_ext_c<float, float>};
fmap[DPNPFuncName::DPNP_FN_EIG_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_eig_ext_c<double, double>};

fmap[DPNPFuncName::DPNP_FN_EIGVALS][eft_INT][eft_INT] = {eft_DBL, (void*)dpnp_eigvals_default_c<int32_t, double>};
fmap[DPNPFuncName::DPNP_FN_EIGVALS][eft_LNG][eft_LNG] = {eft_DBL, (void*)dpnp_eigvals_default_c<int64_t, double>};
fmap[DPNPFuncName::DPNP_FN_EIGVALS][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_eigvals_default_c<float, float>};
fmap[DPNPFuncName::DPNP_FN_EIGVALS][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_eigvals_default_c<double, double>};

fmap[DPNPFuncName::DPNP_FN_EIGVALS_EXT][eft_INT][eft_INT] = {eft_DBL,
(void*)dpnp_eigvals_ext_c<int32_t, double>};
fmap[DPNPFuncName::DPNP_FN_EIGVALS_EXT][eft_LNG][eft_LNG] = {eft_DBL,
(void*)dpnp_eigvals_ext_c<int64_t, double>};
fmap[DPNPFuncName::DPNP_FN_EIGVALS_EXT][eft_FLT][eft_FLT] = {eft_FLT,
(void*)dpnp_eigvals_ext_c<float, float>};
fmap[DPNPFuncName::DPNP_FN_EIGVALS_EXT][eft_DBL][eft_DBL] = {eft_DBL,
(void*)dpnp_eigvals_ext_c<double, double>};

fmap[DPNPFuncName::DPNP_FN_INITVAL][eft_BLN][eft_BLN] = {eft_BLN, (void*)dpnp_initval_default_c<bool>};
fmap[DPNPFuncName::DPNP_FN_INITVAL][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_initval_default_c<int32_t>};
fmap[DPNPFuncName::DPNP_FN_INITVAL][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_initval_default_c<int64_t>};
Expand Down
179 changes: 109 additions & 70 deletions dpnp/backend/kernels/dpnp_krnl_fft.cpp

Large diffs are not rendered by default.

48 changes: 44 additions & 4 deletions dpnp/backend/kernels/dpnp_krnl_linalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,16 +872,29 @@ void func_map_init_linalg_func(func_map_t& fmap)
fmap[DPNPFuncName::DPNP_FN_CHOLESKY][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_cholesky_default_c<float>};
fmap[DPNPFuncName::DPNP_FN_CHOLESKY][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_cholesky_default_c<double>};

fmap[DPNPFuncName::DPNP_FN_CHOLESKY_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_cholesky_ext_c<float>};
fmap[DPNPFuncName::DPNP_FN_CHOLESKY_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_cholesky_ext_c<double>};

fmap[DPNPFuncName::DPNP_FN_DET][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_det_default_c<int32_t>};
fmap[DPNPFuncName::DPNP_FN_DET][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_det_default_c<int64_t>};
fmap[DPNPFuncName::DPNP_FN_DET][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_det_default_c<float>};
fmap[DPNPFuncName::DPNP_FN_DET][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_det_default_c<double>};

fmap[DPNPFuncName::DPNP_FN_DET_EXT][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_det_ext_c<int32_t>};
fmap[DPNPFuncName::DPNP_FN_DET_EXT][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_det_ext_c<int64_t>};
fmap[DPNPFuncName::DPNP_FN_DET_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_det_ext_c<float>};
fmap[DPNPFuncName::DPNP_FN_DET_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_det_ext_c<double>};

fmap[DPNPFuncName::DPNP_FN_INV][eft_INT][eft_INT] = {eft_DBL, (void*)dpnp_inv_default_c<int32_t, double>};
fmap[DPNPFuncName::DPNP_FN_INV][eft_LNG][eft_LNG] = {eft_DBL, (void*)dpnp_inv_default_c<int64_t, double>};
fmap[DPNPFuncName::DPNP_FN_INV][eft_FLT][eft_FLT] = {eft_DBL, (void*)dpnp_inv_default_c<float, double>};
fmap[DPNPFuncName::DPNP_FN_INV][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_inv_default_c<double, double>};

fmap[DPNPFuncName::DPNP_FN_INV_EXT][eft_INT][eft_INT] = {eft_DBL, (void*)dpnp_inv_ext_c<int32_t, double>};
fmap[DPNPFuncName::DPNP_FN_INV_EXT][eft_LNG][eft_LNG] = {eft_DBL, (void*)dpnp_inv_ext_c<int64_t, double>};
fmap[DPNPFuncName::DPNP_FN_INV_EXT][eft_FLT][eft_FLT] = {eft_DBL, (void*)dpnp_inv_ext_c<float, double>};
fmap[DPNPFuncName::DPNP_FN_INV_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_inv_ext_c<double, double>};

fmap[DPNPFuncName::DPNP_FN_KRON][eft_INT][eft_INT] = {eft_INT,
(void*)dpnp_kron_default_c<int32_t, int32_t, int32_t>};
fmap[DPNPFuncName::DPNP_FN_KRON][eft_INT][eft_LNG] = {eft_LNG,
Expand Down Expand Up @@ -989,19 +1002,46 @@ void func_map_init_linalg_func(func_map_t& fmap)
fmap[DPNPFuncName::DPNP_FN_MATRIX_RANK][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_matrix_rank_default_c<float>};
fmap[DPNPFuncName::DPNP_FN_MATRIX_RANK][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_matrix_rank_default_c<double>};

fmap[DPNPFuncName::DPNP_FN_MATRIX_RANK_EXT][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_matrix_rank_ext_c<int32_t>};
fmap[DPNPFuncName::DPNP_FN_MATRIX_RANK_EXT][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_matrix_rank_ext_c<int64_t>};
fmap[DPNPFuncName::DPNP_FN_MATRIX_RANK_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_matrix_rank_ext_c<float>};
fmap[DPNPFuncName::DPNP_FN_MATRIX_RANK_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_matrix_rank_ext_c<double>};

fmap[DPNPFuncName::DPNP_FN_QR][eft_INT][eft_INT] = {eft_DBL, (void*)dpnp_qr_default_c<int32_t, double>};
fmap[DPNPFuncName::DPNP_FN_QR][eft_LNG][eft_LNG] = {eft_DBL, (void*)dpnp_qr_default_c<int64_t, double>};
fmap[DPNPFuncName::DPNP_FN_QR][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_qr_default_c<float, float>};
fmap[DPNPFuncName::DPNP_FN_QR][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_qr_default_c<double, double>};
// fmap[DPNPFuncName::DPNP_FN_QR][eft_C128][eft_C128] = {
// eft_C128, (void*)dpnp_qr_c<std::complex<double>, std::complex<double>>};

fmap[DPNPFuncName::DPNP_FN_SVD][eft_INT][eft_INT] = {eft_DBL, (void*)dpnp_svd_default_c<int32_t, double, double>};
fmap[DPNPFuncName::DPNP_FN_SVD][eft_LNG][eft_LNG] = {eft_DBL, (void*)dpnp_svd_default_c<int64_t, double, double>};
fmap[DPNPFuncName::DPNP_FN_SVD][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_svd_default_c<float, float, float>};
fmap[DPNPFuncName::DPNP_FN_SVD][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_svd_default_c<double, double, double>};
fmap[DPNPFuncName::DPNP_FN_QR_EXT][eft_INT][eft_INT] = {eft_DBL, (void*)dpnp_qr_ext_c<int32_t, double>};
fmap[DPNPFuncName::DPNP_FN_QR_EXT][eft_LNG][eft_LNG] = {eft_DBL, (void*)dpnp_qr_ext_c<int64_t, double>};
fmap[DPNPFuncName::DPNP_FN_QR_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_qr_ext_c<float, float>};
fmap[DPNPFuncName::DPNP_FN_QR_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_qr_ext_c<double, double>};
// fmap[DPNPFuncName::DPNP_FN_QR_EXT][eft_C128][eft_C128] = {
// eft_C128, (void*)dpnp_qr_c<std::complex<double>, std::complex<double>>};

fmap[DPNPFuncName::DPNP_FN_SVD][eft_INT][eft_INT] = {eft_DBL,
(void*)dpnp_svd_default_c<int32_t, double, double>};
fmap[DPNPFuncName::DPNP_FN_SVD][eft_LNG][eft_LNG] = {eft_DBL,
(void*)dpnp_svd_default_c<int64_t, double, double>};
fmap[DPNPFuncName::DPNP_FN_SVD][eft_FLT][eft_FLT] = {eft_FLT,
(void*)dpnp_svd_default_c<float, float, float>};
fmap[DPNPFuncName::DPNP_FN_SVD][eft_DBL][eft_DBL] = {eft_DBL,
(void*)dpnp_svd_default_c<double, double, double>};
fmap[DPNPFuncName::DPNP_FN_SVD][eft_C128][eft_C128] = {
eft_C128, (void*)dpnp_svd_default_c<std::complex<double>, std::complex<double>, double>};

fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_INT][eft_INT] = {eft_DBL,
(void*)dpnp_svd_ext_c<int32_t, double, double>};
fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_LNG][eft_LNG] = {eft_DBL,
(void*)dpnp_svd_ext_c<int64_t, double, double>};
fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_FLT][eft_FLT] = {eft_FLT,
(void*)dpnp_svd_ext_c<float, float, float>};
fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_DBL][eft_DBL] = {eft_DBL,
(void*)dpnp_svd_ext_c<double, double, double>};
fmap[DPNPFuncName::DPNP_FN_SVD_EXT][eft_C128][eft_C128] = {
eft_C128, (void*)dpnp_svd_ext_c<std::complex<double>, std::complex<double>, double>};

return;
}
3 changes: 1 addition & 2 deletions dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
# *****************************************************************************
cimport dpctl as c_dpctl

cimport dpctl as c_dpctl

from libcpp cimport bool as cpp_bool

from dpnp.dpnp_utils.dpnp_algo_utils cimport dpnp_descriptor
Expand Down Expand Up @@ -145,6 +143,7 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_FFT_FFT
DPNP_FN_FFT_FFT_EXT
DPNP_FN_FFT_RFFT
DPNP_FN_FFT_RFFT_EXT
DPNP_FN_FILL_DIAGONAL
DPNP_FN_FILL_DIAGONAL_EXT
DPNP_FN_FLATTEN
Expand Down
1 change: 1 addition & 0 deletions dpnp/dpnp_algo/dpnp_algo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ cdef DPNPFuncType dpnp_dtype_to_DPNPFuncType(dtype):
if isinstance(kind, int):
kind = chr(kind)
itemsize = numpy.dtype(dtype).itemsize
print(f"dpnp_dtype_to_DPNPFuncType: dtype={dtype}, dt_c={dt_c}, kind={kind}, itemsize={itemsize}")

if dt_c == 'd':
return DPNP_FT_DOUBLE
Expand Down
20 changes: 20 additions & 0 deletions dpnp/dpnp_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,38 @@ def asarray(x1,
usm_type=None,
sycl_queue=None):
"""Converts `x1` to `dpnp_array`."""
print(f"asarray: x1.dtype={x1.dtype}")
print(f"asarray: x1={x1}, dtype={dtype}, copy={copy}, order={order}, device={device}, usm_type={usm_type}, sycl_queue={sycl_queue}")
if isinstance(x1, dpnp_array):
print("asarray: instance of dpnp_array?")
x1_obj = x1.get_array()
else:
x1_obj = x1

sycl_queue_normalized = normalize_queue_device(sycl_queue=sycl_queue, device=device)
print(f"asarray: sycl_queue_normalized={sycl_queue_normalized}")
print(f"asarray: before dpctl: x1_obj.dtype={x1_obj.dtype}")
array_obj = dpt.asarray(x1_obj,
dtype=dtype,
copy=copy,
order=order,
usm_type=usm_type,
sycl_queue=sycl_queue_normalized)
print(f"asarray: after dpctl: array_obj.dtype={array_obj.dtype}")

# test dpctl call:
obj_no_dtype = dpt.asarray(x1, dtype=None, copy=True, order="C")
print(f"dpt.asarray with dtype=None: obj_no_dtype.dtype={obj_no_dtype.dtype}")

obj_w_dtype = dpt.asarray(x1, dtype=numpy.float64, copy=True, order="C")
print(f"dpt.asarray with dtype=numpy.float64: obj_w_dtype.dtype={obj_w_dtype.dtype}")

try:
import dpctl.tensor._tensor_impl as ti
dt_from_ti = ti.default_device_fp_type(sycl_queue_normalized)
print(f"default_device_fp_type: dt_from_ti={dt_from_ti}")
except ImportError as err:
print(f"DOCBUILD: Can't load dpctl.tensor._tensor_impl module with error={err}")

return dpnp_array(array_obj.shape, buffer=array_obj, order=order)

Expand Down
12 changes: 12 additions & 0 deletions dpnp/dpnp_iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def get_dpnp_descriptor(ext_obj, copy_when_strides=True, copy_when_nondefault_qu
# if no_modules_load_doc_build();
# return False

print(f"get_dpnp_descriptor: enter: ext_obj.dtype={ext_obj.dtype}")

if use_origin_backend():
return False

Expand All @@ -219,22 +221,32 @@ def get_dpnp_descriptor(ext_obj, copy_when_strides=True, copy_when_nondefault_qu
ext_obj_offset = 0

if ext_obj.strides != shape_offsets or ext_obj_offset != 0:
print("get_dpnp_descriptor: create non-strides copy")
ext_obj = array(ext_obj)
else:
print("get_dpnp_descriptor: no need to create non-strides copy")

print(f"get_dpnp_descriptor: if non-strided copy: ext_obj.dtype={ext_obj.dtype}")

# while dpnp functions are based on DPNP_QUEUE
# we need to create a copy on device associated with DPNP_QUEUE
# if function get implementation for different queue
# then this behavior can be disabled with setting "copy_when_nondefault_queue"
arr_obj = unwrap_array(ext_obj)
print(f"get_dpnp_descriptor: arr_obj.dtype={arr_obj.dtype}")

queue = getattr(arr_obj, "sycl_queue", None)
if queue is not None and copy_when_nondefault_queue:
default_queue = dpctl.SyclQueue()
queue_is_default = dpctl.utils.get_execution_queue([queue, default_queue]) is not None
if not queue_is_default:
ext_obj = array(arr_obj, sycl_queue=default_queue)

print(f"get_dpnp_descriptor: if new queue: arr_obj.dtype={arr_obj.dtype}")

dpnp_desc = dpnp_descriptor(ext_obj)
if dpnp_desc.is_valid:
print(f"get_dpnp_descriptor: return: dpnp_desc.dtype={dpnp_desc.dtype}")
return dpnp_desc

return False
Expand Down
8 changes: 8 additions & 0 deletions dpnp/dpnp_utils/dpnp_algo_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ cdef dpnp_descriptor create_output_descriptor(shape_type_c output_shape,
if sycl_queue is not None:
device = None
result_dtype = dpnp_DPNPFuncType_to_dtype(< size_t > c_type)
print(f"create_output_descriptor: result_dtype={result_dtype}")
result_obj = dpnp_container.empty(output_shape,
dtype=result_dtype,
device=device,
Expand Down Expand Up @@ -570,6 +571,8 @@ cdef class dpnp_descriptor:
self.dpnp_descriptor_data_size = 0
self.dpnp_descriptor_is_scalar = True

print("dpnp_descriptor: __init__")

""" Accure DPCTL data container storage """
self.descriptor = getattr(obj, "__sycl_usm_array_interface__", None)
if self.descriptor is None:
Expand All @@ -581,8 +584,12 @@ cdef class dpnp_descriptor:

if self.descriptor["version"] != 3:
return
else:
print("dpnp_descriptor: has __sycl_usm_array_interface__ attr")
print(f"dpnp_descriptor: self.descriptor={self.descriptor}")

self.origin_pyobj = obj
print(f"dpnp_descriptor: obj.dtype={obj.dtype}")

""" array size calculation """
cdef Py_ssize_t shape_it = 0
Expand Down Expand Up @@ -630,6 +637,7 @@ cdef class dpnp_descriptor:
def dtype(self):
if self.is_valid:
type_str = self.descriptor["typestr"]
print(f"dtype: type_str={type_str}")
return dpnp.dtype(type_str)
return None

Expand Down
Loading