20 #include <type_traits>
23 inline namespace _V1 {
28 template <
typename ElementType, access::address_space Space>
38 template <
typename ElementType>
41 ElementType, access::address_space::constant_space>::type;
47 template <
typename ElementType, access::address_space Space>
52 typename multi_ptr<
const ElementType, Space,
58 template <
typename ElementType>
60 access::address_space::constant_space> {
62 ElementType, access::address_space::constant_space>::type;
69 template <
typename dataT,
int dimensions,
access::mode accessMode,
85 using decorated_type =
86 typename detail::DecoratedType<ElementType, Space>::type;
95 std::add_pointer_t<value_type>>;
97 std::add_lvalue_reference_t<value_type>>;
102 std::add_pointer_t<value_type>>);
104 std::add_lvalue_reference_t<value_type>>);
106 static_assert(DecorateAddress != access::decorated::legacy);
122 typename =
typename std::enable_if_t<
130 :
multi_ptr(detail::cast_AS<decorated_type *>(
131 Accessor.template get_multi_ptr<DecorateAddress>()
132 .get_decorated())) {}
138 typename =
typename std::enable_if_t<
143 "multi_ptr construction using target::local specialized "
144 "accessor is deprecated since SYCL 2020")
152 typename =
typename std::enable_if_t<
164 typename =
typename std::enable_if_t<
165 _Space == Space && Space == access::address_space::constant_space>>
167 "multi_ptr construction using target::constant_buffer specialized "
168 "accessor is deprecated since SYCL 2020")
190 typename RelayElementType = ElementType,
191 typename =
typename std::enable_if_t<
196 std::is_const_v<RelayElementType> &&
197 std::is_same_v<RelayElementType, ElementType>>>
201 : m_Pointer(detail::
cast_AS<decorated_type *>(
202 Accessor.template get_multi_ptr<DecorateAddress>()
209 typename RelayElementType = ElementType,
210 typename =
typename std::enable_if_t<
214 std::is_const_v<RelayElementType> &&
215 std::is_same_v<RelayElementType, ElementType>>>
217 "multi_ptr construction using target::local specialized "
218 "accessor is deprecated since SYCL 2020")
226 typename RelayElementType = ElementType,
227 typename =
typename std::enable_if_t<
231 std::is_const_v<RelayElementType> &&
232 std::is_same_v<RelayElementType, ElementType>>>
234 local_accessor<
typename std::remove_const_t<RelayElementType>,
Dimensions>
246 typename RelayElementType = ElementType,
247 typename =
typename std::enable_if_t<
248 _Space == Space && Space == access::address_space::constant_space &&
249 std::is_const_v<RelayElementType> &&
250 std::is_same_v<RelayElementType, ElementType>>>
252 "multi_ptr construction using target::constant_buffer specialized "
253 "accessor is deprecated since SYCL 2020")
272 OtherSpace != access::address_space::constant_space>>
275 m_Pointer = detail::cast_AS<decorated_type *>(Other.
get_decorated());
282 OtherSpace != access::address_space::constant_space>>
285 m_Pointer = detail::cast_AS<decorated_type *>(std::move(Other.m_Pointer));
293 pointer get()
const {
return detail::cast_AS<pointer>(m_Pointer); }
295 std::add_pointer_t<value_type>
get_raw()
const {
296 return reinterpret_cast<std::add_pointer_t<value_type>
>(
get());
300 "2020. Please use get() instead.")
306 typename =
typename std::enable_if_t<
322 typename RelayElementType = ElementType,
324 typename =
typename std::enable_if_t<
325 std::is_same_v<RelayElementType, ElementType> &&
326 !std::is_const_v<RelayElementType> &&
RelaySpace == Space &&
340 typename RelayElementType = ElementType,
341 typename =
typename std::enable_if_t<
342 std::is_same_v<RelayElementType, ElementType> &&
343 !std::is_const_v<RelayElementType>>>
351 typename RelayElementType = ElementType,
352 typename =
typename std::enable_if_t<
353 std::is_same_v<RelayElementType, ElementType> &&
354 std::is_const_v<RelayElementType>>>
361 template <access::decorated ConvIsDecorated>
382 typename =
typename std::enable_if_t<
390 typename multi_ptr<ElementType, GlobalSpace,
399 typename =
typename std::enable_if_t<
402 size_t NumBytes = NumElements *
sizeof(ElementType);
442 decorated_type *m_Pointer;
446 template <access::address_space Space, access::decorated DecorateAddress>
449 using decorated_type =
459 std::add_pointer_t<value_type>>;
463 std::add_pointer_t<value_type>>);
465 static_assert(DecorateAddress != access::decorated::legacy);
482 typename =
typename std::enable_if_t<
490 :
multi_ptr(detail::cast_AS<decorated_type *>(
491 Accessor.template get_multi_ptr<DecorateAddress>()
492 .get_decorated())) {}
499 typename =
typename std::enable_if_t<
502 "multi_ptr construction using target::local specialized "
503 "accessor is deprecated since SYCL 2020")
512 typename =
typename std::enable_if_t<
522 typename ElementType,
int dimensions,
typename PropertyListT,
524 typename =
typename std::enable_if_t<
525 _Space == Space && Space == access::address_space::constant_space>>
527 "multi_ptr construction using target::constant_buffer specialized "
528 "accessor is deprecated since SYCL 2020")
544 pointer get()
const {
return detail::cast_AS<pointer>(m_Pointer); }
548 "2020. Please use get() instead.")
552 template <
typename ElementType,
553 typename =
typename std::enable_if_t<std::is_const_v<ElementType>>>
575 typename =
typename std::enable_if_t<
583 typename multi_ptr<
const void, GlobalSpace,
586 detail::cast_AS<global_pointer_t>(m_Pointer));
590 decorated_type *m_Pointer;
594 template <access::address_space Space, access::decorated DecorateAddress>
597 using decorated_type =
typename detail::DecoratedType<void, Space>::type;
600 static constexpr
bool is_decorated =
605 using pointer = std::conditional_t<is_decorated, decorated_type *,
606 std::add_pointer_t<value_type>>;
610 std::add_pointer_t<value_type>>);
612 static_assert(DecorateAddress != access::decorated::legacy);
614 static_assert(Space != access::address_space::constant_space,
615 "SYCL 2020 multi_ptr does not support the deprecated "
616 "constant_space address space.");
633 typename =
typename std::enable_if_t<
634 RelaySpace == Space &&
641 :
multi_ptr(detail::cast_AS<decorated_type *>(
642 Accessor.template get_multi_ptr<DecorateAddress>()
643 .get_decorated())) {}
650 typename =
typename std::enable_if_t<
653 "multi_ptr construction using target::local specialized "
654 "accessor is deprecated since SYCL 2020")
663 typename =
typename std::enable_if_t<
664 RelaySpace == Space &&
668 :
multi_ptr(Accessor.template get_multi_ptr<DecorateAddress>()
673 typename ElementType,
int dimensions,
typename PropertyListT,
675 typename =
typename std::enable_if_t<
676 _Space == Space && Space == access::address_space::constant_space>>
678 "multi_ptr construction using target::constant_buffer specialized "
679 "accessor is deprecated since SYCL 2020")
684 :
multi_ptr(Accessor.template get_multi_ptr<DecorateAddress>()
695 pointer get()
const {
return detail::cast_AS<pointer>(m_Pointer); }
699 "2020. Please use get() instead.")
703 template <
typename ElementType>
725 typename =
typename std::enable_if_t<
726 RelaySpace == Space &&
734 detail::cast_AS<global_pointer_t>(m_Pointer));
738 decorated_type *m_Pointer;
743 template <
typename ElementType, access::address_space Space>
745 "decorated::legacy multi_ptr specialization is deprecated since SYCL 2020.")
748 using value_type = ElementType;
750 std::conditional_t<std::is_same_v<ElementType, half>,
764 typename detail::LegacyReferenceTypes<ElementType,
773 #ifdef __SYCL_DEVICE_ONLY__
779 typename =
typename std::enable_if_t<
789 #if defined(RESTRICT_WRITE_ACCESS_TO_CONSTANT_PTR)
790 template <
typename =
typename detail::const_if_const_AS<Space, ElementType>>
802 #ifdef __SYCL_DEVICE_ONLY__
808 typename =
typename std::enable_if_t<
819 m_Pointer = detail::cast_AS<pointer_t>(pointer);
829 using ReturnRef = detail::const_if_const_AS<Space, ElementType> &;
833 return *
reinterpret_cast<ReturnPtr>(m_Pointer);
837 return reinterpret_cast<ReturnPtr>(m_Pointer);
841 return reinterpret_cast<ReturnPtr>(m_Pointer)[index];
845 return reinterpret_cast<ReturnPtr>(m_Pointer)[index];
853 typename =
typename std::enable_if_t<
861 :
multi_ptr(detail::cast_AS<pointer_t>(Accessor.get_pointer().get())) {}
867 typename =
typename std::enable_if_t<
876 template <
int dimensions>
884 typename =
typename std::enable_if_t<
885 _Space == Space && Space == access::address_space::constant_space>>
907 typename ET = ElementType,
908 typename =
typename std::enable_if_t<
913 std::is_const_v<ET> && std::is_same_v<ET, ElementType>>>
923 typename =
typename std::enable_if_t<
927 std::is_const_v<ET> && std::is_same_v<ET, ElementType>>>
935 typename ET = ElementType,
936 typename =
typename std::enable_if_t<
940 std::is_const_v<ET> && std::is_same_v<ET, ElementType>>>
942 local_accessor<
typename std::remove_const_t<ET>, dimensions> Accessor)
949 typename ET = ElementType,
950 typename =
typename std::enable_if_t<
951 _Space == Space && Space == access::address_space::constant_space &&
952 std::is_const_v<ET> && std::is_same_v<ET, ElementType>>>
966 template <
typename ET = ElementType>
968 std::is_const_v<ET> && std::is_same_v<ET, ElementType>,
969 const multi_ptr<
typename std::remove_const_t<ET>, Space,
970 access::decorated::legacy>> &ETP)
971 : m_Pointer(ETP.
get()) {}
976 std::add_pointer_t<element_type>
get_raw()
const {
977 return reinterpret_cast<std::add_pointer_t<element_type>
>(
get());
985 template <
typename ET = ElementType>
987 typename std::enable_if_t<
988 std::is_same_v<ET, ElementType> && !std::is_const_v<ET>,
void>::type,
989 Space, access::decorated::legacy>()
const {
990 using ptr_t =
typename detail::DecoratedType<void, Space> *;
992 reinterpret_cast<ptr_t
>(m_Pointer));
997 template <
typename ET = ElementType>
998 operator multi_ptr<
typename std::enable_if_t<
999 std::is_same_v<ET, ElementType> && std::is_const_v<ET>,
1001 Space, access::decorated::legacy>()
const {
1002 using ptr_t =
typename detail::DecoratedType<const void, Space> *;
1003 return multi_ptr<const void, Space, access::decorated::legacy>(
1004 reinterpret_cast<ptr_t
>(m_Pointer));
1014 reinterpret_cast<ptr_t
>(m_Pointer));
1051 #ifdef __ENABLE_USM_ADDR_SPACE__
1057 typename =
typename std::enable_if_t<
1062 access::decorated::legacy>()
const {
1066 access::decorated::legacy>(
1069 #endif // __ENABLE_USM_ADDR_SPACE__
1074 typename =
typename std::enable_if_t<
1077 size_t NumBytes = NumElements *
sizeof(ElementType);
1088 template <access::address_space Space>
1091 multi_ptr<void, Space, access::decorated::legacy> {
1093 using value_type = void;
1110 #ifdef __SYCL_DEVICE_ONLY__
1113 typename = std::enable_if_t<std::is_same_v<RelayPointerT, pointer_t> &&
1114 !std::is_same_v<RelayPointerT, void *>>>
1119 #if defined(RESTRICT_WRITE_ACCESS_TO_CONSTANT_PTR)
1120 template <
typename =
typename detail::const_if_const_AS<Space,
void>>
1125 multi_ptr(std::nullptr_t) : m_Pointer(nullptr) {}
1133 template <
typename ElementType>
1134 multi_ptr(
const multi_ptr<ElementType, Space, access::decorated::legacy> &ETP)
1135 : m_Pointer(ETP.
get()) {}
1141 m_Pointer = pointer;
1144 #ifdef __SYCL_DEVICE_ONLY__
1147 typename = std::enable_if_t<std::is_same_v<RelayPointerT, pointer_t> &&
1148 !std::is_same_v<RelayPointerT, void *>>>
1152 m_Pointer = detail::cast_AS<pointer_t>(pointer);
1157 m_Pointer =
nullptr;
1164 typename ElementType,
int dimensions,
access::mode Mode,
1166 typename =
typename std::enable_if_t<
1178 typename ElementType,
int dimensions,
access::mode Mode,
1180 typename =
typename std::enable_if_t<
1190 typename ElementType,
int dimensions,
1192 typename =
typename std::enable_if_t<
1195 multi_ptr(local_accessor<ElementType, dimensions> Accessor)
1200 typename ElementType,
int dimensions,
access::mode Mode,
1202 typename =
typename std::enable_if_t<
1203 _Space == Space && Space == access::address_space::constant_space>>
1209 using ReturnPtr = detail::const_if_const_AS<Space, void> *;
1213 std::add_pointer_t<element_type>
get_raw()
const {
1214 return reinterpret_cast<std::add_pointer_t<element_type>
>(
get());
1221 template <
typename ElementType>
1223 operator multi_ptr<ElementType, Space, access::decorated::legacy>()
const {
1224 using elem_pointer_t =
1225 typename detail::DecoratedType<ElementType, Space>::type *;
1226 return multi_ptr<ElementType, Space, access::decorated::legacy>(
1227 static_cast<elem_pointer_t
>(m_Pointer));
1231 operator multi_ptr<const void, Space, access::decorated::legacy>()
const {
1232 using ptr_t =
typename detail::DecoratedType<const void, Space>::type *;
1233 return multi_ptr<const void, Space, access::decorated::legacy>(
1234 reinterpret_cast<ptr_t
>(m_Pointer));
1243 template <access::address_space Space>
1246 multi_ptr<const void, Space, access::decorated::legacy> {
1248 using value_type =
const void;
1266 #ifdef __SYCL_DEVICE_ONLY__
1269 typename = std::enable_if_t<std::is_same_v<RelayPointerT, pointer_t> &&
1270 !std::is_same_v<RelayPointerT, const void *>>>
1276 #if defined(RESTRICT_WRITE_ACCESS_TO_CONSTANT_PTR)
1277 template <
typename =
typename detail::const_if_const_AS<Space,
void>>
1282 multi_ptr(std::nullptr_t) : m_Pointer(nullptr) {}
1290 template <
typename ElementType>
1291 multi_ptr(
const multi_ptr<ElementType, Space, access::decorated::legacy> &ETP)
1292 : m_Pointer(ETP.
get()) {}
1298 m_Pointer = pointer;
1301 #ifdef __SYCL_DEVICE_ONLY__
1304 typename = std::enable_if_t<std::is_same_v<RelayPointerT, pointer_t> &&
1305 !std::is_same_v<RelayPointerT, const void *>>>
1309 m_Pointer = detail::cast_AS<pointer_t>(pointer);
1314 m_Pointer =
nullptr;
1321 typename ElementType,
int dimensions,
access::mode Mode,
1323 typename =
typename std::enable_if_t<
1335 typename ElementType,
int dimensions,
access::mode Mode,
1337 typename =
typename std::enable_if_t<
1347 typename ElementType,
int dimensions,
1349 typename =
typename std::enable_if_t<
1352 multi_ptr(local_accessor<ElementType, dimensions> Accessor)
1357 typename ElementType,
int dimensions,
access::mode Mode,
1359 typename =
typename std::enable_if_t<
1360 _Space == Space && Space == access::address_space::constant_space>>
1369 std::add_pointer_t<element_type>
get_raw()
const {
1370 return reinterpret_cast<std::add_pointer_t<element_type>
>(
get());
1374 operator const void *()
const {
1375 return reinterpret_cast<const void *
>(m_Pointer);
1382 template <
typename ElementType>
1384 operator multi_ptr<const ElementType, Space, access::decorated::legacy>()
1386 using elem_pointer_t =
1387 typename detail::DecoratedType<const ElementType, Space>::type *;
1388 return multi_ptr<const ElementType, Space, access::decorated::legacy>(
1389 static_cast<elem_pointer_t
>(m_Pointer));
1396 #ifdef __cpp_deduction_guides
1407 -> multi_ptr<T, access::address_space::global_space, access::decorated::no>;
1412 -> multi_ptr<T, access::address_space::global_space, access::decorated::no>;
1417 ->
multi_ptr<
const T, access::address_space::constant_space,
1422 accessor<T, dimensions, Mode, target::local, isPlaceholder, PropertyListT>)
1423 -> multi_ptr<T, access::address_space::local_space, access::decorated::no>;
1424 template <
typename T,
int dimensions>
1425 multi_ptr(local_accessor<T, dimensions>)
1426 -> multi_ptr<T, access::address_space::local_space, access::decorated::no>;
1430 typename ElementType>
1431 multi_ptr<ElementType, Space, DecorateAddress>
1432 address_space_cast(ElementType *pointer) {
1436 return multi_ptr<ElementType, Space, DecorateAddress>(
1445 typename = std::enable_if_t<DecorateAddress == access::decorated::legacy>>
1447 "address_space_cast instead.")
1448 multi_ptr<ElementType, Space, DecorateAddress> make_ptr(
1457 typename = std::enable_if_t<DecorateAddress != access::decorated::legacy>>
1459 "address_space_cast instead.")
1460 multi_ptr<ElementType, Space, DecorateAddress> make_ptr(
1461 typename
multi_ptr<ElementType, Space, DecorateAddress>::pointer pointer) {
1462 return address_space_cast<Space, DecorateAddress>(pointer);
1465 #ifdef __SYCL_DEVICE_ONLY__
1472 "address_space_cast instead.")
1473 multi_ptr<ElementType, Space, DecorateAddress> make_ptr(ElementType *pointer) {
1474 return address_space_cast<Space, DecorateAddress>(pointer);
1476 #if defined(RESTRICT_WRITE_ACCESS_TO_CONSTANT_PTR)
1479 typename =
typename detail::const_if_const_AS<Space, ElementType>>
1481 "address_space_cast instead.")
1482 multi_ptr<ElementType, Space, DecorateAddress> make_ptr(
1483 const ElementType *pointer) {
1484 return multi_ptr<ElementType, Space, DecorateAddress>(pointer);
1486 #endif // RESTRICT_WRITE_ACCESS_TO_CONSTANT_PTR
1487 #endif // // __SYCL_DEVICE_ONLY__
1491 bool operator==(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1492 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1493 return lhs.get() == rhs.get();
1498 bool operator!=(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1499 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1500 return lhs.get() != rhs.get();
1505 bool operator<(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1506 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1507 return lhs.get() < rhs.get();
1512 bool operator>(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1513 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1514 return lhs.get() > rhs.get();
1519 bool operator<=(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1520 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1521 return lhs.get() <= rhs.get();
1526 bool operator>=(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1527 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1528 return lhs.get() >= rhs.get();
1533 bool operator!=(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1535 return lhs.get() !=
nullptr;
1541 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1542 return rhs.get() !=
nullptr;
1547 bool operator==(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1549 return lhs.get() ==
nullptr;
1555 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1556 return rhs.get() ==
nullptr;
1561 bool operator>(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1563 return lhs.get() !=
nullptr;
1568 bool operator>(std::nullptr_t,
1569 const multi_ptr<ElementType, Space, DecorateAddress> &) {
1575 bool operator<(
const multi_ptr<ElementType, Space, DecorateAddress> &,
1582 bool operator<(std::nullptr_t,
1583 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1584 return rhs.get() !=
nullptr;
1589 bool operator>=(
const multi_ptr<ElementType, Space, DecorateAddress> &,
1596 bool operator>=(std::nullptr_t,
1597 const multi_ptr<ElementType, Space, DecorateAddress> &rhs) {
1598 return rhs.get() ==
nullptr;
1603 bool operator<=(
const multi_ptr<ElementType, Space, DecorateAddress> &lhs,
1605 return lhs.get() ==
nullptr;
1610 bool operator<=(std::nullptr_t,
1611 const multi_ptr<ElementType, Space, DecorateAddress> &) {