@@ -71,33 +71,35 @@ Features
71
71
72
72
**Memory spaces **
73
73
74
- +--------------------+------------------+-------------------+
75
- | | Host memory | Device memory |
76
- +====================+==================+===================+
77
- | ``host_mdspan `` | Allowed | *Compile error * |
78
- +--------------------+------------------+-------------------+
79
- | ``device_mdspan `` | *Compile error * | Allowed |
80
- +--------------------+------------------+-------------------+
81
- | ``managed_mdspan `` | Allowed *** ** | Allowed *** ** |
82
- +--------------------+------------------+-------------------+
83
-
84
- *** ** the validity of the *managed * memory space is checked at run-time in debug mode.
74
+ *Host *, *device *, and *managed * ``mdspan `` can be created and "sliced" (``cuda::std::submdspan ``) on any memory spaces. However, accessing to a specific memory space is restricted to the respective *accessor * type.
75
+
76
+ +----------------------------------+------------------+-------------------+
77
+ | ``mdspan `` / memory space access | Host memory | Device memory |
78
+ +==================================+==================+===================+
79
+ | ``host_mdspan `` | Allowed | *Compile error * |
80
+ +----------------------------------+------------------+-------------------+
81
+ | ``device_mdspan `` | *Compile error * | Allowed |
82
+ +----------------------------------+------------------+-------------------+
83
+ | ``managed_mdspan `` | Allowed *** ** | Allowed *** ** |
84
+ +----------------------------------+------------------+-------------------+
85
+
86
+ *** ** the validity of the *managed * memory space is checked at run-time in debug mode (host-side).
85
87
86
88
**Conversions **
87
89
88
90
+-----------------------------+------------------+-------------------+---------------------+
89
91
| | ``host_mdspan `` | ``device_mdspan `` | ``managed_mdspan `` |
90
92
+=============================+==================+===================+=====================+
91
- | ``host_mdspan `` | Allowed ** * ** | *Compile error * | *Compile error * |
93
+ | ``host_mdspan `` | Allowed | *Compile error * | *Compile error * |
92
94
+-----------------------------+------------------+-------------------+---------------------+
93
- | ``device_mdspan `` | *Compile error * | Allowed ** * ** | *Compile error * |
95
+ | ``device_mdspan `` | *Compile error * | Allowed | *Compile error * |
94
96
+-----------------------------+------------------+-------------------+---------------------+
95
- | ``managed_mdspan `` | Allowed | Allowed | Allowed ** * ** |
97
+ | ``managed_mdspan `` | Allowed | Allowed | Allowed |
96
98
+-----------------------------+------------------+-------------------+---------------------+
97
99
| Other mdspan | Allowed | Allowed | Allowed |
98
100
+-----------------------------+------------------+-------------------+---------------------+
99
101
100
- ** * ** the conversion is ``explicit `` if the base accessors are not directly convertible.
102
+ *Note: * the conversion is ``explicit `` if the base accessor is not directly convertible.
101
103
102
104
Example 1
103
105
---------
@@ -128,19 +130,20 @@ Example 1
128
130
}
129
131
130
132
int main() {
131
- void * d_ptr;
133
+ int * d_ptr;
132
134
cudaMalloc(&d_ptr, 4 * sizeof(int));
133
- int h_ptr[4];
134
- cuda::host_mdspan<int, dim> h_md{h_ptr, 4 };
135
- cuda::device_mdspan<int, dim> d_md{d_ptr, 4};
135
+ int h_ptr[4];
136
+ cuda::host_mdspan h_md{h_ptr};
137
+ cuda::device_mdspan d_md{d_ptr, 4};
136
138
kernel_d<<<1, 1>>>(d_md); // ok
137
139
// kernel_d<<<1, 1>>>(h_md); // compile error
138
140
host_function_h(h_md); // ok
139
141
host_function_d(h_md); // compile error
140
142
// host_function_m(h_md); // compile error
143
+ cudaFree(d_ptr);
141
144
}
142
145
143
- `See example 1 on Godbolt 🔗 <https://godbolt.org/z/hW9faqsGW >`_
146
+ `See example 1 on Godbolt 🔗 <https://godbolt.org/z/fezxsbjaq >`_
144
147
145
148
Example 2
146
149
---------
@@ -162,17 +165,18 @@ Example 2
162
165
}
163
166
164
167
int main() {
165
- void * m_ptr;
168
+ int * m_ptr;
166
169
cudaMallocManaged(&m_ptr, 4 * sizeof(int));
167
- cuda::managed_mdspan<int, dim> m_md{m_ptr, 4};
170
+ cuda::managed_mdspan m_md{m_ptr, 4};
168
171
kernel_d<<<1, 1>>>(m_md); // ok
169
172
host_function_h(m_md); // ok
170
173
171
- cuda::managed_mdspan<int, dim> m_md2{d_ptr, 4};
174
+ cuda::managed_mdspan m_md2{d_ptr, 4};
172
175
m_md2[0]; // run-time error
176
+ cudaFree(d_ptr);
173
177
}
174
178
175
- `See example 2 on Godbolt 🔗 <https://godbolt.org/z/WxWfaas5h >`_
179
+ `See example 2 on Godbolt 🔗 <https://godbolt.org/z/Kj39Pe4vP >`_
176
180
177
181
178
182
Example 3
@@ -189,13 +193,13 @@ Conversion from other accessors:
189
193
int main() {
190
194
using cuda::std::layout_right;
191
195
using cuda::std::aligned_accessor;
192
- int h_ptr[4];
193
- cuda::std::mdspan<int, dim> md{h_ptr, 4 };
194
- cuda::host_mdspan<int, dim> h_md = md; // ok
196
+ int h_ptr[4];
197
+ cuda::std::mdspan md{h_ptr};
198
+ cuda::host_mdspan h_md = md; // ok
195
199
196
200
cuda::std::mdspan<int, dim, layout_right, aligned_accessor<int, 8>> md_a{h_ptr, 4};
197
- // cuda::host_mdspan<int, dim> h_md = md_a; // compile-error
198
- cuda::host_mdspan<int, dim> h_md{md_a}; // ok
201
+ // cuda::host_mdspan h_md = md_a; // compile-error
202
+ cuda::host_mdspan h_md{md_a}; // ok
199
203
}
200
204
201
- `See example 3 on Godbolt 🔗 <https://godbolt.org/z/ja89roofx >`_
205
+ `See example 3 on Godbolt 🔗 <https://godbolt.org/z/7dq7vcTWP >`_
0 commit comments