Skip to content

Commit 46aa7bf

Browse files
authored
Merge 47f51e3 into e236ad9
2 parents e236ad9 + 47f51e3 commit 46aa7bf

25 files changed

+771
-40
lines changed

dpnp/dpnp_iface.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"get_normalized_queue_device",
6969
"get_result_array",
7070
"get_usm_ndarray",
71+
"is_cuda_backend",
7172
"get_usm_ndarray_or_scalar",
7273
"is_supported_array_or_scalar",
7374
"is_supported_array_type",
@@ -733,6 +734,40 @@ def get_usm_ndarray_or_scalar(a):
733734
return a if dpnp.isscalar(a) else get_usm_ndarray(a)
734735

735736

737+
def is_cuda_backend(obj=None):
738+
"""
739+
Checks that object has a CUDA backend.
740+
741+
Parameters
742+
----------
743+
obj : {Device, SyclDevice, SyclQueue, dpnp.ndarray, usm_ndarray, None},
744+
optional
745+
An input object with sycl_device property to check device backend.
746+
If `obj` is ``None``, device backend will be checked for the default
747+
queue.
748+
Default: ``None``.
749+
750+
Returns
751+
-------
752+
out : bool
753+
Return ``True`` if object has a cuda backend, otherwise``False``.
754+
755+
"""
756+
757+
if obj is None:
758+
sycl_device = dpctl.SyclQueue().sycl_device
759+
elif isinstance(obj, dpctl.SyclDevice):
760+
sycl_device = obj
761+
else:
762+
sycl_device = getattr(obj, "sycl_device", None)
763+
if (
764+
sycl_device is not None
765+
and sycl_device.backend == dpctl.backend_type.cuda
766+
):
767+
return True
768+
return False
769+
770+
736771
def is_supported_array_or_scalar(a):
737772
"""
738773
Return ``True`` if `a` is a scalar or an array of either

dpnp/dpnp_iface_indexing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def choose(x1, choices, out=None, mode="raise"):
173173
:obj:`dpnp.take_along_axis` : Preferable if choices is an array.
174174
175175
"""
176+
176177
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
177178

178179
choices_list = []
@@ -192,6 +193,8 @@ def choose(x1, choices, out=None, mode="raise"):
192193
pass
193194
elif not choices_list:
194195
pass
196+
elif dpnp.is_cuda_backend(x1):
197+
pass
195198
else:
196199
size = x1_desc.size
197200
choices_size = choices_list[0].size

dpnp/dpnp_iface_libmath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def erf(in_array1):
8181
x1_desc = dpnp.get_dpnp_descriptor(
8282
in_array1, copy_when_strides=False, copy_when_nondefault_queue=False
8383
)
84-
if x1_desc:
84+
if x1_desc and not dpnp.is_cuda_backend(in_array1):
8585
return dpnp_erf(x1_desc).get_pyobj()
8686

