DPC++ Runtime
Runtime libraries for oneAPI DPC++
sycl_span.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 //===------------------------------ span ---------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===---------------------------------------------------------------------===//
9 
10 #if __cplusplus >= 201703L
11 
12 #ifndef _SYCL_SPAN
13 #define _SYCL_SPAN
14 
15 /*
16  Derived from libcxx span.
17  Original _LIBCPP macros replaced with _SYCL_SPAN to avoid collisions.
18 
19 
20  span synopsis
21 
22 namespace std {
23 
24 // constants
25 inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
26 
27 // [views.span], class template span
28 template <class ElementType, size_t Extent = dynamic_extent>
29  class span;
30 
31 // [span.objectrep], views of object representation
32 template <class ElementType, size_t Extent>
33  span<const byte, ((Extent == dynamic_extent) ? dynamic_extent :
34  (sizeof(ElementType) * Extent))> as_bytes(span<ElementType, Extent> s)
35 noexcept;
36 
37 template <class ElementType, size_t Extent>
38  span< byte, ((Extent == dynamic_extent) ? dynamic_extent :
39  (sizeof(ElementType) * Extent))> as_writable_bytes(span<ElementType,
40 Extent> s) noexcept;
41 
42 
43 namespace std {
44 template <class ElementType, size_t Extent = dynamic_extent>
45 class span {
46 public:
47  // constants and types
48  using element_type = ElementType;
49  using value_type = std::remove_cv_t<ElementType>;
50  using size_type = size_t;
51  using difference_type = ptrdiff_t;
52  using pointer = element_type*;
53  using const_pointer = const element_type*;
54  using reference = element_type&;
55  using const_reference = const element_type&;
56  using iterator = implementation-defined;
57  using reverse_iterator = std::reverse_iterator<iterator>;
58  static constexpr size_type extent = Extent;
59 
60  // [span.cons], span constructors, copy, assignment, and destructor
61  constexpr span() noexcept;
62  constexpr explicit(Extent != dynamic_extent) span(pointer ptr, size_type
63 count); constexpr explicit(Extent != dynamic_extent) span(pointer firstElem,
64 pointer lastElem); template <size_t N> constexpr span(element_type (&arr)[N])
65 noexcept; template <size_t N> constexpr span(array<value_type, N>& arr)
66 noexcept; template <size_t N> constexpr span(const array<value_type, N>& arr)
67 noexcept; template <class Container> constexpr explicit(Extent !=
68 dynamic_extent) span(Container& cont); template <class Container> constexpr
69 explicit(Extent != dynamic_extent) span(const Container& cont); constexpr
70 span(const span& other) noexcept = default; template <class OtherElementType,
71 size_t OtherExtent> constexpr explicit(Extent != dynamic_extent) span(const
72 span<OtherElementType, OtherExtent>& s) noexcept; ~span() noexcept = default;
73  constexpr span& operator=(const span& other) noexcept = default;
74 
75  // [span.sub], span subviews
76  template <size_t Count>
77  constexpr span<element_type, Count> first() const;
78  template <size_t Count>
79  constexpr span<element_type, Count> last() const;
80  template <size_t Offset, size_t Count = dynamic_extent>
81  constexpr span<element_type, see below> subspan() const;
82 
83  constexpr span<element_type, dynamic_extent> first(size_type count) const;
84  constexpr span<element_type, dynamic_extent> last(size_type count) const;
85  constexpr span<element_type, dynamic_extent> subspan(size_type offset,
86 size_type count = dynamic_extent) const;
87 
88  // [span.obs], span observers
89  constexpr size_type size() const noexcept;
90  constexpr size_type size_bytes() const noexcept;
91  constexpr bool empty() const noexcept;
92 
93  // [span.elem], span element access
94  constexpr reference operator[](size_type idx) const;
95  constexpr reference front() const;
96  constexpr reference back() const;
97  constexpr pointer data() const noexcept;
98 
99  // [span.iterators], span iterator support
100  constexpr iterator begin() const noexcept;
101  constexpr iterator end() const noexcept;
102  constexpr reverse_iterator rbegin() const noexcept;
103  constexpr reverse_iterator rend() const noexcept;
104 
105 private:
106  pointer data_; // exposition only
107  size_type size_; // exposition only
108 };
109 
110 template<class T, size_t N>
111  span(T (&)[N]) -> span<T, N>;
112 
113 template<class T, size_t N>
114  span(array<T, N>&) -> span<T, N>;
115 
116 template<class T, size_t N>
117  span(const array<T, N>&) -> span<const T, N>;
118 
119 template<class Container>
120  span(Container&) -> span<typename Container::value_type>;
121 
122 template<class Container>
123  span(const Container&) -> span<const typename Container::value_type>;
124 
125 } // namespace std
126 
127 */
128 
129 #include <array> // for array
130 #include <cassert> // for assert
131 #include <cstddef> // for byte
132 #include <iterator> // for iterators
133 #include <type_traits> // for remove_cv, etc
134 
135 #define _SYCL_SPAN_TEMPLATE_VIS
136 #define _SYCL_SPAN_INLINE_VISIBILITY inline
137 
139 namespace sycl {
140 
141 // byte is unsigned char at sycl/image.hpp:58
142 using byte = unsigned char;
143 
144 // asserts suppressed for device compatibility.
145 // TODO: enable
146 #if defined(__SYCL_DEVICE_ONLY__)
147 #define _SYCL_SPAN_ASSERT(x, m) ((void)0)
148 #else
149 #define _SYCL_SPAN_ASSERT(x, m) assert(((x) && m))
150 #endif
151 
152 inline constexpr size_t dynamic_extent = SIZE_MAX;
153 template <typename _Tp, size_t _Extent = dynamic_extent> class span;
154 
155 template <class _Tp> struct __is_span_impl : public std::false_type {};
156 
157 template <class _Tp, size_t _Extent>
158 struct __is_span_impl<span<_Tp, _Extent>> : public std::true_type {};
159 
160 template <class _Tp>
161 struct __is_span : public __is_span_impl<std::remove_cv_t<_Tp>> {};
162 
163 template <class _Tp> struct __is_std_array_impl : public std::false_type {};
164 
165 template <class _Tp, size_t _Sz>
166 struct __is_std_array_impl<std::array<_Tp, _Sz>> : public std::true_type {};
167 
168 template <class _Tp>
169 struct __is_std_array : public __is_std_array_impl<std::remove_cv_t<_Tp>> {};
170 
171 template <class _Tp, class _ElementType, class = void>
172 struct __is_span_compatible_container : public std::false_type {};
173 
174 template <class _Tp, class _ElementType>
175 struct __is_span_compatible_container<
176  _Tp, _ElementType,
177  std::void_t<
178  // is not a specialization of span
179  typename std::enable_if<!__is_span<_Tp>::value, std::nullptr_t>::type,
180  // is not a specialization of array
181  typename std::enable_if<!__is_std_array<_Tp>::value,
182  std::nullptr_t>::type,
183  // is_array_v<Container> is false,
184  typename std::enable_if<!std::is_array_v<_Tp>, std::nullptr_t>::type,
185  // data(cont) and size(cont) are well formed
186  decltype(data(std::declval<_Tp>())),
187  decltype(size(std::declval<_Tp>())),
188  // remove_pointer_t<decltype(data(cont))>(*)[] is convertible to
189  // ElementType(*)[]
190  typename std::enable_if<
191  std::is_convertible_v<std::remove_pointer_t<decltype(
192  data(std::declval<_Tp &>()))> (*)[],
193  _ElementType (*)[]>,
194  std::nullptr_t>::type>> : public std::true_type {};
195 
196 template <typename _Tp, size_t _Extent> class _SYCL_SPAN_TEMPLATE_VIS span {
197 public:
198  // constants and types
199  using element_type = _Tp;
200  using value_type = std::remove_cv_t<_Tp>;
201  using size_type = size_t;
202  using difference_type = ptrdiff_t;
203  using pointer = _Tp *;
204  using const_pointer = const _Tp *;
205  using reference = _Tp &;
206  using const_reference = const _Tp &;
207  using iterator = pointer;
208  using rev_iterator = std::reverse_iterator<pointer>;
209 
210  static constexpr size_type extent = _Extent;
211 
212  // [span.cons], span constructors, copy, assignment, and destructor
213  template <size_t _Sz = _Extent,
214  std::enable_if_t<_Sz == 0, std::nullptr_t> = nullptr>
215  _SYCL_SPAN_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} {}
216 
217  constexpr span(const span &) noexcept = default;
218  constexpr span &operator=(const span &) noexcept = default;
219 
220  _SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span(pointer __ptr,
221  size_type __count)
222  : __data{__ptr} {
223  (void)__count;
224  _SYCL_SPAN_ASSERT(_Extent == __count,
225  "size mismatch in span's constructor (ptr, len)");
226  }
227  _SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span(pointer __f, pointer __l)
228  : __data{__f} {
229  (void)__l;
230  _SYCL_SPAN_ASSERT(_Extent == std::distance(__f, __l),
231  "size mismatch in span's constructor (ptr, ptr)");
232  }
233 
234  template <class _OtherElementType,
235  std::enable_if_t<std::is_convertible_v<_OtherElementType (*)[],
236  element_type (*)[]>,
237  std::nullptr_t> = nullptr>
238  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(
239  std::array<_OtherElementType, _Extent> &__arr) noexcept
240  : __data{__arr.data()} {}
241 
242  template <
243  class _OtherElementType,
244  std::enable_if_t<std::is_convertible_v<const _OtherElementType (*)[],
245  element_type (*)[]>,
246  std::nullptr_t> = nullptr>
247  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(
248  const std::array<_OtherElementType, _Extent> &__arr) noexcept
249  : __data{__arr.data()} {}
250 
251  template <class _Container>
252  _SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span(
253  _Container &__c,
254  std::enable_if_t<__is_span_compatible_container<_Container, _Tp>::value,
255  std::nullptr_t> = nullptr)
256  : __data{std::data(__c)} {
257  _SYCL_SPAN_ASSERT(_Extent == std::size(__c),
258  "size mismatch in span's constructor (range)");
259  }
260 
261  template <class _Container>
262  _SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span(
263  const _Container &__c,
265  __is_span_compatible_container<const _Container, _Tp>::value,
266  std::nullptr_t> = nullptr)
267  : __data{std::data(__c)} {
268  _SYCL_SPAN_ASSERT(_Extent == std::size(__c),
269  "size mismatch in span's constructor (range)");
270  }
271 
272  template <class _OtherElementType>
273  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(
274  const span<_OtherElementType, _Extent> &__other,
276  std::is_convertible_v<_OtherElementType (*)[], element_type (*)[]>,
277  std::nullptr_t> = nullptr)
278  : __data{__other.data()} {}
279 
280  // ~span() noexcept = default;
281 
282  template <size_t _Count>
283  _SYCL_SPAN_INLINE_VISIBILITY constexpr span<element_type, _Count>
284  first() const noexcept {
285  static_assert(_Count <= _Extent, "Count out of range in span::first()");
286  return span<element_type, _Count>{data(), _Count};
287  }
288 
289  template <size_t _Count>
290  _SYCL_SPAN_INLINE_VISIBILITY constexpr span<element_type, _Count> last() const
291  noexcept {
292  static_assert(_Count <= _Extent, "Count out of range in span::last()");
293  return span<element_type, _Count>{data() + size() - _Count, _Count};
294  }
295 
296  _SYCL_SPAN_INLINE_VISIBILITY
297  constexpr span<element_type, dynamic_extent> first(size_type __count) const
298  noexcept {
299  _SYCL_SPAN_ASSERT(__count <= size(),
300  "Count out of range in span::first(count)");
301  return {data(), __count};
302  }
303 
304  _SYCL_SPAN_INLINE_VISIBILITY
305  constexpr span<element_type, dynamic_extent> last(size_type __count) const
306  noexcept {
307  _SYCL_SPAN_ASSERT(__count <= size(),
308  "Count out of range in span::last(count)");
309  return {data() + size() - __count, __count};
310  }
311 
312  template <size_t _Offset, size_t _Count = dynamic_extent>
313  _SYCL_SPAN_INLINE_VISIBILITY constexpr auto subspan() const noexcept
314  -> span<element_type,
315  (_Count != dynamic_extent ? _Count : _Extent - _Offset)> {
316  static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()");
317  static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset,
318  "Offset + count out of range in span::subspan()");
319 
320  using _ReturnType =
321  span<element_type,
322  _Count != dynamic_extent ? _Count : _Extent - _Offset>;
323  return _ReturnType{data() + _Offset,
324  _Count == dynamic_extent ? size() - _Offset : _Count};
325  }
326 
327  _SYCL_SPAN_INLINE_VISIBILITY
328  constexpr span<element_type, dynamic_extent>
329  subspan(size_type __offset, size_type __count = dynamic_extent) const
330  noexcept {
331  _SYCL_SPAN_ASSERT(__offset <= size(),
332  "Offset out of range in span::subspan(offset, count)");
333  _SYCL_SPAN_ASSERT(__count <= size() || __count == dynamic_extent,
334  "Count out of range in span::subspan(offset, count)");
335  if (__count == dynamic_extent)
336  return {data() + __offset, size() - __offset};
337  _SYCL_SPAN_ASSERT(
338  __count <= size() - __offset,
339  "Offset + count out of range in span::subspan(offset, count)");
340  return {data() + __offset, __count};
341  }
342 
343  _SYCL_SPAN_INLINE_VISIBILITY constexpr size_type size() const noexcept {
344  return _Extent;
345  }
346  _SYCL_SPAN_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept {
347  return _Extent * sizeof(element_type);
348  }
349  _SYCL_SPAN_INLINE_VISIBILITY constexpr bool empty() const noexcept {
350  return _Extent == 0;
351  }
352 
353  _SYCL_SPAN_INLINE_VISIBILITY constexpr reference
354  operator[](size_type __idx) const noexcept {
355  _SYCL_SPAN_ASSERT(__idx < size(), "span<T,N>[] index out of bounds");
356  return __data[__idx];
357  }
358 
359  _SYCL_SPAN_INLINE_VISIBILITY constexpr reference front() const noexcept {
360  _SYCL_SPAN_ASSERT(!empty(), "span<T, N>::front() on empty span");
361  return __data[0];
362  }
363 
364  _SYCL_SPAN_INLINE_VISIBILITY constexpr reference back() const noexcept {
365  _SYCL_SPAN_ASSERT(!empty(), "span<T, N>::back() on empty span");
366  return __data[size() - 1];
367  }
368 
369  _SYCL_SPAN_INLINE_VISIBILITY constexpr pointer data() const noexcept {
370  return __data;
371  }
372 
373  // [span.iter], span iterator support
374  _SYCL_SPAN_INLINE_VISIBILITY constexpr iterator begin() const noexcept {
375  return iterator(data());
376  }
377  _SYCL_SPAN_INLINE_VISIBILITY constexpr iterator end() const noexcept {
378  return iterator(data() + size());
379  }
380  _SYCL_SPAN_INLINE_VISIBILITY constexpr rev_iterator rbegin() const noexcept {
381  return rev_iterator(end());
382  }
383  _SYCL_SPAN_INLINE_VISIBILITY constexpr rev_iterator rend() const noexcept {
384  return rev_iterator(begin());
385  }
386 
387  _SYCL_SPAN_INLINE_VISIBILITY span<const byte, _Extent * sizeof(element_type)>
388  __as_bytes() const noexcept {
389  return span<const byte, _Extent * sizeof(element_type)>{
390  reinterpret_cast<const byte *>(data()), size_bytes()};
391  }
392 
393  _SYCL_SPAN_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)>
394  __as_writable_bytes() const noexcept {
395  return span<byte, _Extent * sizeof(element_type)>{
396  reinterpret_cast<byte *>(data()), size_bytes()};
397  }
398 
399 private:
400  pointer __data;
401 };
402 
403 template <typename _Tp>
404 class _SYCL_SPAN_TEMPLATE_VIS span<_Tp, dynamic_extent> {
405 private:
406 public:
407  // constants and types
408  using element_type = _Tp;
409  using value_type = std::remove_cv_t<_Tp>;
410  using size_type = size_t;
411  using difference_type = ptrdiff_t;
412  using pointer = _Tp *;
413  using const_pointer = const _Tp *;
414  using reference = _Tp &;
415  using const_reference = const _Tp &;
416  using iterator = pointer;
417  using rev_iterator = std::reverse_iterator<pointer>;
418 
419  static constexpr size_type extent = dynamic_extent;
420 
421  // [span.cons], span constructors, copy, assignment, and destructor
422  _SYCL_SPAN_INLINE_VISIBILITY constexpr span() noexcept
423  : __data{nullptr}, __size{0} {}
424 
425  constexpr span(const span &) noexcept = default;
426  constexpr span &operator=(const span &) noexcept = default;
427 
428  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(pointer __ptr, size_type __count)
429  : __data{__ptr}, __size{__count} {}
430  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l)
431  : __data{__f}, __size{static_cast<size_t>(std::distance(__f, __l))} {}
432 
433  template <size_t _Sz>
434  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(
435  element_type (&__arr)[_Sz]) noexcept
436  : __data{__arr}, __size{_Sz} {}
437 
438  template <class _OtherElementType, size_t _Sz,
439  std::enable_if_t<std::is_convertible_v<_OtherElementType (*)[],
440  element_type (*)[]>,
441  std::nullptr_t> = nullptr>
442  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(
443  std::array<_OtherElementType, _Sz> &__arr) noexcept
444  : __data{__arr.data()}, __size{_Sz} {}
445 
446  template <
447  class _OtherElementType, size_t _Sz,
448  std::enable_if_t<std::is_convertible_v<const _OtherElementType (*)[],
449  element_type (*)[]>,
450  std::nullptr_t> = nullptr>
451  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(
452  const std::array<_OtherElementType, _Sz> &__arr) noexcept
453  : __data{__arr.data()}, __size{_Sz} {}
454 
455  template <class _Container>
456  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(
457  _Container &__c,
458  std::enable_if_t<__is_span_compatible_container<_Container, _Tp>::value,
459  std::nullptr_t> = nullptr)
460  : __data{std::data(__c)}, __size{(size_type)std::size(__c)} {}
461 
462  template <class _Container>
463  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(
464  const _Container &__c,
466  __is_span_compatible_container<const _Container, _Tp>::value,
467  std::nullptr_t> = nullptr)
468  : __data{std::data(__c)}, __size{(size_type)std::size(__c)} {}
469 
470  template <class _OtherElementType, size_t _OtherExtent>
471  _SYCL_SPAN_INLINE_VISIBILITY constexpr span(
472  const span<_OtherElementType, _OtherExtent> &__other,
474  std::is_convertible_v<_OtherElementType (*)[], element_type (*)[]>,
475  std::nullptr_t> = nullptr) noexcept
476  : __data{__other.data()}, __size{__other.size()} {}
477 
478  // ~span() noexcept = default;
479 
480  template <size_t _Count>
481  _SYCL_SPAN_INLINE_VISIBILITY constexpr span<element_type, _Count>
482  first() const noexcept {
483  _SYCL_SPAN_ASSERT(_Count <= size(), "Count out of range in span::first()");
484  return span<element_type, _Count>{data(), _Count};
485  }
486 
487  template <size_t _Count>
488  _SYCL_SPAN_INLINE_VISIBILITY constexpr span<element_type, _Count> last() const
489  noexcept {
490  _SYCL_SPAN_ASSERT(_Count <= size(), "Count out of range in span::last()");
491  return span<element_type, _Count>{data() + size() - _Count, _Count};
492  }
493 
494  _SYCL_SPAN_INLINE_VISIBILITY
495  constexpr span<element_type, dynamic_extent> first(size_type __count) const
496  noexcept {
497  _SYCL_SPAN_ASSERT(__count <= size(),
498  "Count out of range in span::first(count)");
499  return {data(), __count};
500  }
501 
502  _SYCL_SPAN_INLINE_VISIBILITY
503  constexpr span<element_type, dynamic_extent> last(size_type __count) const
504  noexcept {
505  _SYCL_SPAN_ASSERT(__count <= size(),
506  "Count out of range in span::last(count)");
507  return {data() + size() - __count, __count};
508  }
509 
510  template <size_t _Offset, size_t _Count = dynamic_extent>
511  _SYCL_SPAN_INLINE_VISIBILITY constexpr span<element_type, _Count>
512  subspan() const noexcept {
513  _SYCL_SPAN_ASSERT(_Offset <= size(),
514  "Offset out of range in span::subspan()");
515  _SYCL_SPAN_ASSERT(_Count == dynamic_extent || _Count <= size() - _Offset,
516  "Offset + count out of range in span::subspan()");
517  return span<element_type, _Count>{
518  data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
519  }
520 
521  constexpr span<element_type, dynamic_extent> _SYCL_SPAN_INLINE_VISIBILITY
522  subspan(size_type __offset, size_type __count = dynamic_extent) const
523  noexcept {
524  _SYCL_SPAN_ASSERT(__offset <= size(),
525  "Offset out of range in span::subspan(offset, count)");
526  _SYCL_SPAN_ASSERT(__count <= size() || __count == dynamic_extent,
527  "count out of range in span::subspan(offset, count)");
528  if (__count == dynamic_extent)
529  return {data() + __offset, size() - __offset};
530  _SYCL_SPAN_ASSERT(
531  __count <= size() - __offset,
532  "Offset + count out of range in span::subspan(offset, count)");
533  return {data() + __offset, __count};
534  }
535 
536  _SYCL_SPAN_INLINE_VISIBILITY constexpr size_type size() const noexcept {
537  return __size;
538  }
539  _SYCL_SPAN_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept {
540  return __size * sizeof(element_type);
541  }
542  _SYCL_SPAN_INLINE_VISIBILITY constexpr bool empty() const noexcept {
543  return __size == 0;
544  }
545 
546  _SYCL_SPAN_INLINE_VISIBILITY constexpr reference
547  operator[](size_type __idx) const noexcept {
548  _SYCL_SPAN_ASSERT(__idx < size(), "span<T>[] index out of bounds");
549  return __data[__idx];
550  }
551 
552  _SYCL_SPAN_INLINE_VISIBILITY constexpr reference front() const noexcept {
553  _SYCL_SPAN_ASSERT(!empty(), "span<T>[].front() on empty span");
554  return __data[0];
555  }
556 
557  _SYCL_SPAN_INLINE_VISIBILITY constexpr reference back() const noexcept {
558  _SYCL_SPAN_ASSERT(!empty(), "span<T>[].back() on empty span");
559  return __data[size() - 1];
560  }
561 
562  _SYCL_SPAN_INLINE_VISIBILITY constexpr pointer data() const noexcept {
563  return __data;
564  }
565 
566  // [span.iter], span iterator support
567  _SYCL_SPAN_INLINE_VISIBILITY constexpr iterator begin() const noexcept {
568  return iterator(data());
569  }
570  _SYCL_SPAN_INLINE_VISIBILITY constexpr iterator end() const noexcept {
571  return iterator(data() + size());
572  }
573  _SYCL_SPAN_INLINE_VISIBILITY constexpr rev_iterator rbegin() const noexcept {
574  return rev_iterator(end());
575  }
576  _SYCL_SPAN_INLINE_VISIBILITY constexpr rev_iterator rend() const noexcept {
577  return rev_iterator(begin());
578  }
579 
580  _SYCL_SPAN_INLINE_VISIBILITY span<const byte, dynamic_extent>
581  __as_bytes() const noexcept {
582  return {reinterpret_cast<const byte *>(data()), size_bytes()};
583  }
584 
585  _SYCL_SPAN_INLINE_VISIBILITY span<byte, dynamic_extent>
586  __as_writable_bytes() const noexcept {
587  return {reinterpret_cast<byte *>(data()), size_bytes()};
588  }
589 
590 private:
591  pointer __data;
592  size_type __size;
593 };
594 
595 // as_bytes & as_writable_bytes
596 template <class _Tp, size_t _Extent>
597 _SYCL_SPAN_INLINE_VISIBILITY auto as_bytes(span<_Tp, _Extent> __s) noexcept
598  -> decltype(__s.__as_bytes()) {
599  return __s.__as_bytes();
600 }
601 
602 template <class _Tp, size_t _Extent>
603 _SYCL_SPAN_INLINE_VISIBILITY auto
604 as_writable_bytes(span<_Tp, _Extent> __s) noexcept
605  -> std::enable_if_t<!std::is_const_v<_Tp>,
606  decltype(__s.__as_writable_bytes())> {
607  return __s.__as_writable_bytes();
608 }
609 
610 // Deduction guides
611 
612 // array arg deduction guide. dynamic_extent arg used to select
613 // the correct template. The _Sz will be used for the __size of the span.
614 template <class _Tp, size_t _Sz>
615 span(_Tp (&)[_Sz]) -> span<_Tp, dynamic_extent>;
616 
617 template <class _Tp, size_t _Sz> span(std::array<_Tp, _Sz> &)->span<_Tp, _Sz>;
618 
619 template <class _Tp, size_t _Sz>
620 span(const std::array<_Tp, _Sz> &)->span<const _Tp, _Sz>;
621 
622 template <class _Container>
623 span(_Container &)->span<typename _Container::value_type>;
624 
625 template <class _Container>
626 span(const _Container &)->span<const typename _Container::value_type>;
627 
628 } // namespace sycl
629 } // __SYCL_INLINE_NAMESPACE(cl)
630 
631 #endif // _SYCL_SPAN
632 
633 #endif // __cplusplus >= 201703L
cl::sycl::distance
float distance(T p0, T p1) __NOEXC
Definition: builtins.hpp:1011
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::void_t
void void_t
Definition: stl_type_traits.hpp:42
char
cl::sycl::byte
unsigned char byte
Definition: image.hpp:59
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
std
Definition: accessor.hpp:2617
cl::sycl::detail::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Definition: stl_type_traits.hpp:24
cl::sycl::ext::intel::detail::dynamic_extent
constexpr size_t dynamic_extent
Definition: matrix-aot-amx.hpp:50
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12