Skip to content

Use get_ret_type_and_func in call_fptr functions #1500

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

Merged
merged 8 commits into from
Jul 26, 2023
43 changes: 28 additions & 15 deletions dpnp/dpnp_algo/dpnp_algo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,15 @@ cdef utils.dpnp_descriptor call_fptr_1in_1out_strides(DPNPFuncName fptr_name,
""" get the FPTR data structure """
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(fptr_name, param1_type, param1_type)

result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
x1_obj = x1.get_array()

# get FPTR function and return type
cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
x1_obj.sycl_device.has_aspect_fp64)
cdef DPNPFuncType return_type = ret_type_and_func[0]
cdef fptr_1in_1out_strides_t func = < fptr_1in_1out_strides_t > ret_type_and_func[1]

result_type = dpnp_DPNPFuncType_to_dtype( < size_t > return_type)

cdef shape_type_c x1_shape = x1.shape
cdef shape_type_c x1_strides = utils.strides_to_vector(x1.strides, x1_shape)
Expand All @@ -358,9 +366,8 @@ cdef utils.dpnp_descriptor call_fptr_1in_1out_strides(DPNPFuncName fptr_name,

if out is None:
""" Create result array with type given by FPTR data """
x1_obj = x1.get_array()
result = utils.create_output_descriptor(result_shape,
kernel_data.return_type,
return_type,
None,
device=x1_obj.sycl_device,
usm_type=x1_obj.usm_type,
Expand All @@ -383,7 +390,6 @@ cdef utils.dpnp_descriptor call_fptr_1in_1out_strides(DPNPFuncName fptr_name,
cdef shape_type_c result_strides = utils.strides_to_vector(result.strides, result_shape)

""" Call FPTR function """
cdef fptr_1in_1out_strides_t func = <fptr_1in_1out_strides_t > kernel_data.ptr
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
result.get_data(),
result.size,
Expand Down Expand Up @@ -419,20 +425,26 @@ cdef utils.dpnp_descriptor call_fptr_2in_1out(DPNPFuncName fptr_name,
# get the FPTR data structure
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(fptr_name, x1_c_type, x2_c_type)

result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
result_sycl_device, result_usm_type, result_sycl_queue = utils.get_common_usm_allocation(x1_obj, x2_obj)

# get FPTR function and return type
cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
result_sycl_device.has_aspect_fp64)
cdef DPNPFuncType return_type = ret_type_and_func[0]
cdef fptr_2in_1out_t func = < fptr_2in_1out_t > ret_type_and_func[1]

result_type = dpnp_DPNPFuncType_to_dtype( < size_t > return_type)

# Create result array
cdef shape_type_c x1_shape = x1_obj.shape
cdef shape_type_c x2_shape = x2_obj.shape
cdef shape_type_c result_shape = utils.get_common_shape(x1_shape, x2_shape)
cdef utils.dpnp_descriptor result

result_sycl_device, result_usm_type, result_sycl_queue = utils.get_common_usm_allocation(x1_obj, x2_obj)

if out is None:
""" Create result array with type given by FPTR data """
result = utils.create_output_descriptor(result_shape,
kernel_data.return_type,
return_type,
None,
device=result_sycl_device,
usm_type=result_usm_type,
Expand All @@ -451,7 +463,6 @@ cdef utils.dpnp_descriptor call_fptr_2in_1out(DPNPFuncName fptr_name,
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()

""" Call FPTR function """
cdef fptr_2in_1out_t func = <fptr_2in_1out_t > kernel_data.ptr
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
result.get_data(),
x1_obj.get_data(),
Expand Down Expand Up @@ -485,6 +496,14 @@ cdef utils.dpnp_descriptor call_fptr_2in_1out_strides(DPNPFuncName fptr_name,
# get the FPTR data structure
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(fptr_name, x1_c_type, x2_c_type)

result_sycl_device, result_usm_type, result_sycl_queue = utils.get_common_usm_allocation(x1_obj, x2_obj)

# get FPTR function and return type
cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
result_sycl_device.has_aspect_fp64)
cdef DPNPFuncType return_type = ret_type_and_func[0]
cdef fptr_2in_1out_strides_t func = < fptr_2in_1out_strides_t > ret_type_and_func[1]

# Create result array
cdef shape_type_c x1_shape = x1_obj.shape

Expand All @@ -495,12 +514,6 @@ cdef utils.dpnp_descriptor call_fptr_2in_1out_strides(DPNPFuncName fptr_name,
cdef shape_type_c result_shape = utils.get_common_shape(x1_shape, x2_shape)
cdef utils.dpnp_descriptor result

result_sycl_device, result_usm_type, result_sycl_queue = utils.get_common_usm_allocation(x1_obj, x2_obj)

# get FPTR function and return type
cdef fptr_2in_1out_strides_t func = < fptr_2in_1out_strides_t > kernel_data.ptr
cdef DPNPFuncType return_type = kernel_data.return_type

# check 'out' parameter data
if out is not None:
if out.shape != result_shape:
Expand Down
3 changes: 2 additions & 1 deletion dpnp/dpnp_algo/dpnp_algo_statistics.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ cpdef utils.dpnp_descriptor dpnp_median(utils.dpnp_descriptor array1):

array1_obj = array1.get_array()

cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(array1_obj, kernel_data)
cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
array1_obj.sycl_device.has_aspect_fp64)
cdef DPNPFuncType return_type = ret_type_and_func[0]
cdef custom_statistic_1in_1out_func_ptr_t func = < custom_statistic_1in_1out_func_ptr_t > ret_type_and_func[1]

Expand Down
5 changes: 3 additions & 2 deletions dpnp/dpnp_utils/dpnp_algo_utils.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ cdef tuple get_common_usm_allocation(dpnp_descriptor x1, dpnp_descriptor x2)
Get common USM allocation in the form of (sycl_device, usm_type, sycl_queue)
"""

cdef (DPNPFuncType, void *) get_ret_type_and_func(x1_obj, DPNPFuncData kernel_data)
cdef (DPNPFuncType, void *) get_ret_type_and_func(DPNPFuncData kernel_data,
cpp_bool has_aspect_fp64)
"""
Get the corresponding return type and function pointer based on the
capability of the allocated input array device for the integer types.
capability of the allocated result array device.
"""
17 changes: 12 additions & 5 deletions dpnp/dpnp_utils/dpnp_algo_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,20 @@ cdef tuple get_common_usm_allocation(dpnp_descriptor x1, dpnp_descriptor x2):
return (common_sycl_queue.sycl_device, common_usm_type, common_sycl_queue)


cdef (DPNPFuncType, void *) get_ret_type_and_func(x1_obj, DPNPFuncData kernel_data):
if dpnp.issubdtype(x1_obj.dtype, dpnp.integer) and not x1_obj.sycl_device.has_aspect_fp64:
cdef (DPNPFuncType, void *) get_ret_type_and_func(DPNPFuncData kernel_data,
cpp_bool has_aspect_fp64):
"""
This function is responsible for determining the appropriate return type
and function pointer based on the capability of the allocated result array device.
"""
return_type = kernel_data.return_type
func = kernel_data.ptr

if kernel_data.ptr_no_fp64 != NULL and not has_aspect_fp64:

return_type = kernel_data.return_type_no_fp64
func = kernel_data.ptr_no_fp64
else:
return_type = kernel_data.return_type
func = kernel_data.ptr

return return_type, func


Expand Down
4 changes: 2 additions & 2 deletions dpnp/dpnp_utils/dpnp_utils_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def _get_2dmin_array(x, dtype):
dtypes = [m.dtype, dpnp.default_float_type(sycl_queue=queue)]
if y is not None:
dtypes.append(y.dtype)
dtype = dpt.result_type(*dtypes)
# TODO: remove when dpctl.result_type() is fixed
dtype = dpnp.result_type(*dtypes)
# TODO: remove when dpctl.result_type() is returned dtype based on fp64
fp64 = queue.sycl_device.has_aspect_fp64
if not fp64:
if dtype == dpnp.float64:
Expand Down
15 changes: 10 additions & 5 deletions dpnp/linalg/dpnp_algo_linalg.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ cpdef tuple dpnp_eig(utils.dpnp_descriptor x1):

x1_obj = x1.get_array()

cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(x1_obj, kernel_data)
cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
x1_obj.sycl_device.has_aspect_fp64)
cdef DPNPFuncType return_type = ret_type_and_func[0]
cdef custom_linalg_2in_1out_func_ptr_t func = < custom_linalg_2in_1out_func_ptr_t > ret_type_and_func[1]

Expand Down Expand Up @@ -242,7 +243,8 @@ cpdef utils.dpnp_descriptor dpnp_eigvals(utils.dpnp_descriptor input):

input_obj = input.get_array()

cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(input_obj, kernel_data)
cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
input_obj.sycl_device.has_aspect_fp64)
cdef DPNPFuncType return_type = ret_type_and_func[0]
cdef custom_linalg_1in_1out_with_size_func_ptr_t_ func = < custom_linalg_1in_1out_with_size_func_ptr_t_ > ret_type_and_func[1]

Expand Down Expand Up @@ -281,7 +283,8 @@ cpdef utils.dpnp_descriptor dpnp_inv(utils.dpnp_descriptor input):

input_obj = input.get_array()

cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(input_obj, kernel_data)
cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
input_obj.sycl_device.has_aspect_fp64)
cdef DPNPFuncType return_type = ret_type_and_func[0]
cdef custom_linalg_1in_1out_func_ptr_t func = < custom_linalg_1in_1out_func_ptr_t > ret_type_and_func[1]

Expand Down Expand Up @@ -462,7 +465,8 @@ cpdef tuple dpnp_qr(utils.dpnp_descriptor x1, str mode):

x1_obj = x1.get_array()

cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(x1_obj, kernel_data)
cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
x1_obj.sycl_device.has_aspect_fp64)
cdef DPNPFuncType return_type = ret_type_and_func[0]
cdef custom_linalg_1in_3out_shape_t func = < custom_linalg_1in_3out_shape_t > ret_type_and_func[1]

Expand Down Expand Up @@ -515,7 +519,8 @@ cpdef tuple dpnp_svd(utils.dpnp_descriptor x1, cpp_bool full_matrices, cpp_bool

x1_obj = x1.get_array()

cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(x1_obj, kernel_data)
cdef (DPNPFuncType, void *) ret_type_and_func = utils.get_ret_type_and_func(kernel_data,
x1_obj.sycl_device.has_aspect_fp64)
cdef DPNPFuncType return_type = ret_type_and_func[0]
cdef custom_linalg_1in_3out_shape_t func = < custom_linalg_1in_3out_shape_t > ret_type_and_func[1]

Expand Down