Skip to content

Commit 8c89ab0

Browse files
authored
Merge pull request #1240 from antonwolfy/gold/2021
Merge master into gold/2021
2 parents 32c234e + fa13036 commit 8c89ab0

File tree

8 files changed

+111
-55
lines changed

8 files changed

+111
-55
lines changed

.github/workflows/build-sphinx.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
# https://github.com/marketplace/actions/setup-miniconda
6060
- name: Setup miniconda
61-
uses: conda-incubator/setup-miniconda@v2.1.1
61+
uses: conda-incubator/setup-miniconda@v2.2.0
6262
with:
6363
auto-update-conda: true
6464
python-version: ${{ env.python-ver }}
@@ -106,7 +106,7 @@ jobs:
106106
if: |
107107
!github.event.pull_request.head.repo.fork &&
108108
(github.ref == 'refs/heads/master' || (startsWith(github.ref, 'refs/heads/release') == true) || github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
109-
uses: peaceiris/actions-gh-pages@v3.8.0
109+
uses: peaceiris/actions-gh-pages@v3.9.0
110110
with:
111111
github_token: ${{ secrets.GITHUB_TOKEN }}
112112
publish_dir: doc/_build/html/

.github/workflows/conda-package.yml

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ env:
1010
PACKAGE_NAME: dpnp
1111
MODULE_NAME: dpnp
1212
CHANNELS: '-c dppy/label/dev -c intel -c defaults --override-channels'
13+
TEST_SCOPE: >-
14+
test_arraycreation.py
15+
test_dparray.py
16+
test_fft.py
17+
test_linalg.py
18+
test_mathematical.py
19+
test_random_state.py
20+
test_special.py
21+
test_usm_type.py
1322
VER_JSON_NAME: 'version.json'
1423
VER_SCRIPT1: "import json; f = open('version.json', 'r'); j = json.load(f); f.close(); "
1524
VER_SCRIPT2: "d = j['dpnp'][0]; print('='.join((d[s] for s in ('version', 'build'))))"
@@ -41,7 +50,7 @@ jobs:
4150
fetch-depth: 0
4251

4352
- name: Setup miniconda
44-
uses: conda-incubator/setup-miniconda@v2.1.1
53+
uses: conda-incubator/setup-miniconda@v2.2.0
4554
with:
4655
auto-update-conda: true
4756
python-version: ${{ matrix.python }}
@@ -71,7 +80,7 @@ jobs:
7180
run: conda build --no-test --python ${{ matrix.python }} ${{ env.CHANNELS }} conda-recipe
7281

7382
- name: Upload artifact
74-
uses: actions/[email protected].0
83+
uses: actions/[email protected].1
7584
with:
7685
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
7786
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.tar.bz2
@@ -102,7 +111,7 @@ jobs:
102111
fetch-depth: 0
103112

104113
- name: Setup miniconda
105-
uses: conda-incubator/setup-miniconda@v2.1.1
114+
uses: conda-incubator/setup-miniconda@v2.2.0
106115
with:
107116
auto-update-conda: true
108117
python-version: ${{ matrix.python }}
@@ -134,7 +143,7 @@ jobs:
134143
run: conda build --no-test --python ${{ matrix.python }} ${{ env.CHANNELS }} conda-recipe
135144

136145
- name: Upload artifact
137-
uses: actions/[email protected].0
146+
uses: actions/[email protected].1
138147
with:
139148
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
140149
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.tar.bz2
@@ -165,7 +174,7 @@ jobs:
165174

166175
steps:
167176
- name: Download artifact
168-
uses: actions/[email protected].0
177+
uses: actions/[email protected].1
169178
with:
170179
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
171180
path: ${{ env.pkg-path-in-channel }}
@@ -176,7 +185,7 @@ jobs:
176185
tar -xvf ${{ env.pkg-path-in-channel }}/${{ env.PACKAGE_NAME }}-*.tar.bz2 -C ${{ env.extracted-pkg-path }}
177186
178187
- name: Setup miniconda
179-
uses: conda-incubator/setup-miniconda@v2.1.1
188+
uses: conda-incubator/setup-miniconda@v2.2.0
180189
with:
181190
auto-update-conda: true
182191
python-version: ${{ matrix.python }}
@@ -235,7 +244,7 @@ jobs:
235244
# TODO: run the whole scope once the issues on CPU are resolved
236245
- name: Run tests
237246
run: |
238-
python -m pytest -q -ra --disable-warnings -vv test_arraycreation.py test_dparray.py test_fft.py test_linalg.py test_mathematical.py test_random_state.py test_special.py
247+
python -m pytest -q -ra --disable-warnings -vv ${{ env.TEST_SCOPE }}
239248
env:
240249
OCL_ICD_FILENAMES: 'libintelocl.so'
241250
working-directory: ${{ env.tests-path }}
@@ -267,7 +276,7 @@ jobs:
267276

268277
steps:
269278
- name: Download artifact
270-
uses: actions/[email protected].0
279+
uses: actions/[email protected].1
271280
with:
272281
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
273282
path: ${{ env.pkg-path-in-channel }}
@@ -287,7 +296,7 @@ jobs:
287296
dir ${{ env.extracted-pkg-path }}
288297
289298
- name: Setup miniconda
290-
uses: conda-incubator/setup-miniconda@v2.1.1
299+
uses: conda-incubator/setup-miniconda@v2.2.0
291300
with:
292301
auto-update-conda: true
293302
python-version: ${{ matrix.python }}
@@ -410,14 +419,14 @@ jobs:
410419
# TODO: run the whole scope once the issues on CPU are resolved
411420
- name: Run tests
412421
run: |
413-
python -m pytest -q -ra --disable-warnings -vv test_arraycreation.py test_dparray.py test_fft.py test_linalg.py test_mathematical.py test_random_state.py test_special.py
422+
python -m pytest -q -ra --disable-warnings -vv ${{ env.TEST_SCOPE }}
414423
working-directory: ${{ env.tests-path }}
415424

416425
upload_linux:
417426
needs: test_linux
418427

419428
if: |
420-
!github.event.pull_request.head.repo.fork &&
429+
(github.repository == 'IntelPython/dpnp') &&
421430
(github.ref == 'refs/heads/master' || (startsWith(github.ref, 'refs/heads/release') == true) || github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
422431
423432
runs-on: ubuntu-latest
@@ -432,12 +441,12 @@ jobs:
432441

433442
steps:
434443
- name: Download artifact
435-
uses: actions/[email protected].0
444+
uses: actions/[email protected].1
436445
with:
437446
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
438447

439448
- name: Setup miniconda
440-
uses: conda-incubator/setup-miniconda@v2.1.1
449+
uses: conda-incubator/setup-miniconda@v2.2.0
441450
with:
442451
auto-update-conda: true
443452
python-version: ${{ matrix.python }}
@@ -456,7 +465,7 @@ jobs:
456465
needs: test_windows
457466

458467
if: |
459-
!github.event.pull_request.head.repo.fork && !github.event.push.repository.fork &&
468+
(github.repository == 'IntelPython/dpnp') &&
460469
(github.ref == 'refs/heads/master' || (startsWith(github.ref, 'refs/heads/release') == true) || github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
461470
462471
runs-on: windows-latest
@@ -470,12 +479,12 @@ jobs:
470479
python: ['3.8', '3.9']
471480
steps:
472481
- name: Download artifact
473-
uses: actions/[email protected].0
482+
uses: actions/[email protected].1
474483
with:
475484
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
476485

477486
- name: Setup miniconda
478-
uses: conda-incubator/setup-miniconda@v2.1.1
487+
uses: conda-incubator/setup-miniconda@v2.2.0
479488
with:
480489
auto-update-conda: true
481490
python-version: ${{ matrix.python }}

dpnp/backend/kernels/dpnp_krnl_random.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -973,33 +973,43 @@ DPCTLSyclEventRef dpnp_rng_multinomial_c(DPCTLSyclQueueRef q_ref,
973973
else
974974
{
975975
DPNPC_ptr_adapter<double> p_ptr(q_ref, p_in, p_size, true);
976-
const double* p = p_ptr.get_ptr();
977-
std::vector<double> p_vec(p, p + p_size);
976+
double* p_data = p_ptr.get_ptr();
977+
978978
// size = size
979979
// `result` is a array for random numbers
980-
// `size` is a `result`'s len. `size = n * p.size()`
980+
// `size` is a `result`'s len. `size = n * p_size`
981981
// `n` is a number of random values to be generated.
982-
size_t n = size / p_vec.size();
982+
size_t n = size / p_size;
983983

984984
size_t is_cpu_queue = dpnp_queue_is_cpu_c();
985985

986986
// math library supports the distribution generation on GPU device with input parameters
987987
// which follow the condition
988988
if (is_cpu_queue || (!is_cpu_queue && (p_size >= ((size_t)ntrial * 16)) && (ntrial <= 16)))
989989
{
990-
DPNPC_ptr_adapter<std::int32_t> result_ptr(q_ref, result, size, false, true);
991-
std::int32_t* result1 = result_ptr.get_ptr();
992-
mkl_rng::multinomial<std::int32_t> distribution(ntrial, p_vec);
990+
DPNPC_ptr_adapter<_DataType> result_ptr(q_ref, result, size, true, true);
991+
_DataType* result1 = result_ptr.get_ptr();
992+
993+
#if (INTEL_MKL_VERSION < __INTEL_MKL_2023_SWITCHOVER)
994+
std::vector<double> p(p_data, p_data + p_size);
995+
#else
996+
auto p = sycl::span<double>{p_data, p_size};
997+
#endif
998+
mkl_rng::multinomial<_DataType> distribution(ntrial, p);
999+
9931000
// perform generation
9941001
event_out = mkl_rng::generate(distribution, DPNP_RNG_ENGINE, n, result1);
9951002
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event_out);
1003+
1004+
p_ptr.depends_on(event_out);
1005+
result_ptr.depends_on(event_out);
9961006
}
9971007
else
9981008
{
999-
DPNPC_ptr_adapter<std::int32_t> result_ptr(q_ref, result, size, true, true);
1000-
std::int32_t* result1 = result_ptr.get_ptr();
1009+
DPNPC_ptr_adapter<_DataType> result_ptr(q_ref, result, size, true, true);
1010+
_DataType* result1 = result_ptr.get_ptr();
10011011
int errcode = viRngMultinomial(
1002-
VSL_RNG_METHOD_MULTINOMIAL_MULTPOISSON, get_rng_stream(), n, result1, ntrial, p_size, p);
1012+
VSL_RNG_METHOD_MULTINOMIAL_MULTPOISSON, get_rng_stream(), n, result1, ntrial, p_size, p_data);
10031013
if (errcode != VSL_STATUS_OK)
10041014
{
10051015
throw std::runtime_error("DPNP RNG Error: dpnp_rng_multinomial_c() failed.");
@@ -1023,6 +1033,7 @@ void dpnp_rng_multinomial_c(
10231033
size,
10241034
dep_event_vec_ref);
10251035
DPCTLEvent_WaitAndThrow(event_ref);
1036+
DPCTLEvent_Delete(event_ref);
10261037
}
10271038

10281039
template <typename _DataType>
@@ -1065,24 +1076,32 @@ DPCTLSyclEventRef dpnp_rng_multivariate_normal_c(DPCTLSyclQueueRef q_ref,
10651076
sycl::queue q = *(reinterpret_cast<sycl::queue*>(q_ref));
10661077

10671078
DPNPC_ptr_adapter<double> mean_ptr(q_ref, mean_in, mean_size, true);
1068-
const double* mean = mean_ptr.get_ptr();
1079+
double* mean_data = mean_ptr.get_ptr();
10691080
DPNPC_ptr_adapter<double> cov_ptr(q_ref, cov_in, cov_size, true);
1070-
const double* cov = cov_ptr.get_ptr();
1081+
double* cov_data = cov_ptr.get_ptr();
10711082

1072-
_DataType* result1 = reinterpret_cast<_DataType*>(result);
1083+
_DataType* result1 = static_cast<_DataType *>(result);
10731084

1074-
std::vector<double> mean_vec(mean, mean + mean_size);
1075-
std::vector<double> cov_vec(cov, cov + cov_size);
1085+
#if (INTEL_MKL_VERSION < __INTEL_MKL_2023_SWITCHOVER)
1086+
std::vector<double> mean(mean_data, mean_data + mean_size);
1087+
std::vector<double> cov(cov_data, cov_data + cov_size);
1088+
#else
1089+
auto mean = sycl::span<double>{mean_data, mean_size};
1090+
auto cov = sycl::span<double>{cov_data, cov_size};
1091+
#endif
10761092

10771093
// `result` is a array for random numbers
10781094
// `size` is a `result`'s len.
10791095
// `size1` is a number of random values to be generated for each dimension.
10801096
size_t size1 = size / dimen;
10811097

1082-
mkl_rng::gaussian_mv<_DataType> distribution(dimen, mean_vec, cov_vec);
1098+
mkl_rng::gaussian_mv<_DataType> distribution(dimen, mean, cov);
10831099
auto event_out = mkl_rng::generate(distribution, DPNP_RNG_ENGINE, size1, result1);
10841100
event_ref = reinterpret_cast<DPCTLSyclEventRef>(&event_out);
10851101

1102+
mean_ptr.depends_on(event_out);
1103+
cov_ptr.depends_on(event_out);
1104+
10861105
return DPCTLEvent_Copy(event_ref);
10871106
}
10881107

@@ -1107,6 +1126,7 @@ void dpnp_rng_multivariate_normal_c(void* result,
11071126
size,
11081127
dep_event_vec_ref);
11091128
DPCTLEvent_WaitAndThrow(event_ref);
1129+
DPCTLEvent_Delete(event_ref);
11101130
}
11111131

11121132
template <typename _DataType>

dpnp/backend/src/dpnp_utils.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
#define __SYCL_COMPILER_2023_SWITCHOVER 20221102L
5050
#endif
5151

52+
/**
53+
* Version of Intel MKL at which transition to OneMKL release 2023.0.0 occurs.
54+
*/
55+
#ifndef __INTEL_MKL_2023_SWITCHOVER
56+
#define __INTEL_MKL_2023_SWITCHOVER 20230000
57+
#endif
58+
5259
/**
5360
* @defgroup BACKEND_UTILS Backend C++ library utilities
5461
* @{

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -532,22 +532,7 @@ cdef tuple get_common_usm_allocation(dpnp_descriptor x1, dpnp_descriptor x2):
532532
array1_obj = x1.get_array()
533533
array2_obj = x2.get_array()
534534

535-
def get_usm_type(usm_types):
536-
if not isinstance(usm_types, (list, tuple)):
537-
raise TypeError(
538-
"Expected a list or a tuple, got {}".format(type(usm_types))
539-
)
540-
if len(usm_types) == 0:
541-
return None
542-
elif len(usm_types) == 1:
543-
return usm_types[0]
544-
for usm_type1, usm_type2 in zip(usm_types, usm_types[1:]):
545-
if usm_type1 != usm_type2:
546-
return None
547-
return usm_types[0]
548-
549-
# TODO: use similar function from dpctl.utils instead of get_usm_type
550-
common_usm_type = get_usm_type((array1_obj.usm_type, array2_obj.usm_type))
535+
common_usm_type = dpctl.utils.get_coerced_usm_type((array1_obj.usm_type, array2_obj.usm_type))
551536
if common_usm_type is None:
552537
raise ValueError(
553538
"could not recognize common USM type for inputs of USM types {} and {}"

tests/skipped_tests.tbl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,12 @@ tests/test_linalg.py::test_svd[(5,3)-float64]
199199
tests/test_linalg.py::test_svd[(16,16)-float64]
200200

201201
tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[3.5-array1]
202+
203+
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray([[i, i] for i in x])]
202204
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: (dpnp.asarray([(i, i) for i in x], [("a", int), ("b", int)]).view(dpnp.recarray))]
203205
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray([(i, i) for i in x], [("a", object), ("b", dpnp.int32)])]]
204206
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray(x).astype(dpnp.int8)]
207+
205208
tests/test_sort.py::test_partition[[[1, 0], [3, 0]]-float32-1]
206209
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_and
207210
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_or

tests/skipped_tests_gpu.tbl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
tests/test_random.py::TestDistributionsMultinomial::test_extreme_value
2-
tests/test_random.py::TestDistributionsMultinomial::test_seed1
31
tests/test_random.py::TestDistributionsMultivariateNormal::test_moments
42
tests/test_random.py::TestDistributionsMultivariateNormal::test_output_shape_check
53
tests/test_random.py::TestDistributionsMultivariateNormal::test_seed
@@ -219,9 +217,7 @@ tests/test_mathematical.py::TestGradient::test_gradient_y1[array2]
219217
tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[2-array0]
220218
tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[2-array1]
221219
tests/test_mathematical.py::TestGradient::test_gradient_y1_dx[2-array2]
222-
tests/test_random.py::TestDistributionsMultinomial::test_check_sum
223-
tests/test_random.py::TestDistributionsMultinomial::test_moments
224-
tests/test_random.py::TestDistributionsMultinomial::test_seed
220+
225221
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.astype(dpnp.asarray(x), dpnp.int8)]
226222
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.astype(dpnp.asarray(x), object)]
227223
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.vstack([x, x]).T]

tests/test_usm_type.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
3+
import dpnp as dp
4+
5+
import dpctl.utils as du
6+
7+
list_of_usm_types = [
8+
"device",
9+
"shared",
10+
"host"
11+
]
12+
13+
14+
@pytest.mark.parametrize("usm_type", list_of_usm_types, ids=list_of_usm_types)
15+
def test_coerced_usm_types_sum(usm_type):
16+
x = dp.arange(10, usm_type = "device")
17+
y = dp.arange(10, usm_type = usm_type)
18+
19+
z = x + y
20+
21+
assert z.usm_type == x.usm_type
22+
assert z.usm_type == "device"
23+
assert y.usm_type == usm_type
24+
25+
26+
@pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types)
27+
@pytest.mark.parametrize("usm_type_y", list_of_usm_types, ids=list_of_usm_types)
28+
def test_coerced_usm_types_mul(usm_type_x, usm_type_y):
29+
x = dp.arange(10, usm_type = usm_type_x)
30+
y = dp.arange(10, usm_type = usm_type_y)
31+
32+
z = x * y
33+
34+
assert x.usm_type == usm_type_x
35+
assert y.usm_type == usm_type_y
36+
assert z.usm_type == du.get_coerced_usm_type([usm_type_x, usm_type_y])

0 commit comments

Comments
 (0)