From 85d417fc41ec5491d8ed87325169d2bf07180107 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 7 Aug 2024 19:04:17 -0700 Subject: [PATCH 1/3] Expose `DLDeviceType` in `dpctl.tensor` --- dpctl/tensor/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dpctl/tensor/__init__.py b/dpctl/tensor/__init__.py index dff75b9c2c..c6fb8f21ea 100644 --- a/dpctl/tensor/__init__.py +++ b/dpctl/tensor/__init__.py @@ -93,7 +93,7 @@ from dpctl.tensor._reshape import reshape from dpctl.tensor._search_functions import where from dpctl.tensor._statistical_functions import mean, std, var -from dpctl.tensor._usmarray import usm_ndarray +from dpctl.tensor._usmarray import DLDeviceType, usm_ndarray from dpctl.tensor._utility_functions import all, any, diff from ._accumulation import cumulative_logsumexp, cumulative_prod, cumulative_sum @@ -376,4 +376,5 @@ "nextafter", "diff", "count_nonzero", + "DLDeviceType", ] From 5ae872a986cade261467722ee62adf0cef59a58d Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 7 Aug 2024 19:04:41 -0700 Subject: [PATCH 2/3] Docstring for DLDeviceType listing the valid enumerators --- dpctl/tensor/_usmarray.pyx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dpctl/tensor/_usmarray.pyx b/dpctl/tensor/_usmarray.pyx index 2984159261..f9d8278864 100644 --- a/dpctl/tensor/_usmarray.pyx +++ b/dpctl/tensor/_usmarray.pyx @@ -54,6 +54,40 @@ include "_slicing.pxi" class DLDeviceType(IntEnum): + """ + An ``IntEnum`` for the types of DLDevices supported by the DLPack + protocol. + ``kDLCPU``: + CPU (host) device + ``kDLCUDA``: + CUDA GPU device + ``kDLCUDAHost``: + Pinned CUDA CPU memory by cudaMallocHost + ``kDLOpenCL``: + OpenCL device + ``kDLVulkan``: + Vulkan buffer + ``kDLMetal``: + Metal for Apple GPU + ``kDLVPI``: + Verilog simulator buffer + ``kDLROCM``: + ROCm GPU device + ``kDLROCMHost``: + Pinned ROCm CPU memory allocated by hipMallocHost + ``kDLExtDev``: + Reserved extension device type used to test new devices + ``kDLCUDAManaged``: + CUDA managed/unified memory allocated by cudaMallocManaged + ``kDLOneAPI``: + Unified shared memory allocated on a oneAPI non-partitioned device + ``kDLWebGPU``: + Device support for WebGPU standard + ``kDLHexagon``: + Qualcomm Hexagon DSP + ``kDLMAIA``: + Microsoft MAIA device + """ kDLCPU = c_dlpack.device_CPU kDLCUDA = c_dlpack.device_CUDA kDLCUDAHost = c_dlpack.device_CUDAHost From 353be0d8ef3b66703d3a2474bc9dc23e316e553e Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 7 Aug 2024 19:08:30 -0700 Subject: [PATCH 3/3] Add documentation for constants and `DLDeviceType` enums --- .../api_reference/dpctl/tensor.constants.rst | 35 +++++++++++++++++++ .../api_reference/dpctl/tensor.rst | 2 ++ dpctl/tensor/_usmarray.pyx | 2 ++ 3 files changed, 39 insertions(+) create mode 100644 docs/doc_sources/api_reference/dpctl/tensor.constants.rst diff --git a/docs/doc_sources/api_reference/dpctl/tensor.constants.rst b/docs/doc_sources/api_reference/dpctl/tensor.constants.rst new file mode 100644 index 0000000000..2cb9f770d2 --- /dev/null +++ b/docs/doc_sources/api_reference/dpctl/tensor.constants.rst @@ -0,0 +1,35 @@ +.. _dpctl_tensor_constants: + +Constants +======================== + +The following constants are defined in :py:mod:`dpctl.tensor`: + +.. currentmodule:: dpctl.tensor + +.. autodata:: DLDeviceType + +.. data:: e + + ``float``: + IEEE 754 floating-point representation of Euler's constant. + +.. data:: inf + + ``float``: + IEEE 754 floating-point representation of (positive) infinity. + +.. data:: nan + + ``float``: + IEEE 754 floating-point representation of Not a Number (NaN). + +.. data:: newaxis + + ``NoneType``: + Alias for ``None`` which is useful for indexing. + +.. data:: pi + + ``float``: + IEEE 754 floating-point representation of the mathematical constant π. diff --git a/docs/doc_sources/api_reference/dpctl/tensor.rst b/docs/doc_sources/api_reference/dpctl/tensor.rst index d2aaa6fbc4..10e1f65d9f 100644 --- a/docs/doc_sources/api_reference/dpctl/tensor.rst +++ b/docs/doc_sources/api_reference/dpctl/tensor.rst @@ -29,6 +29,7 @@ This module contains: * :ref:`sorting functions ` * :ref:`statistical functions ` * :ref:`utility functions ` +* :ref:`constants ` .. toctree:: @@ -48,3 +49,4 @@ This module contains: tensor.sorting_functions tensor.statistical_functions tensor.utility_functions + tensor.constants diff --git a/dpctl/tensor/_usmarray.pyx b/dpctl/tensor/_usmarray.pyx index f9d8278864..b1a428cbb4 100644 --- a/dpctl/tensor/_usmarray.pyx +++ b/dpctl/tensor/_usmarray.pyx @@ -1278,6 +1278,8 @@ cdef class usm_ndarray: The tuple describes the non-partitioned device where the array has been allocated, or the non-partitioned parent device of the allocation device. + See ``DLDeviceType`` for a list of devices supported by the DLPack protocol. + Raises: DLPackCreationError: when the ``device_id`` could not be determined.