You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/libcudacxx/extended_api/mdspan/mdspan_to_dlpack.rst
+17-18Lines changed: 17 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
``mdspan`` to DLPack
4
4
====================
5
5
6
-
This functionality provides a conversion from ``cuda::host_mdspan``, ``cuda::device_mdspan``, and ``cuda::managed_mdspan`` to a `DLPack <https://dmlc.github.io/dlpack/latest/>`__ ``DLTensor`` view.
6
+
This functionality provides a conversion from ``cuda::host_mdspan``, ``cuda::device_mdspan``, and ``cuda::managed_mdspan`` to `DLPack <https://dmlc.github.io/dlpack/latest/>`__ ``DLTensor`` view.
7
7
8
8
Defined in the ``<cuda/mdspan>`` header.
9
9
@@ -48,17 +48,17 @@ Types
48
48
49
49
DLTensor& get() noexcept;
50
50
const DLTensor& get() const noexcept;
51
-
};
51
+
};
52
52
53
53
} // namespace cuda
54
54
55
55
``cuda::dlpack_tensor`` stores a ``DLTensor`` and owns the backing storage for its ``shape`` and ``strides`` pointers. The class does not use any heap allocation.
56
56
57
-
.. note:: Lifetime
57
+
.. note:: **Lifetime**
58
58
59
59
The ``DLTensor`` associated with ``cuda::dlpack_tensor`` must not outlive the wrapper. If the wrapper is destroyed, the returned ``DLTensor::shape`` and ``DLTensor::strides`` pointers will dangle.
60
60
61
-
.. note:: Const-correctness
61
+
.. note:: **Const-correctness**
62
62
63
63
``DLTensor::data`` points at ``mdspan.data_handle()`` (or is ``nullptr`` if ``mdspan.size() == 0``). If ``T`` is ``const``, the pointer is ``const_cast``'d because ``DLTensor::data`` is unqualified.
64
64
@@ -79,27 +79,27 @@ The conversion produces a non-owning DLPack view of the ``mdspan`` data and meta
79
79
80
80
Element types are mapped to ``DLDataType`` according to the DLPack conventions, including:
81
81
82
+
- ``bool``.
82
83
- Signed and unsigned integers.
83
-
- IEEE-754 Floating-point and extended precision floating-point, including ``__half``, ``__nv_bfloat16``, FP8, FP6, FP4 when available.
84
+
- IEEE-754 Floating-point and extended precision floating-point, including ``__half``, ``__nv_bfloat16``, ``__float128``, FP8, FP6, FP4 when available.
84
85
- Complex: ``cuda::std::complex<__half>``, ``cuda::std::complex<float>``, and ``cuda::std::complex<double>``.
85
-
- `CUDA built-in vector types <https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/cpp-language-extensions.html#built-in-types>`__, such as ``int2``, ``float4``, etc..
86
+
- `CUDA built-in vector types <https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/cpp-language-extensions.html#built-in-types>`__, such as ``int2``, ``float4``, etc.
87
+
- Vector types for extended floating-point, such as ``__half2``, ``__nv_fp8x4_e4m3``, etc.
86
88
87
-
Constraints and errors
88
-
----------------------
89
-
90
-
**Constraints**
89
+
Constraints
90
+
-----------
91
91
92
92
- The accessor ``data_handle_type`` must be a pointer type.
93
93
94
-
**Runtime errors**
94
+
Runtime errors
95
+
--------------
95
96
96
97
- If any ``extent(i)`` or ``stride(i)`` cannot be represented in ``int64_t``, the conversion raises an exception.
97
98
98
99
Availability notes
99
100
------------------
100
101
101
-
- This API is available only when DLPack headers are present (``<dlpack/dlpack.h>`` is found in the include path).
102
-
* ``dlpack/dlpack.h`` (`DLPack v1 <https://github.com/dmlc/dlpack>`__) must be discoverable at compile time, namely available in the include path.
102
+
- This API is available only when DLPack header is present, namely ``<dlpack/dlpack.h>`` is found in the include path.
103
103
104
104
References
105
105
----------
@@ -111,14 +111,13 @@ Example
111
111
112
112
.. code:: cuda
113
113
114
-
#include <cuda/mdspan>
115
-
116
114
#include <dlpack/dlpack.h>
117
-
#include <cassert>
118
-
#include <cstdint>
115
+
#include <cuda/mdspan>
116
+
#include <cuda/std/cassert>
117
+
#include <cuda/std/cstdint>
119
118
120
119
int main() {
121
-
using extents_t = cuda::std::extents<std::size_t, 2, 3>;
120
+
using extents_t = cuda::std::extents<size_t, 2, 3>;
0 commit comments