From Jason Turner

[mdspan.accessor]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpdj7oaaex/{from.md → to.md} +146 -1
tmp/tmpdj7oaaex/{from.md → to.md} RENAMED
@@ -8,11 +8,11 @@ of such objects and an index.
8
 
9
  A range of indices [0, N) is an *accessible range* of a given data
10
  handle and an accessor if, for each i in the range, the accessor
11
  policy’s `access` function produces a valid reference to an object.
12
 
13
- In subclause [[mdspan.accessor.reqmts]],
14
 
15
  - `A` denotes an accessor policy.
16
  - `a` denotes a value of type `A` or `const A`.
17
  - `p` denotes a value of type `A::data_handle_type` or
18
  `const A::data_handle_type`. \[*Note 1*: The type
@@ -152,5 +152,150 @@ constexpr reference access(data_handle_type p, size_t i) const noexcept;
152
  constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept;
153
  ```
154
 
155
  *Effects:* Equivalent to: `return p + i;`
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  A range of indices [0, N) is an *accessible range* of a given data
10
  handle and an accessor if, for each i in the range, the accessor
11
  policy’s `access` function produces a valid reference to an object.
12
 
13
+ In [[mdspan.accessor.reqmts]],
14
 
15
  - `A` denotes an accessor policy.
16
  - `a` denotes a value of type `A` or `const A`.
17
  - `p` denotes a value of type `A::data_handle_type` or
18
  `const A::data_handle_type`. \[*Note 1*: The type
 
152
  constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept;
153
  ```
154
 
155
  *Effects:* Equivalent to: `return p + i;`
156
 
157
+ ##### Class template `aligned_accessor` <a id="mdspan.accessor.aligned">[[mdspan.accessor.aligned]]</a>
158
+
159
+ ###### Overview <a id="mdspan.accessor.aligned.overview">[[mdspan.accessor.aligned.overview]]</a>
160
+
161
+ ``` cpp
162
+ namespace std {
163
+ template<class ElementType, size_t ByteAlignment>
164
+ struct aligned_accessor {
165
+ using offset_policy = default_accessor<ElementType>;
166
+ using element_type = ElementType;
167
+ using reference = ElementType&;
168
+ using data_handle_type = ElementType*;
169
+
170
+ static constexpr size_t byte_alignment = ByteAlignment;
171
+
172
+ constexpr aligned_accessor() noexcept = default;
173
+ template<class OtherElementType, size_t OtherByteAlignment>
174
+ constexpr aligned_accessor(
175
+ aligned_accessor<OtherElementType, OtherByteAlignment>) noexcept;
176
+ template<class OtherElementType>
177
+ constexpr explicit aligned_accessor(default_accessor<OtherElementType>) noexcept;
178
+
179
+ template<class OtherElementType>
180
+ constexpr operator default_accessor<OtherElementType>() const noexcept;
181
+
182
+ constexpr reference access(data_handle_type p, size_t i) const noexcept;
183
+
184
+ constexpr typename offset_policy::data_handle_type offset(
185
+ data_handle_type p, size_t i) const noexcept;
186
+ };
187
+ }
188
+ ```
189
+
190
+ *Mandates:*
191
+
192
+ - `byte_alignment` is a power of two, and
193
+ - `byte_alignment >= alignof(ElementType)` is `true`.
194
+
195
+ `aligned_accessor` meets the accessor policy requirements.
196
+
197
+ `ElementType` is required to be a complete object type that is neither
198
+ an abstract class type nor an array type.
199
+
200
+ Each specialization of `aligned_accessor` is a trivially copyable type
201
+ that models `semiregular`.
202
+
203
+ \[`0`, n) is an accessible range for an object `p` of type
204
+ `data_handle_type` and an object of type `aligned_accessor` if and only
205
+ if
206
+
207
+ - \[`p`, `p + `n) is a valid range, and,
208
+ - if n is greater than zero, then
209
+ `is_sufficiently_aligned<byte_alignment>(p)` is `true`.
210
+
211
+ [*Example 1*:
212
+
213
+ The following function `compute` uses `is_sufficiently_aligned` to check
214
+ whether a given `mdspan` with `default_accessor` has a data handle with
215
+ sufficient alignment to be used with
216
+ `aligned_accessor<float, 4 * sizeof(float)>`. If so, the function
217
+ dispatches to a function `compute_using_fourfold_overalignment` that
218
+ requires fourfold over-alignment of arrays, but can therefore use
219
+ hardware-specific instructions, such as four-wide SIMD (Single
220
+ Instruction Multiple Data) instructions. Otherwise, `compute` dispatches
221
+ to a possibly less optimized function
222
+ `compute_without_requiring_overalignment` that has no over-alignment
223
+ requirement.
224
+
225
+ ``` cpp
226
+ void compute_using_fourfold_overalignment(
227
+ mdspan<float, dims<1>, layout_right, aligned_accessor<float, 4 * alignof(float)>> x);
228
+
229
+ void compute_without_requiring_overalignment(
230
+ mdspan<float, dims<1>, layout_right> x);
231
+
232
+ void compute(mdspan<float, dims<1>> x) {
233
+ constexpr auto byte_alignment = 4 * sizeof(float);
234
+ auto accessor = aligned_accessor<float, byte_alignment>{};
235
+ auto x_handle = x.data_handle();
236
+
237
+ if (is_sufficiently_aligned<byte_alignment>(x_handle)) {
238
+ compute_using_fourfold_overalignment(mdspan{x_handle, x.mapping(), accessor});
239
+ } else {
240
+ compute_without_requiring_overalignment(x);
241
+ }
242
+ }
243
+ ```
244
+
245
+ — *end example*]
246
+
247
+ ###### Members <a id="mdspan.accessor.aligned.members">[[mdspan.accessor.aligned.members]]</a>
248
+
249
+ ``` cpp
250
+ template<class OtherElementType, size_t OtherByteAlignment>
251
+ constexpr aligned_accessor(aligned_accessor<OtherElementType, OtherByteAlignment>) noexcept;
252
+ ```
253
+
254
+ *Constraints:*
255
+
256
+ - `is_convertible_v<OtherElementType(*)[], element_type(*)[]>` is
257
+ `true`.
258
+ - `OtherByteAlignment >= byte_alignment` is `true`.
259
+
260
+ *Effects:* None.
261
+
262
+ ``` cpp
263
+ template<class OtherElementType>
264
+ constexpr explicit aligned_accessor(default_accessor<OtherElementType>) noexcept;
265
+ ```
266
+
267
+ *Constraints:*
268
+ `is_convertible_v<OtherElementType(*)[], element_type(*)[]>` is `true`.
269
+
270
+ *Effects:* None.
271
+
272
+ ``` cpp
273
+ constexpr reference access(data_handle_type p, size_t i) const noexcept;
274
+ ```
275
+
276
+ *Preconditions:* \[`0`, `i + 1`) is an accessible range for `p` and
277
+ `*this`.
278
+
279
+ *Effects:* Equivalent to: `return assume_aligned<byte_alignment>(p)[i];`
280
+
281
+ ``` cpp
282
+ template<class OtherElementType>
283
+ constexpr operator default_accessor<OtherElementType>() const noexcept;
284
+ ```
285
+
286
+ *Constraints:*
287
+ `is_convertible_v<element_type(*)[], OtherElementType(*)[]>` is `true`.
288
+
289
+ *Effects:* Equivalent to: `return {};`
290
+
291
+ ``` cpp
292
+ constexpr typename offset_policy::data_handle_type
293
+ offset(data_handle_type p, size_t i) const noexcept;
294
+ ```
295
+
296
+ *Preconditions:* \[`0`, `i + 1`) is an accessible range for `p` and
297
+ `*this`.
298
+
299
+ *Effects:* Equivalent to:
300
+ `return assume_aligned<byte_alignment>(p) + i;`
301
+