Skip to content

Commit 3dd3940

Browse files
committed
Revert "Implement call of arange() function from dpctl.tensor (#1202)"
This reverts commit 749fd3f.
1 parent 895e766 commit 3dd3940

File tree

10 files changed

+95
-146
lines changed

10 files changed

+95
-146
lines changed

.github/workflows/conda-package.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ jobs:
169169
strategy:
170170
matrix:
171171
python: ['3.8', '3.9']
172+
dpctl: ['0.13.0']
172173
experimental: [false]
173174

174175
continue-on-error: ${{ matrix.experimental }}
@@ -238,7 +239,7 @@ jobs:
238239
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
239240
240241
- name: Install dpnp
241-
run: conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
242+
run: conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} dpctl=${{ matrix.dpctl }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
242243
env:
243244
TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}'
244245

@@ -269,6 +270,7 @@ jobs:
269270
strategy:
270271
matrix:
271272
python: ['3.8', '3.9']
273+
dpctl: ['0.13.0']
272274
experimental: [false]
273275

274276
continue-on-error: ${{ matrix.experimental }}
@@ -342,7 +344,7 @@ jobs:
342344
echo PACKAGE_VERSION: %PACKAGE_VERSION%
343345
(echo PACKAGE_VERSION=%PACKAGE_VERSION%) >> %GITHUB_ENV%
344346
345-
conda install ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} --only-deps --dry-run > lockfile
347+
conda install ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% dpctl=${{ matrix.dpctl }} python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} --only-deps --dry-run > lockfile
346348
env:
347349
TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}'
348350

@@ -367,7 +369,7 @@ jobs:
367369
- name: Install dpnp
368370
run: |
369371
@echo on
370-
conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
372+
conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} dpctl=${{ matrix.dpctl }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
371373
env:
372374
TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}'
373375

dpnp/backend/include/dpnp_iface_fptr.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//*****************************************************************************
2-
// Copyright (c) 2016-2022, Intel Corporation
2+
// Copyright (c) 2016-2020, Intel Corporation
33
// All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
@@ -69,6 +69,7 @@ enum class DPNPFuncName : size_t
6969
DPNP_FN_ANY, /**< Used in numpy.any() impl */
7070
DPNP_FN_ANY_EXT, /**< Used in numpy.any() impl, requires extra parameters */
7171
DPNP_FN_ARANGE, /**< Used in numpy.arange() impl */
72+
DPNP_FN_ARANGE_EXT, /**< Used in numpy.arange() impl, requires extra parameters */
7273
DPNP_FN_ARCCOS, /**< Used in numpy.arccos() impl */
7374
DPNP_FN_ARCCOS_EXT, /**< Used in numpy.arccos() impl, requires extra parameters */
7475
DPNP_FN_ARCCOSH, /**< Used in numpy.arccosh() impl */

dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//*****************************************************************************
2-
// Copyright (c) 2016-2022, Intel Corporation
2+
// Copyright (c) 2016-2020, Intel Corporation
33
// All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
@@ -90,41 +90,18 @@ void dpnp_arange_c(size_t start, size_t step, void* result1, size_t size)
9090
size,
9191
dep_event_vec_ref);
9292
DPCTLEvent_WaitAndThrow(event_ref);
93-
DPCTLEvent_Delete(event_ref);
9493
}
9594

9695
template <typename _DataType>
9796
void (*dpnp_arange_default_c)(size_t, size_t, void*, size_t) = dpnp_arange_c<_DataType>;
9897

99-
// Explicit instantiation of the function, since dpnp_arange_c() is used by other template functions,
100-
// but implicit instantiation is not applied anymore.
101-
template DPCTLSyclEventRef dpnp_arange_c<int32_t>(DPCTLSyclQueueRef,
102-
size_t,
103-
size_t,
104-
void*,
105-
size_t,
106-
const DPCTLEventVectorRef);
107-
108-
template DPCTLSyclEventRef dpnp_arange_c<int64_t>(DPCTLSyclQueueRef,
109-
size_t,
110-
size_t,
111-
void*,
112-
size_t,
113-
const DPCTLEventVectorRef);
114-
115-
template DPCTLSyclEventRef dpnp_arange_c<float>(DPCTLSyclQueueRef,
116-
size_t,
117-
size_t,
118-
void*,
119-
size_t,
120-
const DPCTLEventVectorRef);
121-
122-
template DPCTLSyclEventRef dpnp_arange_c<double>(DPCTLSyclQueueRef,
123-
size_t,
124-
size_t,
125-
void*,
126-
size_t,
127-
const DPCTLEventVectorRef);
98+
template <typename _DataType>
99+
DPCTLSyclEventRef (*dpnp_arange_ext_c)(DPCTLSyclQueueRef,
100+
size_t,
101+
size_t,
102+
void*,
103+
size_t,
104+
const DPCTLEventVectorRef) = dpnp_arange_c<_DataType>;
128105

