Skip to content

Commit 2bd92df

Browse files
Merge pull request #1793 from IntelPython/document-dldevicetype-constants
Expose `DLDeviceType` enumerator in `dpctl.tensor`
2 parents fe71e99 + 353be0d commit 2bd92df

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. _dpctl_tensor_constants:
2+
3+
Constants
4+
========================
5+
6+
The following constants are defined in :py:mod:`dpctl.tensor`:
7+
8+
.. currentmodule:: dpctl.tensor
9+
10+
.. autodata:: DLDeviceType
11+
12+
.. data:: e
13+
14+
``float``:
15+
IEEE 754 floating-point representation of Euler's constant.
16+
17+
.. data:: inf
18+
19+
``float``:
20+
IEEE 754 floating-point representation of (positive) infinity.
21+
22+
.. data:: nan
23+
24+
``float``:
25+
IEEE 754 floating-point representation of Not a Number (NaN).
26+
27+
.. data:: newaxis
28+
29+
``NoneType``:
30+
Alias for ``None`` which is useful for indexing.
31+
32+
.. data:: pi
33+
34+
``float``:
35+
IEEE 754 floating-point representation of the mathematical constant π.

docs/doc_sources/api_reference/dpctl/tensor.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This module contains:
2929
* :ref:`sorting functions <dpctl_tensor_sorting_functions>`
3030
* :ref:`statistical functions <dpctl_tensor_statistical_functions>`
3131
* :ref:`utility functions <dpctl_tensor_utility_functions>`
32+
* :ref:`constants <dpctl_tensor_constants>`
3233

3334

3435
.. toctree::
@@ -48,3 +49,4 @@ This module contains:
4849
tensor.sorting_functions
4950
tensor.statistical_functions
5051
tensor.utility_functions
52+
tensor.constants

dpctl/tensor/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
from dpctl.tensor._reshape import reshape
9494
from dpctl.tensor._search_functions import where
9595
from dpctl.tensor._statistical_functions import mean, std, var
96-
from dpctl.tensor._usmarray import usm_ndarray
96+
from dpctl.tensor._usmarray import DLDeviceType, usm_ndarray
9797
from dpctl.tensor._utility_functions import all, any, diff
9898

9999
from ._accumulation import cumulative_logsumexp, cumulative_prod, cumulative_sum
@@ -376,4 +376,5 @@
376376
"nextafter",
377377
"diff",
378378
"count_nonzero",
379+
"DLDeviceType",
379380
]

dpctl/tensor/_usmarray.pyx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,40 @@ include "_slicing.pxi"
5454

5555

5656
class DLDeviceType(IntEnum):
57+
"""
58+
An ``IntEnum`` for the types of DLDevices supported by the DLPack
59+
protocol.
60+
``kDLCPU``:
61+
CPU (host) device
62+
``kDLCUDA``:
63+
CUDA GPU device
64+
``kDLCUDAHost``:
65+
Pinned CUDA CPU memory by cudaMallocHost
66+
``kDLOpenCL``:
67+
OpenCL device
68+
``kDLVulkan``:
69+
Vulkan buffer
70+
``kDLMetal``:
71+
Metal for Apple GPU
72+
``kDLVPI``:
73+
Verilog simulator buffer
74+
``kDLROCM``:
75+
ROCm GPU device
76+
``kDLROCMHost``:
77+
Pinned ROCm CPU memory allocated by hipMallocHost
78+
``kDLExtDev``:
79+
Reserved extension device type used to test new devices
80+
``kDLCUDAManaged``:
81+
CUDA managed/unified memory allocated by cudaMallocManaged
82+
``kDLOneAPI``:
83+
Unified shared memory allocated on a oneAPI non-partitioned device
84+
``kDLWebGPU``:
85+
Device support for WebGPU standard
86+
``kDLHexagon``:
87+
Qualcomm Hexagon DSP
88+
``kDLMAIA``:
89+
Microsoft MAIA device
90+
"""
5791
kDLCPU = c_dlpack.device_CPU
5892
kDLCUDA = c_dlpack.device_CUDA
5993
kDLCUDAHost = c_dlpack.device_CUDAHost
@@ -1244,6 +1278,8 @@ cdef class usm_ndarray:
12441278
The tuple describes the non-partitioned device where the array has been allocated,
12451279
or the non-partitioned parent device of the allocation device.
12461280
1281+
See ``DLDeviceType`` for a list of devices supported by the DLPack protocol.
1282+
12471283
Raises:
12481284
DLPackCreationError:
12491285
when the ``device_id`` could not be determined.

0 commit comments

Comments
 (0)