Skip to content
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
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ e62718415aa3660da5f607e352c991a063a54219

# Bump clang-format from 12.0.1 to 22.1.0 version
c2d65bd451a7d8e5b6319147da95e9dabf7a382b

# cython-lint cleanup
6afda951b26d59aee7488f40c40968feb4725ad8
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ repos:
- id: gersemi
exclude: "dpnp/backend/cmake/Modules/"
args: ["-i", "-l", "88", "--no-warn-about-unknown-commands"]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.19.0
hooks:
- id: cython-lint
- id: double-quote-cython-strings
12 changes: 9 additions & 3 deletions dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
# *****************************************************************************


cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this namespace for Enum import
# need this namespace for Enum import
cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName":
cdef enum DPNPFuncName "DPNPFuncName":
DPNP_FN_PARTITION_EXT
DPNP_FN_RNG_BETA_EXT
Expand Down Expand Up @@ -70,7 +71,8 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_RNG_WEIBULL_EXT
DPNP_FN_RNG_ZIPF_EXT

cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncType": # need this namespace for Enum import
# need this namespace for Enum import
cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncType":
cdef enum DPNPFuncType "DPNPFuncType":
DPNP_FT_NONE
DPNP_FT_INT
Expand All @@ -88,7 +90,11 @@ cdef extern from "dpnp_iface_fptr.hpp":
DPNPFuncType return_type_no_fp64
void *ptr_no_fp64

DPNPFuncData get_dpnp_function_ptr(DPNPFuncName name, DPNPFuncType first_type, DPNPFuncType second_type) except +
DPNPFuncData get_dpnp_function_ptr(
DPNPFuncName name,
DPNPFuncType first_type,
DPNPFuncType second_type,
) except +


"""
Expand Down
15 changes: 8 additions & 7 deletions dpnp/dpnp_algo/dpnp_algo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,31 @@ cdef DPNPFuncType dpnp_dtype_to_DPNPFuncType(dtype):
kind = chr(kind)
itemsize = dpnp.dtype(dtype).itemsize

if dt_c == 'd':
if dt_c == "d":
return DPNP_FT_DOUBLE
elif dt_c == 'f':
elif dt_c == "f":
return DPNP_FT_FLOAT
elif kind == 'i':
elif kind == "i":
if itemsize == 8:
return DPNP_FT_LONG
elif itemsize == 4:
return DPNP_FT_INT
else:
utils.checker_throw_type_error("dpnp_dtype_to_DPNPFuncType", dtype)
elif dt_c == 'F':
elif dt_c == "F":
return DPNP_FT_CMPLX64
elif dt_c == 'D':
elif dt_c == "D":
return DPNP_FT_CMPLX128
elif dt_c == '?':
elif dt_c == "?":
return DPNP_FT_BOOL
else:
utils.checker_throw_type_error("dpnp_dtype_to_DPNPFuncType", dtype)


cdef dpnp_DPNPFuncType_to_dtype(size_t type):
"""
Type 'size_t' used instead 'DPNPFuncType' because Cython has lack of Enum support (0.29)
Type 'size_t' used instead 'DPNPFuncType' because
Cython has lack of Enum support (0.29)
TODO needs to use DPNPFuncType here
"""
if type == <size_t > DPNP_FT_DOUBLE:
Expand Down
6 changes: 5 additions & 1 deletion dpnp/dpnp_algo/dpnp_algo_indexing.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ __all__ += [
"dpnp_putmask",
]

cpdef dpnp_putmask(utils.dpnp_descriptor arr, utils.dpnp_descriptor mask, utils.dpnp_descriptor values):
cpdef dpnp_putmask(
utils.dpnp_descriptor arr,
utils.dpnp_descriptor mask,
utils.dpnp_descriptor values,
):
cdef int values_size = values.size

mask_flatiter = mask.get_pyobj().flat
Expand Down
109 changes: 71 additions & 38 deletions dpnp/dpnp_algo/dpnp_algo_sorting.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -43,52 +43,85 @@ __all__ += [
]


ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_partition_t)(c_dpctl.DPCTLSyclQueueRef,
void * ,
void * ,
void * ,
const size_t,
const shape_elem_type * ,
const size_t,
const c_dpctl.DPCTLEventVectorRef)


cpdef utils.dpnp_descriptor dpnp_partition(utils.dpnp_descriptor arr, int kth, axis=-1, kind='introselect', order=None):
ctypedef c_dpctl.DPCTLSyclEventRef(
*fptr_dpnp_partition_t)(
c_dpctl.DPCTLSyclQueueRef,
void *,
void *,
void *,
const size_t,
const shape_elem_type *,
const size_t,
const c_dpctl.DPCTLEventVectorRef,
)


cpdef utils.dpnp_descriptor dpnp_partition(
utils.dpnp_descriptor arr, int kth,
axis=-1, kind="introselect", order=None,
):
cdef shape_type_c shape1 = arr.shape

cdef size_t kth_ = kth if kth >= 0 else (arr.ndim + kth)
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(arr.dtype)

cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_PARTITION_EXT, param1_type, param1_type)

cdef utils.dpnp_descriptor arr2 = dpnp.get_dpnp_descriptor(arr.get_pyobj().copy(), copy_when_nondefault_queue=False)
cdef size_t kth_ = (
kth if kth >= 0 else (arr.ndim + kth)
)
cdef DPNPFuncType param1_type = (
dpnp_dtype_to_DPNPFuncType(arr.dtype)
)

cdef DPNPFuncData kernel_data = (
get_dpnp_function_ptr(
DPNP_FN_PARTITION_EXT,
param1_type, param1_type,
)
)

cdef utils.dpnp_descriptor arr2 = (
dpnp.get_dpnp_descriptor(
arr.get_pyobj().copy(),
copy_when_nondefault_queue=False,
)
)

arr_obj = arr.get_array()

cdef utils.dpnp_descriptor result = utils.create_output_descriptor(arr.shape,
kernel_data.return_type,
None,
device=arr_obj.sycl_device,
usm_type=arr_obj.usm_type,
sycl_queue=arr_obj.sycl_queue)
cdef utils.dpnp_descriptor result = (
utils.create_output_descriptor(
arr.shape,
kernel_data.return_type,
None,
device=arr_obj.sycl_device,
usm_type=arr_obj.usm_type,
sycl_queue=arr_obj.sycl_queue,
)
)

result_sycl_queue = result.get_array().sycl_queue

cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()

cdef fptr_dpnp_partition_t func = <fptr_dpnp_partition_t > kernel_data.ptr

cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
arr.get_data(),
arr2.get_data(),
result.get_data(),
kth_,
shape1.data(),
arr.ndim,
NULL) # dep_events_ref

with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
cdef c_dpctl.SyclQueue q = (
<c_dpctl.SyclQueue> result_sycl_queue
)
cdef c_dpctl.DPCTLSyclQueueRef q_ref = (
q.get_queue_ref()
)

cdef fptr_dpnp_partition_t func = (
<fptr_dpnp_partition_t> kernel_data.ptr
)

cdef c_dpctl.DPCTLSyclEventRef event_ref = func(
q_ref,
arr.get_data(),
arr2.get_data(),
result.get_data(),
kth_,
shape1.data(),
arr.ndim,
NULL,
)

with nogil:
c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
c_dpctl.DPCTLEvent_Delete(event_ref)

return result
Loading
Loading