Skip to content

Commit

Permalink
update dpnp.cross (#1715)
Browse files Browse the repository at this point in the history
* update dpnp.cross

* rename test file in github actions

* address comments

* use direct call of multiply etc from dpctl to have async calculation

* add braodcasting
  • Loading branch information
vtavana authored Feb 21, 2024
1 parent e6e7b3e commit 95fdbec
Show file tree
Hide file tree
Showing 12 changed files with 560 additions and 265 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ env:
TEST_SCOPE: >-
test_arraycreation.py
test_amin_amax.py
test_dot.py
test_dparray.py
test_copy.py
test_fft.py
test_linalg.py
test_logic.py
test_manipulation.py
test_mathematical.py
test_product.py
test_random_state.py
test_sort.py
test_special.py
Expand Down
2 changes: 0 additions & 2 deletions dpnp/backend/include/dpnp_iface_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ enum class DPNPFuncName : size_t
DPNP_FN_COUNT_NONZERO, /**< Used in numpy.count_nonzero() impl */
DPNP_FN_COV, /**< Used in numpy.cov() impl */
DPNP_FN_CROSS, /**< Used in numpy.cross() impl */
DPNP_FN_CROSS_EXT, /**< Used in numpy.cross() impl, requires extra
parameters */
DPNP_FN_CUMPROD, /**< Used in numpy.cumprod() impl */
DPNP_FN_CUMPROD_EXT, /**< Used in numpy.cumprod() impl, requires extra
parameters */
Expand Down
45 changes: 0 additions & 45 deletions dpnp/backend/kernels/dpnp_krnl_mathematical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,6 @@ void (*dpnp_cross_default_c)(void *,
const size_t *) =
dpnp_cross_c<_DataType_output, _DataType_input1, _DataType_input2>;

template <typename _DataType_output,
typename _DataType_input1,
typename _DataType_input2>
DPCTLSyclEventRef (*dpnp_cross_ext_c)(DPCTLSyclQueueRef,
void *,
const void *,
const size_t,
const shape_elem_type *,
const size_t,
const void *,
const size_t,
const shape_elem_type *,
const size_t,
const size_t *,
const DPCTLEventVectorRef) =
dpnp_cross_c<_DataType_output, _DataType_input1, _DataType_input2>;

template <typename _KernelNameSpecialization1,
typename _KernelNameSpecialization2>
class dpnp_cumprod_c_kernel;
Expand Down Expand Up @@ -1116,31 +1099,6 @@ DPCTLSyclEventRef (*dpnp_trapz_ext_c)(DPCTLSyclQueueRef,
const DPCTLEventVectorRef) =
dpnp_trapz_c<_DataType_input1, _DataType_input2, _DataType_output>;

template <DPNPFuncType FT1, DPNPFuncType... FTs>
static void func_map_elemwise_2arg_3type_core(func_map_t &fmap)
{
((fmap[DPNPFuncName::DPNP_FN_CROSS_EXT][FT1][FTs] =
{get_floating_res_type<FT1, FTs, std::true_type, std::true_type>(),
(void *)dpnp_cross_ext_c<
func_type_map_t::find_type<get_floating_res_type<
FT1, FTs, std::true_type, std::true_type>()>,
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>,
get_floating_res_type<FT1, FTs, std::false_type, std::true_type>(),
(void *)dpnp_cross_ext_c<
func_type_map_t::find_type<get_floating_res_type<
FT1, FTs, std::false_type, std::true_type>()>,
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>}),
...);
}

template <DPNPFuncType... FTs>
static void func_map_elemwise_2arg_3type_helper(func_map_t &fmap)
{
((func_map_elemwise_2arg_3type_core<FTs, FTs...>(fmap)), ...);
}

void func_map_init_mathematical(func_map_t &fmap)
{
fmap[DPNPFuncName::DPNP_FN_ABSOLUTE][eft_INT][eft_INT] = {
Expand Down Expand Up @@ -1402,8 +1360,5 @@ void func_map_init_mathematical(func_map_t &fmap)
fmap[DPNPFuncName::DPNP_FN_TRAPZ_EXT][eft_DBL][eft_DBL] = {
eft_DBL, (void *)dpnp_trapz_ext_c<double, double, double>};

func_map_elemwise_2arg_3type_helper<eft_INT, eft_LNG, eft_FLT, eft_DBL>(
fmap);

return;
}
2 changes: 0 additions & 2 deletions dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_COPY_EXT
DPNP_FN_CORRELATE
DPNP_FN_CORRELATE_EXT
DPNP_FN_CROSS
DPNP_FN_CROSS_EXT
DPNP_FN_CUMPROD
DPNP_FN_CUMPROD_EXT
DPNP_FN_CUMSUM
Expand Down
71 changes: 0 additions & 71 deletions dpnp/dpnp_algo/dpnp_algo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -278,77 +278,6 @@ cdef utils.dpnp_descriptor call_fptr_1in_1out_strides(DPNPFuncName fptr_name,
return result


cdef utils.dpnp_descriptor call_fptr_2in_1out(DPNPFuncName fptr_name,
utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
utils.dpnp_descriptor out=None,
object where=True,
func_name=None):

# Convert type (x1_obj.dtype) to C enum DPNPFuncType
cdef DPNPFuncType x1_c_type = dpnp_dtype_to_DPNPFuncType(x1_obj.dtype)
cdef DPNPFuncType x2_c_type = dpnp_dtype_to_DPNPFuncType(x2_obj.dtype)

# 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_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

if out is None:
""" Create result array with type given by FPTR data """
result = utils.create_output_descriptor(result_shape,
return_type,
None,
device=result_sycl_device,
usm_type=result_usm_type,
sycl_queue=result_sycl_queue)
else:
if out.dtype != result_type:
utils.checker_throw_value_error(func_name, 'out.dtype', out.dtype, result_type)
if out.shape != result_shape:
utils.checker_throw_value_error(func_name, 'out.shape', out.shape, result_shape)

result = out

utils.get_common_usm_allocation(x1_obj, result) # check USM allocation is common

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

""" Call FPTR function """
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
result.get_data(),
x1_obj.get_data(),
x1_obj.size,
x1_shape.data(),
x1_shape.size(),
x2_obj.get_data(),
x2_obj.size,
x2_shape.data(),
x2_shape.size(),
NULL,
NULL) # dep_events_ref)

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

return result

cdef utils.dpnp_descriptor call_fptr_2in_1out_strides(DPNPFuncName fptr_name,
utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
Expand Down
9 changes: 0 additions & 9 deletions dpnp/dpnp_algo/dpnp_algo_mathematical.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ and the rest of the library
# NO IMPORTs here. All imports must be placed into main "dpnp_algo.pyx" file

__all__ += [
"dpnp_cross",
"dpnp_cumprod",
"dpnp_cumsum",
"dpnp_ediff1d",
Expand All @@ -60,14 +59,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*ftpr_custom_trapz_2in_1out_with_2size_t)(c_d
const c_dpctl.DPCTLEventVectorRef)


cpdef utils.dpnp_descriptor dpnp_cross(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
utils.dpnp_descriptor out=None,
object where=True):
return call_fptr_2in_1out(DPNP_FN_CROSS_EXT, x1_obj, x2_obj, dtype, out, where)


cpdef utils.dpnp_descriptor dpnp_cumprod(utils.dpnp_descriptor x1):
# instead of x1.shape, (x1.size, ) is passed to the function
# due to the following:
Expand Down
Loading

0 comments on commit 95fdbec

Please sign in to comment.