Skip to content

use_dpctl_remainder_func #1515

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 5 commits into from
Aug 17, 2023
Merged
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
36 changes: 17 additions & 19 deletions dpnp/backend/include/dpnp_iface_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,23 @@ enum class DPNPFuncName : size_t
DPNP_FN_PUT_ALONG_AXIS_EXT, /**< Used in numpy.put_along_axis() impl,
requires extra parameters */
DPNP_FN_QR, /**< Used in numpy.linalg.qr() impl */
DPNP_FN_QR_EXT, /**< Used in numpy.linalg.qr() impl, requires extra
parameters */
DPNP_FN_RADIANS, /**< Used in numpy.radians() impl */
DPNP_FN_RADIANS_EXT, /**< Used in numpy.radians() impl, requires extra
parameters */
DPNP_FN_REMAINDER, /**< Used in numpy.remainder() impl */
DPNP_FN_REMAINDER_EXT, /**< Used in numpy.remainder() impl, requires extra
parameters */
DPNP_FN_RECIP, /**< Used in numpy.recip() impl */
DPNP_FN_RECIP_EXT, /**< Used in numpy.recip() impl, requires extra
parameters */
DPNP_FN_REPEAT, /**< Used in numpy.repeat() impl */
DPNP_FN_REPEAT_EXT, /**< Used in numpy.repeat() impl, requires extra
parameters */
DPNP_FN_RIGHT_SHIFT, /**< Used in numpy.right_shift() impl */
DPNP_FN_RNG_BETA, /**< Used in numpy.random.beta() impl */
DPNP_FN_RNG_BETA_EXT, /**< Used in numpy.random.beta() impl, requires extra
parameters */
DPNP_FN_RNG_BINOMIAL, /**< Used in numpy.random.binomial() impl */
DPNP_FN_QR_EXT, /**< Used in numpy.linalg.qr() impl, requires extra
parameters */
DPNP_FN_RADIANS, /**< Used in numpy.radians() impl */
DPNP_FN_RADIANS_EXT, /**< Used in numpy.radians() impl, requires extra
parameters */
DPNP_FN_REMAINDER, /**< Used in numpy.remainder() impl */
DPNP_FN_RECIP, /**< Used in numpy.recip() impl */
DPNP_FN_RECIP_EXT, /**< Used in numpy.recip() impl, requires extra
parameters */
DPNP_FN_REPEAT, /**< Used in numpy.repeat() impl */
DPNP_FN_REPEAT_EXT, /**< Used in numpy.repeat() impl, requires extra
parameters */
DPNP_FN_RIGHT_SHIFT, /**< Used in numpy.right_shift() impl */
DPNP_FN_RNG_BETA, /**< Used in numpy.random.beta() impl */
DPNP_FN_RNG_BETA_EXT, /**< Used in numpy.random.beta() impl, requires extra
parameters */
DPNP_FN_RNG_BINOMIAL, /**< Used in numpy.random.binomial() impl */
DPNP_FN_RNG_BINOMIAL_EXT, /**< Used in numpy.random.binomial() impl,
requires extra parameters */
DPNP_FN_RNG_CHISQUARE, /**< Used in numpy.random.chisquare() impl */
Expand Down
50 changes: 0 additions & 50 deletions dpnp/backend/kernels/dpnp_krnl_mathematical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,23 +988,6 @@ void (*dpnp_remainder_default_c)(void *,
const size_t *) =
dpnp_remainder_c<_DataType_output, _DataType_input1, _DataType_input2>;