129106
template <typename _DataType>
130107
DPCTLSyclEventRef dpnp_diag_c(DPCTLSyclQueueRef q_ref,
@@ -1310,6 +1287,11 @@ void func_map_init_arraycreation(func_map_t& fmap)
13101287
fmap[DPNPFuncName::DPNP_FN_ARANGE][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_arange_default_c<float>};
13111288
fmap[DPNPFuncName::DPNP_FN_ARANGE][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_arange_default_c<double>};
13121289

1290+
fmap[DPNPFuncName::DPNP_FN_ARANGE_EXT][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_arange_ext_c<int32_t>};
1291+
fmap[DPNPFuncName::DPNP_FN_ARANGE_EXT][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_arange_ext_c<int64_t>};
1292+
fmap[DPNPFuncName::DPNP_FN_ARANGE_EXT][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_arange_ext_c<float>};
1293+
fmap[DPNPFuncName::DPNP_FN_ARANGE_EXT][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_arange_ext_c<double>};
1294+
13131295
fmap[DPNPFuncName::DPNP_FN_DIAG][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_diag_default_c<int32_t>};
13141296
fmap[DPNPFuncName::DPNP_FN_DIAG][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_diag_default_c<int64_t>};
13151297
fmap[DPNPFuncName::DPNP_FN_DIAG][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_diag_default_c<float>};

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
4545
DPNP_FN_ANY
4646
DPNP_FN_ANY_EXT
4747
DPNP_FN_ARANGE
48+
DPNP_FN_ARANGE_EXT
4849
DPNP_FN_ARCCOS
4950
DPNP_FN_ARCCOS_EXT
5051
DPNP_FN_ARCCOSH
@@ -518,6 +519,7 @@ cpdef dpnp_descriptor dpnp_matmul(dpnp_descriptor in_array1, dpnp_descriptor in_
518519
"""
519520
Array creation routines
520521
"""
522+
cpdef dpnp_descriptor dpnp_arange(start, stop, step, dtype)
521523
cpdef dpnp_descriptor dpnp_init_val(shape, dtype, value)
522524
cpdef dpnp_descriptor dpnp_full(result_shape, value_in, result_dtype) # same as dpnp_init_val
523525
cpdef dpnp_descriptor dpnp_copy(dpnp_descriptor x1)

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# cython: language_level=3
22
# -*- coding: utf-8 -*-
33
# *****************************************************************************
4-
# Copyright (c) 2016-2022, Intel Corporation
4+
# Copyright (c) 2016-2020, Intel Corporation
55
# All rights reserved.
66
#
77
# Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,7 @@ import numpy
5050

5151

5252
__all__ = [
53+
"dpnp_arange",
5354
"dpnp_astype",
5455
"dpnp_flatten",
5556
"dpnp_init_val",
@@ -73,6 +74,9 @@ include "dpnp_algo_statistics.pyx"
7374
include "dpnp_algo_trigonometric.pyx"
7475

7576

77+
ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_arange_t)(c_dpctl.DPCTLSyclQueueRef,
78+
size_t, size_t, void *, size_t,
79+
const c_dpctl.DPCTLEventVectorRef)
7680
ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_astype_t)(c_dpctl.DPCTLSyclQueueRef,
7781
const void *, void * , const size_t,
7882
const c_dpctl.DPCTLEventVectorRef)
@@ -88,6 +92,39 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_initval_t)(c_dpctl.DPCTLSyclQueueR
8892
const c_dpctl.DPCTLEventVectorRef)
8993

9094

95+
cpdef utils.dpnp_descriptor dpnp_arange(start, stop, step, dtype):
96+
obj_len = int(numpy.ceil((stop - start) / step))
97+
if obj_len < 0:
98+
raise ValueError(f"DPNP dpnp_arange(): Negative array size (start={start},stop={stop},step={step})")
99+
100+
cdef tuple obj_shape = utils._object_to_tuple(obj_len)
101+
102+
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype)
103+
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_ARANGE_EXT, param1_type, param1_type)
104+
105+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(obj_shape, kernel_data.return_type, None)
106+
107+
# for i in range(result.size):
108+
# result[i] = start + i
109+
110+
result_sycl_queue = result.get_array().sycl_queue
111+
112+
cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
113+
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
114+
115+
cdef fptr_dpnp_arange_t func = <fptr_dpnp_arange_t > kernel_data.ptr
116+
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
117+
start,
118+
step,
119+
result.get_data(),
120+
result.size,
121+
NULL) # dep_events_ref)
122+
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
123+
c_dpctl.DPCTLEvent_Delete(event_ref)
124+
125+
return result
126+
127+
91128
cpdef utils.dpnp_descriptor dpnp_astype(utils.dpnp_descriptor x1, dtype):
92129
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
93130
cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(dtype)

