|
11 | 11 | #include <sycl/detail/defines_elementary.hpp> // for __SYCL2020_DEPRECATED |
12 | 12 |
|
13 | 13 | #ifdef __SYCL_DEVICE_ONLY__ |
14 | | -#include <sycl/__spirv/spirv_ops.hpp> |
15 | 14 | #include <type_traits> |
16 | 15 | #endif |
17 | 16 |
|
@@ -319,123 +318,6 @@ template <typename T> struct remove_decoration<const T &> { |
319 | 318 | template <typename T> |
320 | 319 | using remove_decoration_t = typename remove_decoration<T>::type; |
321 | 320 |
|
322 | | -namespace detail { |
323 | | -#ifdef __SYCL_DEVICE_ONLY__ |
324 | | -inline constexpr bool |
325 | | -address_space_cast_is_possible(access::address_space Src, |
326 | | - access::address_space Dst) { |
327 | | - // constant_space is unique and is not interchangeable with any other. |
328 | | - auto constant_space = access::address_space::constant_space; |
329 | | - if (Src == constant_space || Dst == constant_space) |
330 | | - return Src == Dst; |
331 | | - |
332 | | - auto generic_space = access::address_space::generic_space; |
333 | | - if (Src == Dst || Src == generic_space || Dst == generic_space) |
334 | | - return true; |
335 | | - |
336 | | - // global_host/global_device could be casted to/from global |
337 | | - auto global_space = access::address_space::global_space; |
338 | | - auto global_device = access::address_space::ext_intel_global_device_space; |
339 | | - auto global_host = access::address_space::ext_intel_global_host_space; |
340 | | - |
341 | | - if (Src == global_space || Dst == global_space) { |
342 | | - auto Other = Src == global_space ? Dst : Src; |
343 | | - if (Other == global_device || Other == global_host) |
344 | | - return true; |
345 | | - } |
346 | | - |
347 | | - // No more compatible combinations. |
348 | | - return false; |
349 | | -} |
350 | | - |
351 | | -template <access::address_space Space, typename ElementType> |
352 | | -auto static_address_cast(ElementType *Ptr) { |
353 | | - constexpr auto SrcAS = deduce_AS<ElementType *>::value; |
354 | | - static_assert(address_space_cast_is_possible(SrcAS, Space)); |
355 | | - |
356 | | - using dst_type = typename DecoratedType< |
357 | | - std::remove_pointer_t<remove_decoration_t<ElementType *>>, Space>::type *; |
358 | | - |
359 | | - // Note: reinterpret_cast isn't enough for some of the casts between different |
360 | | - // address spaces, use C-style cast instead. |
361 | | - return (dst_type)Ptr; |
362 | | -} |
363 | | - |
364 | | -// Previous implementation (`castAS`, used in `multi_ptr` ctors among other |
365 | | -// places), used C-style cast instead of a proper dynamic check for some |
366 | | -// backends/spaces. `SupressNotImplementedAssert = true` parameter is emulating |
367 | | -// that previous behavior until the proper support is added for compatibility |
368 | | -// reasons. |
369 | | -template <access::address_space Space, bool SupressNotImplementedAssert = false, |
370 | | - typename ElementType> |
371 | | -auto dynamic_address_cast(ElementType *Ptr) { |
372 | | - constexpr auto generic_space = access::address_space::generic_space; |
373 | | - constexpr auto global_space = access::address_space::global_space; |
374 | | - constexpr auto local_space = access::address_space::local_space; |
375 | | - constexpr auto private_space = access::address_space::private_space; |
376 | | - constexpr auto global_device = |
377 | | - access::address_space::ext_intel_global_device_space; |
378 | | - constexpr auto global_host = |
379 | | - access::address_space::ext_intel_global_host_space; |
380 | | - |
381 | | - constexpr auto SrcAS = deduce_AS<ElementType *>::value; |
382 | | - using dst_type = typename DecoratedType< |
383 | | - std::remove_pointer_t<remove_decoration_t<ElementType *>>, Space>::type *; |
384 | | - using RemoveCvT = std::remove_cv_t<ElementType>; |
385 | | - |
386 | | - if constexpr (!address_space_cast_is_possible(SrcAS, Space)) { |
387 | | - return (dst_type) nullptr; |
388 | | - } else if constexpr (Space == generic_space) { |
389 | | - return (dst_type)Ptr; |
390 | | - } else if constexpr (Space == global_space && |
391 | | - (SrcAS == global_device || SrcAS == global_host)) { |
392 | | - return (dst_type)Ptr; |
393 | | - } else if constexpr (SrcAS == global_space && |
394 | | - (Space == global_device || Space == global_host)) { |
395 | | -#if defined(__ENABLE_USM_ADDR_SPACE__) |
396 | | - static_assert(SupressNotImplementedAssert || Space != Space, |
397 | | - "Not supported yet!"); |
398 | | - return detail::static_address_cast<Space>(Ptr); |
399 | | -#else |
400 | | - // If __ENABLE_USM_ADDR_SPACE__ isn't defined then both |
401 | | - // global_device/global_host are just aliases for global_space. |
402 | | - static_assert(std::is_same_v<dst_type, ElementType *>); |
403 | | - return (dst_type)Ptr; |
404 | | -#endif |
405 | | - } else if constexpr (Space == global_space) { |
406 | | - return (dst_type)__spirv_GenericCastToPtrExplicit_ToGlobal( |
407 | | - const_cast<RemoveCvT *>(Ptr), __spv::StorageClass::CrossWorkgroup); |
408 | | - } else if constexpr (Space == local_space) { |
409 | | - return (dst_type)__spirv_GenericCastToPtrExplicit_ToLocal( |
410 | | - const_cast<RemoveCvT *>(Ptr), __spv::StorageClass::Workgroup); |
411 | | - } else if constexpr (Space == private_space) { |
412 | | - return (dst_type)__spirv_GenericCastToPtrExplicit_ToPrivate( |
413 | | - const_cast<RemoveCvT *>(Ptr), __spv::StorageClass::Function); |
414 | | -#if !defined(__ENABLE_USM_ADDR_SPACE__) |
415 | | - } else if constexpr (SrcAS == generic_space && |
416 | | - (Space == global_device || Space == global_host)) { |
417 | | - return (dst_type)__spirv_GenericCastToPtrExplicit_ToGlobal( |
418 | | - const_cast<RemoveCvT *>(Ptr), __spv::StorageClass::CrossWorkgroup); |
419 | | -#endif |
420 | | - } else { |
421 | | - static_assert(SupressNotImplementedAssert || Space != Space, |
422 | | - "Not supported yet!"); |
423 | | - return detail::static_address_cast<Space>(Ptr); |
424 | | - } |
425 | | -} |
426 | | -#else // __SYCL_DEVICE_ONLY__ |
427 | | -template <access::address_space Space, typename ElementType> |
428 | | -auto static_address_cast(ElementType *Ptr) { |
429 | | - return Ptr; |
430 | | -} |
431 | | -template <access::address_space Space, bool SupressNotImplementedAssert = false, |
432 | | - typename ElementType> |
433 | | -auto dynamic_address_cast(ElementType *Ptr) { |
434 | | - return Ptr; |
435 | | -} |
436 | | -#endif // __SYCL_DEVICE_ONLY__ |
437 | | -} // namespace detail |
438 | | - |
439 | 321 | #undef __OPENCL_GLOBAL_AS__ |
440 | 322 | #undef __OPENCL_GLOBAL_DEVICE_AS__ |
441 | 323 | #undef __OPENCL_GLOBAL_HOST_AS__ |
|
0 commit comments