template <typename _DataType_output,
typename _DataType_input1,
typename _DataType_input2>
DPCTLSyclEventRef (*dpnp_remainder_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_remainder_c<_DataType_output, _DataType_input1, _DataType_input2>;

template <typename _KernelNameSpecialization1,
typename _KernelNameSpecialization2,
typename _KernelNameSpecialization3>
Expand Down Expand Up @@ -1385,39 +1368,6 @@ void func_map_init_mathematical(func_map_t &fmap)
fmap[DPNPFuncName::DPNP_FN_REMAINDER][eft_DBL][eft_DBL] = {
eft_DBL, (void *)dpnp_remainder_default_c<double, double, double>};

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

fmap[DPNPFuncName::DPNP_FN_TRAPZ][eft_INT][eft_INT] = {
eft_DBL, (void *)dpnp_trapz_default_c<int32_t, int32_t, double>};
fmap[DPNPFuncName::DPNP_FN_TRAPZ][eft_INT][eft_LNG] = {
Expand Down
5 changes: 0 additions & 5 deletions dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_QR_EXT
DPNP_FN_RADIANS
DPNP_FN_RADIANS_EXT
DPNP_FN_REMAINDER
DPNP_FN_REMAINDER_EXT
DPNP_FN_RECIP
DPNP_FN_RECIP_EXT
DPNP_FN_REPEAT
Expand Down Expand Up @@ -442,9 +440,6 @@ cpdef dpnp_descriptor dpnp_minimum(dpnp_descriptor x1_obj, dpnp_descriptor x2_ob
cpdef dpnp_descriptor dpnp_negative(dpnp_descriptor array1)
cpdef dpnp_descriptor dpnp_power(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj, object dtype=*,
dpnp_descriptor out=*, object where=*)
cpdef dpnp_descriptor dpnp_remainder(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj, object dtype=*,
dpnp_descriptor out=*, object where=*)


"""
Array manipulation routines
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 @@ -62,7 +62,6 @@ __all__ += [
"dpnp_negative",
"dpnp_power",
"dpnp_prod",
"dpnp_remainder",
"dpnp_sign",
"dpnp_sum",
"dpnp_trapz",
Expand Down Expand Up @@ -546,14 +545,6 @@ cpdef utils.dpnp_descriptor dpnp_prod(utils.dpnp_descriptor x1,
return result


cpdef utils.dpnp_descriptor dpnp_remainder(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_REMAINDER_EXT, x1_obj, x2_obj, dtype, out, where)


cpdef utils.dpnp_descriptor dpnp_sign(utils.dpnp_descriptor x1):
return call_fptr_1in_1out_strides(DPNP_FN_SIGN_EXT, x1)

Expand Down
47 changes: 45 additions & 2 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"dpnp_logical_xor",
"dpnp_multiply",
"dpnp_not_equal",
"dpnp_remainder",
"dpnp_right_shift",
"dpnp_sin",
"dpnp_sqrt",
Expand All @@ -86,7 +87,7 @@ def check_nd_call_func(
**kwargs,
):
"""
Checks arguments and calls function with a single input array.
Checks arguments and calls a function.

Chooses a common internal elementwise function to call in DPNP based on input arguments
or to fallback on NumPy call if any passed argument is not currently supported.
Expand Down Expand Up @@ -127,7 +128,6 @@ def check_nd_call_func(
order
)
)

return dpnp_func(*x_args, out=out, order=order)
return call_origin(
origin_func,
Expand Down Expand Up @@ -1174,6 +1174,49 @@ def dpnp_not_equal(x1, x2, out=None, order="K"):
return dpnp_array._create_from_usm_ndarray(res_usm)


_remainder_docstring_ = """
remainder(x1, x2, out=None, order='K')
Calculates the remainder of division for each element `x1_i` of the input array
`x1` with the respective element `x2_i` of the input array `x2`.
This function is equivalent to the Python modulus operator.
Args:
x1 (dpnp.ndarray):
First input array, expected to have a real-valued data type.
x2 (dpnp.ndarray):
Second input array, also expected to have a real-valued data type.
out ({None, usm_ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
dpnp.ndarray:
an array containing the element-wise remainders. The data type of
the returned array is determined by the Type Promotion Rules.
"""


remainder_func = BinaryElementwiseFunc(
"remainder",
ti._remainder_result_type,
ti._remainder,
_remainder_docstring_,
)


def dpnp_remainder(x1, x2, out=None, order="K"):
# dpctl.tensor only works with usm_ndarray or scalar
x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1)
x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

res_usm = remainder_func(
x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order
)
return dpnp_array._create_from_usm_ndarray(res_usm)


_right_shift_docstring_ = """
right_shift(x1, x2, out=None, order='K')

Expand Down
Loading