Skip to content

Commit 749fd3f

Browse files
authored
Implement call of arange() function from dpctl.tensor (#1202)
* Implement call of arange() function from dpctl.tensor * Add more tests for arange() call * Get rid of temporary skipped tests * Remove pinning on dpctl version from tests run * Remove arange() from cython path
1 parent a731718 commit 749fd3f

File tree

10 files changed

+146
-95
lines changed

10 files changed

+146
-95
lines changed

.github/workflows/conda-package.yml

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

175174
continue-on-error: ${{ matrix.experimental }}
@@ -239,7 +238,7 @@ jobs:
239238
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
240239
241240
- name: Install dpnp
242-
run: conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} dpctl=${{ matrix.dpctl }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
241+
run: conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
243242
env:
244243
TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}'
245244

@@ -270,7 +269,6 @@ jobs:
270269
strategy:
271270
matrix:
272271
python: ['3.8', '3.9']
273-
dpctl: ['0.13.0']
274272
experimental: [false]
275273

276274
continue-on-error: ${{ matrix.experimental }}
@@ -344,7 +342,7 @@ jobs:
344342
echo PACKAGE_VERSION: %PACKAGE_VERSION%
345343
(echo PACKAGE_VERSION=%PACKAGE_VERSION%) >> %GITHUB_ENV%
346344
347-
conda install ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% dpctl=${{ matrix.dpctl }} python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} --only-deps --dry-run > lockfile
345+
conda install ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% python=${{ matrix.python }} ${{ env.TEST_CHANNELS }} --only-deps --dry-run > lockfile
348346
env:
349347
TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}'
350348

@@ -369,7 +367,7 @@ jobs:
369367
- name: Install dpnp
370368
run: |
371369
@echo on
372-
conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} dpctl=${{ matrix.dpctl }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
370+
conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} pytest python=${{ matrix.python }} ${{ env.TEST_CHANNELS }}
373371
env:
374372
TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}'
375373

dpnp/backend/include/dpnp_iface_fptr.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//*****************************************************************************
2-
// Copyright (c) 2016-2020, Intel Corporation
2+
// Copyright (c) 2016-2022, Intel Corporation
33
// All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
@@ -69,7 +69,6 @@ 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 */
7372
DPNP_FN_ARCCOS, /**< Used in numpy.arccos() impl */
7473
DPNP_FN_ARCCOS_EXT, /**< Used in numpy.arccos() impl, requires extra parameters */
7574
DPNP_FN_ARCCOSH, /**< Used in numpy.arccosh() impl */

dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//*****************************************************************************
2-
// Copyright (c) 2016-2020, Intel Corporation
2+
// Copyright (c) 2016-2022, Intel Corporation
33
// All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
@@ -90,18 +90,41 @@ 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);
9394
}
9495

9596
template <typename _DataType>
9697
void (*dpnp_arange_default_c)(size_t, size_t, void*, size_t) = dpnp_arange_c<_DataType>;
9798

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>;
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);
105128

106129
template <typename _DataType>
107130
DPCTLSyclEventRef dpnp_diag_c(DPCTLSyclQueueRef q_ref,
@@ -1287,11 +1310,6 @@ void func_map_init_arraycreation(func_map_t& fmap)
12871310
fmap[DPNPFuncName::DPNP_FN_ARANGE][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_arange_default_c<float>};
12881311
fmap[DPNPFuncName::DPNP_FN_ARANGE][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_arange_default_c<double>};
12891312

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-
12951313
fmap[DPNPFuncName::DPNP_FN_DIAG][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_diag_default_c<int32_t>};
12961314
fmap[DPNPFuncName::DPNP_FN_DIAG][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_diag_default_c<int64_t>};
12971315
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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ 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
4948
DPNP_FN_ARCCOS
5049
DPNP_FN_ARCCOS_EXT
5150
DPNP_FN_ARCCOSH
@@ -519,7 +518,6 @@ cpdef dpnp_descriptor dpnp_matmul(dpnp_descriptor in_array1, dpnp_descriptor in_
519518
"""
520519
Array creation routines
521520
"""
522-
cpdef dpnp_descriptor dpnp_arange(start, stop, step, dtype)
523521
cpdef dpnp_descriptor dpnp_init_val(shape, dtype, value)
524522
cpdef dpnp_descriptor dpnp_full(result_shape, value_in, result_dtype) # same as dpnp_init_val
525523
cpdef dpnp_descriptor dpnp_copy(dpnp_descriptor x1)

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 1 addition & 38 deletions
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-2020, Intel Corporation
4+
# Copyright (c) 2016-2022, Intel Corporation
55
# All rights reserved.
66
#
77
# Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,6 @@ import numpy
5050

5151

5252
__all__ = [
53-
"dpnp_arange",
5453
"dpnp_astype",
5554
"dpnp_flatten",
5655
"dpnp_init_val",
@@ -74,9 +73,6 @@ include "dpnp_algo_statistics.pyx"
7473
include "dpnp_algo_trigonometric.pyx"
7574

7675

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)
8076
ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_astype_t)(c_dpctl.DPCTLSyclQueueRef,
8177
const void *, void * , const size_t,
8278
const c_dpctl.DPCTLEventVectorRef)
@@ -92,39 +88,6 @@ ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_initval_t)(c_dpctl.DPCTLSyclQueueR
9288
const c_dpctl.DPCTLEventVectorRef)
9389

9490

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-
12891
cpdef utils.dpnp_descriptor dpnp_astype(utils.dpnp_descriptor x1, dtype):
12992
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
13093
cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(dtype)

dpnp/dpnp_container.py

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

3636

37+
import dpctl.utils as dpu
3738
import dpctl.tensor as dpt
3839

3940
from dpnp.dpnp_array import dpnp_array
4041
import dpnp
4142

4243

4344
__all__ = [
45+
"arange",
4446
"asarray",
4547
"empty",
4648
]
4749

4850

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+
4974
def asarray(x1,
5075
dtype=None,
5176
copy=False,

dpnp/dpnp_iface_arraycreation.py

Lines changed: 22 additions & 34 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-2020, Intel Corporation
5+
# Copyright (c) 2016-2022, Intel Corporation
66
# All rights reserved.
77
#
88
# Redistribution and use in source and binary forms, with or without
@@ -90,7 +90,16 @@
9090
]
9191

9292

93-
def arange(start, stop=None, step=1, dtype=None):
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):
94103
"""
95104
Returns an array with evenly spaced values within a given interval.
96105
@@ -99,12 +108,11 @@ def arange(start, stop=None, step=1, dtype=None):
99108
Returns
100109
-------
101110
arange : :obj:`dpnp.ndarray`
102-
The 1-D array of range values.
111+
The 1-D array containing evenly spaced values.
103112
104113
Limitations
105114
-----------
106-
Parameter ``start`` is supported as integer only.
107-
Parameters ``stop`` and ``step`` are supported as either integer or ``None``.
115+
Parameter ``like`` is supported only with default value ``None``.
108116
Otherwise the function will be executed sequentially on CPU.
109117
110118
See Also
@@ -113,7 +121,6 @@ def arange(start, stop=None, step=1, dtype=None):
113121
114122
Examples
115123
--------
116-
117124
>>> import dpnp as np
118125
>>> [i for i in np.arange(3)]
119126
[0, 1, 2]
@@ -123,36 +130,17 @@ def arange(start, stop=None, step=1, dtype=None):
123130
[3, 5]
124131
125132
"""
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
152133

153-
return dpnp_arange(start, stop, step, dtype).get_pyobj()
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)
154142

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

157145

158146
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-
tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_arange_no_dtype_int
100+
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)