dpnp/dpnp_container.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,18 @@
3434
"""
3535

3636

37-
import dpctl.utils as dpu
3837
import dpctl.tensor as dpt
3938

4039
from dpnp.dpnp_array import dpnp_array
4140
import dpnp
4241

4342

4443
__all__ = [
45-
"arange",
4644
"asarray",
4745
"empty",
4846
]
4947

5048

51-
def arange(start,
52-
/,
53-
stop=None,
54-
step=1,
55-
*,
56-
dtype=None,
57-
device=None,
58-
usm_type="device",
59-
sycl_queue=None):
60-
"""Validate input parameters before passing them into `dpctl.tensor` module"""
61-
dpu.validate_usm_type(usm_type, allow_none=False)
62-
sycl_queue_normalized = dpnp.get_normalized_queue_device(sycl_queue=sycl_queue, device=device)
63-
64-
array_obj = dpt.arange(start,
65-
stop=stop,
66-
step=step,
67-
dtype=dtype,
68-
usm_type=usm_type,
69-
sycl_queue=sycl_queue_normalized)
70-
71-
return dpnp_array(array_obj.shape, buffer=array_obj)
72-
73-
7449
def asarray(x1,
7550
dtype=None,
7651
copy=False,

dpnp/dpnp_iface_arraycreation.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# distutils: language = c++
33
# -*- coding: utf-8 -*-
44
# *****************************************************************************
5-
# Copyright (c) 2016-2022, Intel Corporation
5+
# Copyright (c) 2016-2020, Intel Corporation
66
# All rights reserved.
77
#
88
# Redistribution and use in source and binary forms, with or without
@@ -90,16 +90,7 @@
9090
]
9191

9292

93-
def arange(start,
94-
/,
95-
stop=None,
96-
step=1,
97-
*,
98-
dtype=None,
99-
like=None,
100-
device=None,
101-
usm_type="device",
102-
sycl_queue=None):
93+
def arange(start, stop=None, step=1, dtype=None):
10394
"""
10495
Returns an array with evenly spaced values within a given interval.
10596
@@ -108,11 +99,12 @@ def arange(start,
10899
Returns
109100
-------
110101
arange : :obj:`dpnp.ndarray`
111-
The 1-D array containing evenly spaced values.
102+
The 1-D array of range values.
112103
113104
Limitations
114105
-----------
115-
Parameter ``like`` is supported only with default value ``None``.
106+
Parameter ``start`` is supported as integer only.
107+
Parameters ``stop`` and ``step`` are supported as either integer or ``None``.
116108
Otherwise the function will be executed sequentially on CPU.
117109
118110
See Also
@@ -121,6 +113,7 @@ def arange(start,
121113
122114
Examples
123115
--------
116+
124117
>>> import dpnp as np
125118
>>> [i for i in np.arange(3)]
126119
[0, 1, 2]
@@ -130,17 +123,36 @@ def arange(start,
130123
[3, 5]
131124
132125
"""
126+
if not use_origin_backend():
127+
if not isinstance(start, int):
128+
pass
129+
elif (stop is not None) and (not isinstance(stop, int)):
130+
pass
131+
elif (step is not None) and (not isinstance(step, int)):
132+
pass
133+
# TODO: modify native implementation to accept negative values
134+
elif (step is not None) and (step < 0):
135+
pass
136+
elif (start is not None) and (start < 0):
137+
pass
138+
elif (start is not None) and (stop is not None) and (start > stop):
139+
pass
140+
elif (dtype is not None) and (dtype not in [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64]):
141+
pass
142+
else:
143+
if dtype is None:
144+
dtype = numpy.int64
145+
146+
if stop is None:
147+
stop = start
148+
start = 0
149+
150+
if step is None:
151+
step = 1
133152

134-
if like is None:
135-
return dpnp_container.arange(start,
136-
stop=stop,
137-
step=step,
138-
dtype=dtype,
139-
device=device,
140-
usm_type=usm_type,
141-
sycl_queue=sycl_queue)
153+
return dpnp_arange(start, stop, step, dtype).get_pyobj()
142154

143-
return call_origin(numpy.arange, start, stop=stop, step=step, dtype=dtype, like=like)
155+
return call_origin(numpy.arange, start, stop=stop, step=step, dtype=dtype)
144156

145157

146158
def array(x1,

tests/skipped_tests_gpu.tbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ tests/test_indexing.py::test_nonzero[[[0, 1, 2], [3, 0, 5], [6, 7, 0]]]
9797
tests/test_indexing.py::test_nonzero[[[0, 1, 0, 3, 0], [5, 0, 7, 0, 9]]]
9898
tests/test_indexing.py::test_nonzero[[[[1, 2], [0, 4]], [[0, 2], [0, 1]], [[0, 0], [3, 1]]]]
9999
tests/test_indexing.py::test_nonzero[[[[[1, 2, 3], [3, 4, 5]], [[1, 2, 3], [2, 1, 0]]], [[[1, 3, 5], [3, 1, 0]], [[0, 1, 2], [1, 3, 4]]]]]
100-
100+
tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_arange_no_dtype_int
101101
tests/third_party/cupy/indexing_tests/test_indexing.py::TestIndexing::test_take_no_axis
102102
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_3_{n_vals=1, shape=(7,)}::test_place
103103
tests/third_party/cupy/indexing_tests/test_insert.py::TestPlace_param_4_{n_vals=1, shape=(2, 3)}::test_place

0 commit comments

Comments
 (0)