Skip to content

Commit f78db30

Browse files
committed
improve documentation
1 parent 7a22848 commit f78db30

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

docs/libcudacxx/extended_api/mdspan/mdspan_to_dlpack.rst

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
``mdspan`` to DLPack
44
====================
55

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.
77

88
Defined in the ``<cuda/mdspan>`` header.
99

@@ -48,17 +48,17 @@ Types
4848
4949
DLTensor& get() noexcept;
5050
const DLTensor& get() const noexcept;
51-
};
51+
};
5252
5353
} // namespace cuda
5454
5555
``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.
5656

57-
.. note:: Lifetime
57+
.. note:: **Lifetime**
5858

5959
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.
6060

61-
.. note:: Const-correctness
61+
.. note:: **Const-correctness**
6262

6363
``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.
6464

@@ -79,27 +79,27 @@ The conversion produces a non-owning DLPack view of the ``mdspan`` data and meta
7979

8080
Element types are mapped to ``DLDataType`` according to the DLPack conventions, including:
8181

82+
- ``bool``.
8283
- 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.
8485
- 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.
8688

87-
Constraints and errors
88-
----------------------
89-
90-
**Constraints**
89+
Constraints
90+
-----------
9191

9292
- The accessor ``data_handle_type`` must be a pointer type.
9393

94-
**Runtime errors**
94+
Runtime errors
95+
--------------
9596

9697
- If any ``extent(i)`` or ``stride(i)`` cannot be represented in ``int64_t``, the conversion raises an exception.
9798

9899
Availability notes
99100
------------------
100101

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.
103103

104104
References
105105
----------
@@ -111,14 +111,13 @@ Example
111111

112112
.. code:: cuda
113113
114-
#include <cuda/mdspan>
115-
116114
#include <dlpack/dlpack.h>
117-
#include <cassert>
118-
#include <cstdint>
115+
#include <cuda/mdspan>
116+
#include <cuda/std/cassert>
117+
#include <cuda/std/cstdint>
119118
120119
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>;
122121
123122
int data[6] = {0, 1, 2, 3, 4, 5};
124123
cuda::host_mdspan<int, extents_t> md{data, extents_t{}};

0 commit comments

Comments
 (0)