8787
result = create_output_descriptor_py(

dpnp/dpnp_iface_mathematical.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,8 +2691,13 @@ def modf(x1, **kwargs):
26912691
"""
26922692

26932693
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
2694-
if x1_desc and not kwargs:
2695-
return dpnp_modf(x1_desc)
2694+
if x1_desc:
2695+
if not kwargs:
2696+
pass
2697+
elif dpnp.is_cuda_backend(x1):
2698+
pass
2699+
else:
2700+
return dpnp_modf(x1_desc)
26962701

26972702
return call_origin(numpy.modf, x1, **kwargs)
26982703

dpnp/dpnp_iface_sorting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ def partition(x1, kth, axis=-1, kind="introselect", order=None):
197197
pass
198198
elif order is not None:
199199
pass
200+
elif dpnp.is_cuda_backend(x1):
201+
pass
200202
else:
201203
return dpnp_partition(x1_desc, kth, axis, kind, order).get_pyobj()
202204

dpnp/dpnp_iface_statistics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ def correlate(x1, x2, mode="valid"):
397397
pass
398398
elif mode != "valid":
399399
pass
400+
elif dpnp.is_cuda_backend(x1) or dpnp.is_cuda_backend(x2):
401+
pass
400402
else:
401403
return dpnp_correlate(x1_desc, x2_desc).get_pyobj()
402404

dpnp/random/dpnp_iface_random.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def beta(a, b, size=None):
150150
pass
151151
elif b <= 0:
152152
pass
153+
elif dpnp.is_cuda_backend():
154+
pass
153155
else:
154156
return dpnp_rng_beta(a, b, size).get_pyobj()
155157

@@ -196,6 +198,8 @@ def binomial(n, p, size=None):
196198
pass
197199
elif n < 0:
198200
pass
201+
elif dpnp.is_cuda_backend():
202+
pass
199203
else:
200204
return dpnp_rng_binomial(int(n), p, size).get_pyobj()
201205

@@ -244,6 +248,8 @@ def chisquare(df, size=None):
244248
pass
245249
elif df <= 0:
246250
pass
251+
elif dpnp.is_cuda_backend():
252+
pass
247253
else:
248254
# TODO:
249255
# float to int, safe
@@ -312,6 +318,8 @@ def exponential(scale=1.0, size=None):
312318
pass
313319
elif scale < 0:
314320
pass
321+
elif dpnp.is_cuda_backend():
322+
pass
315323
else:
316324
return dpnp_rng_exponential(scale, size).get_pyobj()
317325

@@ -348,6 +356,8 @@ def f(dfnum, dfden, size=None):
348356
pass
349357
elif dfden <= 0:
350358
pass
359+
elif dpnp.is_cuda_backend():
360+
pass
351361
else:
352362
return dpnp_rng_f(dfnum, dfden, size).get_pyobj()
353363

@@ -386,6 +396,8 @@ def gamma(shape, scale=1.0, size=None):
386396
pass
387397
elif shape < 0:
388398
pass
399+
elif dpnp.is_cuda_backend():
400+
pass
389401
else:
390402
return dpnp_rng_gamma(shape, scale, size).get_pyobj()
391403

@@ -420,6 +432,8 @@ def geometric(p, size=None):
420432
pass
421433
elif p > 1 or p <= 0:
422434
pass
435+
elif dpnp.is_cuda_backend():
436+
pass
423437
else:
424438
return dpnp_rng_geometric(p, size).get_pyobj()
425439

@@ -456,6 +470,8 @@ def gumbel(loc=0.0, scale=1.0, size=None):
456470
pass
457471
elif scale < 0:
458472
pass
473+
elif dpnp.is_cuda_backend():
474+
pass
459475
else:
460476
return dpnp_rng_gumbel(loc, scale, size).get_pyobj()
461477

@@ -504,6 +520,8 @@ def hypergeometric(ngood, nbad, nsample, size=None):
504520
pass
505521
elif nsample < 1:
506522
pass
523+
elif dpnp.is_cuda_backend():
524+
pass
507525
else:
508526
_m = int(ngood)
509527
_l = int(ngood) + int(nbad)
@@ -542,6 +560,8 @@ def laplace(loc=0.0, scale=1.0, size=None):
542560
pass
543561
elif scale < 0:
544562
pass
563+
elif dpnp.is_cuda_backend():
564+
pass
545565
else:
546566
return dpnp_rng_laplace(loc, scale, size).get_pyobj()
547567

@@ -576,6 +596,8 @@ def logistic(loc=0.0, scale=1.0, size=None):
576596
pass
577597
elif scale < 0:
578598
pass
599+
elif dpnp.is_cuda_backend():
600+
pass
579601
else:
580602
result = dpnp_rng_logistic(loc, scale, size).get_pyobj()
581603
if size is None or size == 1:
@@ -617,6 +639,8 @@ def lognormal(mean=0.0, sigma=1.0, size=None):
617639
pass
618640
elif sigma < 0:
619641
pass
642+
elif dpnp.is_cuda_backend():
643+
pass
620644
else:
621645
return dpnp_rng_lognormal(mean, sigma, size).get_pyobj()
622646

@@ -674,6 +698,8 @@ def multinomial(n, pvals, size=None):
674698
pass
675699
elif pvals_sum < 0.0:
676700
pass
701+
elif dpnp.is_cuda_backend():
702+
pass
677703
else:
678704
if size is None:
679705
shape = (d,)
@@ -725,6 +751,8 @@ def multivariate_normal(mean, cov, size=None, check_valid="warn", tol=1e-8):
725751
pass
726752
elif mean_.shape[0] != cov_.shape[0]:
727753
pass
754+
elif dpnp.is_cuda_backend():
755+
pass
728756
else:
729757
final_shape = list(shape[:])
730758
final_shape.append(mean_.shape[0])
@@ -777,6 +805,8 @@ def negative_binomial(n, p, size=None):
777805
pass
778806
elif n <= 0:
779807
pass
808+
elif dpnp.is_cuda_backend():
809+
pass
780810
else:
781811
return dpnp_rng_negative_binomial(n, p, size).get_pyobj()
782812

@@ -862,6 +892,8 @@ def noncentral_chisquare(df, nonc, size=None):
862892
pass
863893
elif nonc < 0:
864894
pass
895+
elif dpnp.is_cuda_backend():
896+
pass
865897
else:
866898
return dpnp_rng_noncentral_chisquare(df, nonc, size).get_pyobj()
867899

@@ -912,6 +944,8 @@ def pareto(a, size=None):
912944
pass
913945
elif a <= 0:
914946
pass
947+
elif dpnp.is_cuda_backend():
948+
pass
915949
else:
916950
return dpnp_rng_pareto(a, size).get_pyobj()
917951

@@ -981,6 +1015,8 @@ def poisson(lam=1.0, size=None):
9811015
pass
9821016
elif lam < 0:
9831017
pass
1018+
elif dpnp.is_cuda_backend():
1019+
pass
9841020
else:
9851021
return dpnp_rng_poisson(lam, size).get_pyobj()
9861022

@@ -1016,6 +1052,8 @@ def power(a, size=None):
10161052
pass
10171053
elif a <= 0:
10181054
pass
1055+
elif dpnp.is_cuda_backend():
1056+
pass
10191057
else:
10201058
return dpnp_rng_power(a, size).get_pyobj()
10211059

@@ -1423,6 +1461,8 @@ def rayleigh(scale=1.0, size=None):
14231461
pass
14241462
elif scale < 0:
14251463
pass
1464+
elif dpnp.is_cuda_backend():
1465+
pass
14261466
else:
14271467
return dpnp_rng_rayleigh(scale, size).get_pyobj()
14281468

@@ -1495,6 +1535,8 @@ def shuffle(x1):
14951535
if x1_desc:
14961536
if not dpnp.is_type_supported(x1_desc.dtype):
14971537
pass
1538+
elif dpnp.is_cuda_backend(x1):
1539+
pass
14981540
else:
14991541
dpnp_rng_shuffle(x1_desc).get_pyobj()
15001542
return
@@ -1545,6 +1587,8 @@ def seed(seed=None, device=None, sycl_queue=None):
15451587
pass
15461588
elif seed < 0:
15471589
pass
1590+
elif dpnp.is_cuda_backend():
1591+
pass
15481592
else:
15491593
# TODO:
15501594
# migrate to a single approach with RandomState class
@@ -1577,7 +1621,10 @@ def standard_cauchy(size=None):
15771621
"""
15781622

15791623
if not use_origin_backend(size):
1580-
return dpnp_rng_standard_cauchy(size).get_pyobj()
1624+
if dpnp.is_cuda_backend():
1625+
pass
1626+
else:
1627+
return dpnp_rng_standard_cauchy(size).get_pyobj()
15811628

15821629
return call_origin(numpy.random.standard_cauchy, size)
15831630

@@ -1602,7 +1649,10 @@ def standard_exponential(size=None):
16021649
"""
16031650

16041651
if not use_origin_backend(size):
1605-
return dpnp_rng_standard_exponential(size).get_pyobj()
1652+
if dpnp.is_cuda_backend():
1653+
pass
1654+
else:
1655+
return dpnp_rng_standard_exponential(size).get_pyobj()
16061656

16071657
return call_origin(numpy.random.standard_exponential, size)
16081658

@@ -1636,6 +1686,8 @@ def standard_gamma(shape, size=None):
16361686
pass
16371687
elif shape < 0:
16381688
pass
1689+
elif dpnp.is_cuda_backend():
1690+
pass
16391691
else:
16401692
return dpnp_rng_standard_gamma(shape, size).get_pyobj()
16411693

@@ -1714,6 +1766,8 @@ def standard_t(df, size=None):
17141766
pass
17151767
elif df <= 0:
17161768
pass
1769+
elif dpnp.is_cuda_backend():
1770+
pass
17171771
else:
17181772
return dpnp_rng_standard_t(df, size).get_pyobj()
17191773

@@ -1758,6 +1812,8 @@ def triangular(left, mode, right, size=None):
17581812
pass
17591813
elif left == right:
17601814
pass
1815+
elif dpnp.is_cuda_backend():
1816+
pass
17611817
else:
17621818
return dpnp_rng_triangular(left, mode, right, size).get_pyobj()
17631819

@@ -1862,6 +1918,8 @@ def vonmises(mu, kappa, size=None):
18621918
return dpnp.nan
18631919
elif kappa < 0:
18641920
pass
1921+
elif dpnp.is_cuda_backend():
1922+
pass
18651923
else:
18661924
return dpnp_rng_vonmises(mu, kappa, size).get_pyobj()
18671925

@@ -1898,6 +1956,8 @@ def wald(mean, scale, size=None):
18981956
pass
18991957
elif scale <= 0:
19001958
pass
1959+
elif dpnp.is_cuda_backend():
1960+
pass
19011961
else:
19021962
return dpnp_rng_wald(mean, scale, size).get_pyobj()
19031963

@@ -1930,6 +1990,8 @@ def weibull(a, size=None):
19301990
pass
19311991
elif a < 0:
19321992
pass
1993+
elif dpnp.is_cuda_backend():
1994+
pass
19331995
else:
19341996
return dpnp_rng_weibull(a, size).get_pyobj()
19351997

@@ -1962,6 +2024,8 @@ def zipf(a, size=None):
19622024
pass
19632025
elif a <= 1:
19642026
pass
2027+
elif dpnp.is_cuda_backend():
2028+
pass
19652029
else:
19662030
return dpnp_rng_zipf(a, size).get_pyobj()
19672031

0 commit comments

Comments
 (0)