Skip to content

Commit

Permalink
Merge pull request #1614 from IntelPython/reuse_dpctl_repeat
Browse files Browse the repository at this point in the history
Leverage dpctl.tensor.repeat() implementation
  • Loading branch information
npolina4 committed Nov 16, 2023
2 parents c31557c + b81bfb9 commit 96021f0
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 242 deletions.
4 changes: 0 additions & 4 deletions dpnp/backend/include/dpnp_iface_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ enum class DPNPFuncName : size_t
DPNP_FN_FILL_DIAGONAL_EXT, /**< Used in numpy.fill_diagonal() impl, requires
extra parameters */
DPNP_FN_FLATTEN, /**< Used in numpy.flatten() impl */
DPNP_FN_FLATTEN_EXT, /**< Used in numpy.flatten() impl, requires extra
parameters */
DPNP_FN_FLOOR, /**< Used in numpy.floor() impl */
DPNP_FN_FLOOR_DIVIDE, /**< Used in numpy.floor_divide() impl */
DPNP_FN_FLOOR_DIVIDE_EXT, /**< Used in numpy.floor_divide() impl, requires
Expand Down Expand Up @@ -259,8 +257,6 @@ enum class DPNPFuncName : size_t
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
Expand Down
13 changes: 0 additions & 13 deletions dpnp/backend/kernels/dpnp_krnl_elemwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,19 +940,6 @@ static void func_map_init_elemwise_1arg_1type(func_map_t &fmap)
fmap[DPNPFuncName::DPNP_FN_FLATTEN][eft_C128][eft_C128] = {
eft_C128, (void *)dpnp_copy_c_default<std::complex<double>>};

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

fmap[DPNPFuncName::DPNP_FN_NEGATIVE][eft_INT][eft_INT] = {
eft_INT, (void *)dpnp_negative_c_default<int32_t>};
fmap[DPNPFuncName::DPNP_FN_NEGATIVE][eft_LNG][eft_LNG] = {
Expand Down
18 changes: 0 additions & 18 deletions dpnp/backend/kernels/dpnp_krnl_manipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ void (*dpnp_repeat_default_c)(const void *,
const size_t,
const size_t) = dpnp_repeat_c<_DataType>;

template <typename _DataType>
DPCTLSyclEventRef (*dpnp_repeat_ext_c)(DPCTLSyclQueueRef,
const void *,
void *,
const size_t,
const size_t,
const DPCTLEventVectorRef) =
dpnp_repeat_c<_DataType>;

template <typename _KernelNameSpecialization>
class dpnp_elemwise_transpose_c_kernel;

Expand Down Expand Up @@ -232,15 +223,6 @@ void func_map_init_manipulation(func_map_t &fmap)
fmap[DPNPFuncName::DPNP_FN_REPEAT][eft_DBL][eft_DBL] = {
eft_DBL, (void *)dpnp_repeat_default_c<double>};

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

fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_INT][eft_INT] = {
eft_INT, (void *)dpnp_elemwise_transpose_default_c<int32_t>};
fmap[DPNPFuncName::DPNP_FN_TRANSPOSE][eft_LNG][eft_LNG] = {
Expand Down
1 change: 0 additions & 1 deletion dpnp/dpnp_algo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

set(dpnp_algo_pyx_deps
${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_linearalgebra.pxi
${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_manipulation.pxi
${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_statistics.pxi
${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_trigonometric.pxi
${CMAKE_CURRENT_SOURCE_DIR}/dpnp_algo_sorting.pxi
Expand Down
10 changes: 0 additions & 10 deletions dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_FFT_RFFT_EXT
DPNP_FN_FILL_DIAGONAL
DPNP_FN_FILL_DIAGONAL_EXT
DPNP_FN_FLATTEN
DPNP_FN_FLATTEN_EXT
DPNP_FN_FMOD
DPNP_FN_FMOD_EXT
DPNP_FN_FULL
Expand Down Expand Up @@ -130,8 +128,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_RADIANS_EXT
DPNP_FN_RECIP
DPNP_FN_RECIP_EXT
DPNP_FN_REPEAT
DPNP_FN_REPEAT_EXT
DPNP_FN_RNG_BETA
DPNP_FN_RNG_BETA_EXT
DPNP_FN_RNG_BINOMIAL
Expand Down Expand Up @@ -323,8 +319,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*dpnp_reduction_c_t)(c_dpctl.DPCTLSyclQueueRe
const long*,
const c_dpctl.DPCTLEventVectorRef)

cpdef dpnp_descriptor dpnp_flatten(dpnp_descriptor x1)


"""
Internal functions
Expand Down Expand Up @@ -359,10 +353,6 @@ cpdef dpnp_descriptor dpnp_fmax(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj,
dpnp_descriptor out=*, object where=*)
cpdef dpnp_descriptor dpnp_fmin(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj, object dtype=*,
dpnp_descriptor out=*, object where=*)
"""
Array manipulation routines
"""
cpdef dpnp_descriptor dpnp_repeat(dpnp_descriptor array1, repeats, axes=*)


"""
Expand Down
49 changes: 0 additions & 49 deletions dpnp/dpnp_algo/dpnp_algo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import operator
import numpy

__all__ = [
"dpnp_flatten",
"dpnp_queue_initialize",
]

Expand All @@ -63,7 +62,6 @@ include "dpnp_algo_arraycreation.pxi"
include "dpnp_algo_indexing.pxi"
include "dpnp_algo_linearalgebra.pxi"
include "dpnp_algo_logic.pxi"
include "dpnp_algo_manipulation.pxi"
include "dpnp_algo_mathematical.pxi"
include "dpnp_algo_searching.pxi"
include "dpnp_algo_sorting.pxi"
Expand All @@ -81,53 +79,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_flatten_t)(c_dpctl.DPCTLSyclQueueR
const c_dpctl.DPCTLEventVectorRef)


cpdef utils.dpnp_descriptor dpnp_flatten(utils.dpnp_descriptor x1):
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)

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

cdef shape_type_c x1_shape = x1.shape
cdef shape_type_c x1_strides = utils.strides_to_vector(x1.strides, x1_shape)

x1_obj = x1.get_array()

# create result array with type given by FPTR data
cdef shape_type_c result_shape = (x1.size,)
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape,
kernel_data.return_type,
None,
device=x1_obj.sycl_device,
usm_type=x1_obj.usm_type,
sycl_queue=x1_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 shape_type_c result_strides = utils.strides_to_vector(result.strides, result_shape)

cdef fptr_dpnp_flatten_t func = <fptr_dpnp_flatten_t > kernel_data.ptr
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
result.get_data(),
result.size,
result.ndim,
result_shape.data(),
result_strides.data(),
x1.get_data(),
x1.size,
x1.ndim,
x1_shape.data(),
x1_strides.data(),
NULL,
NULL) # dep_events_ref

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

return result


cpdef dpnp_queue_initialize():
"""
Initialize SYCL queue which will be used for any library operations.
Expand Down
80 changes: 0 additions & 80 deletions dpnp/dpnp_algo/dpnp_algo_manipulation.pxi

This file was deleted.

20 changes: 18 additions & 2 deletions dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,15 @@ def put(self, indices, vals, /, *, axis=None, mode="wrap"):

return dpnp.put(self, indices, vals, axis=axis, mode=mode)

# 'ravel',
def ravel(self, order="C"):
"""
Return a contiguous flattened array.
For full documentation refer to :obj:`dpnp.ravel`.
"""

return dpnp.ravel(self, order=order)

@property
def real(self):
Expand Down Expand Up @@ -1087,7 +1095,15 @@ def real(self, value):
"""
dpnp.copyto(self._array_obj.real, value)

# 'repeat',
def repeat(self, repeats, axis=None):
"""
Repeat elements of an array.
For full documentation refer to :obj:`dpnp.repeat`.
"""

return dpnp.repeat(self, repeats, axis=axis)

def reshape(self, *sh, **kwargs):
"""
Expand Down
Loading

0 comments on commit 96021f0

Please sign in to comment.