Skip to content

Commit

Permalink
Generalize the approach, introduce _ONEDPL_GENERIC_SYCL_LIBRARY macro
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriy-sobolev committed Dec 6, 2024
1 parent f5892fe commit 24571ce
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ enum class __peer_prefix_algo
template <std::uint32_t __radix_states, typename _OffsetT, __peer_prefix_algo _Algo>
struct __peer_prefix_helper;

#define _ONEDPL_SYCL2020_SUBGROUP_BARRIER_PRESENT _ONEDPL_LIBSYCL_ZERO_OR_GE(50700)
#define _ONEDPL_SYCL2020_SUBGROUP_BARRIER_PRESENT (_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50700)

#if _ONEDPL_SYCL2020_SUBGROUP_BARRIER_PRESENT
template <std::uint32_t __radix_states, typename _OffsetT>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ __supports_sub_group_size(const _ExecutionPolicy& __exec, std::size_t __target_s

// 20201214 value corresponds to Intel(R) oneAPI C++ Compiler Classic 2021.1.2 Patch release
#define _ONEDPL_SYCL2020_KERNEL_DEVICE_API_PRESENT \
(__SYCL_COMPILER_VERSION > 20201214 || _ONEDPL_LIBSYCL_ZERO_OR_GE(50700))
(_ONEDPL_GENERIC_SYCL_LIBRARY || __SYCL_COMPILER_VERSION > 20201214 || _ONEDPL_LIBSYCL_VERSION >= 50700)

template <typename _ExecutionPolicy>
::std::size_t
Expand Down
65 changes: 35 additions & 30 deletions include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@
#if defined(__LIBSYCL_MAJOR_VERSION) && defined(__LIBSYCL_MINOR_VERSION) && defined(__LIBSYCL_PATCH_VERSION)
# define _ONEDPL_LIBSYCL_VERSION \
(__LIBSYCL_MAJOR_VERSION * 10000 + __LIBSYCL_MINOR_VERSION * 100 + __LIBSYCL_PATCH_VERSION)
#else
# define _ONEDPL_LIBSYCL_VERSION 0
#endif
#define _ONEDPL_LIBSYCL_ZERO_OR_GE(_ONEDPL_LIBSYCL_VERSION) \
(_ONEDPL_LIBSYCL_VERSION >= _ONEDPL_LIBSYCL_VERSION || _ONEDPL_LIBSYCL_VERSION == 0)
#if !defined(_ONEDPL_LIBSYCL_VERSION)
# define _ONEDPL_GENERIC_SYCL_LIBRARY 1
#endif
#if _ONEDPL_FPGA_DEVICE
# if _ONEDPL_LIBSYCL_VERSION >= 50400
Expand All @@ -54,26 +53,32 @@
#endif
// Macros to check the new SYCL features
#define _ONEDPL_SYCL2020_NO_INIT_PRESENT _ONEDPL_LIBSYCL_ZERO_OR_GE(50300)
#define _ONEDPL_SYCL2020_KERNEL_BUNDLE_PRESENT _ONEDPL_LIBSYCL_ZERO_OR_GE(50300)
#define _ONEDPL_SYCL2020_COLLECTIVES_PRESENT _ONEDPL_LIBSYCL_ZERO_OR_GE(50300)
#define _ONEDPL_SYCL2020_KNOWN_IDENTITY_PRESENT _ONEDPL_LIBSYCL_ZERO_OR_GE(50300)
#define _ONEDPL_SYCL2020_FUNCTIONAL_OBJECTS_PRESENT _ONEDPL_LIBSYCL_ZERO_OR_GE(50300)
#define _ONEDPL_SYCL2020_ATOMIC_REF_PRESENT _ONEDPL_LIBSYCL_ZERO_OR_GE(50500)
#define _ONEDPL_SYCL2020_PLACEHOLDER_HOST_ACCESSOR_DEPRECATED _ONEDPL_LIBSYCL_ZERO_OR_GE(60200)
#define _ONEDPL_LIBSYCL_SUB_GROUP_MASK_PRESENT (SYCL_EXT_ONEAPI_SUB_GROUP_MASK >= 1) && \
(_ONEDPL_LIBSYCL_VERSION >= 50700)
#define _ONEDPL_SYCL2020_NO_INIT_PRESENT \
(_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50300)
#define _ONEDPL_SYCL2020_KERNEL_BUNDLE_PRESENT \
(_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50300)
#define _ONEDPL_SYCL2020_COLLECTIVES_PRESENT \
(_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50300)
#define _ONEDPL_SYCL2020_KNOWN_IDENTITY_PRESENT \
(_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50300)
#define _ONEDPL_SYCL2020_FUNCTIONAL_OBJECTS_PRESENT \
(_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50300)
#define _ONEDPL_SYCL2020_ATOMIC_REF_PRESENT \
(_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50500)
#define _ONEDPL_SYCL2020_SUB_GROUP_PRESENT \
(_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50700)
#define _ONEDPL_SYCL2020_PLACEHOLDER_HOST_ACCESSOR_DEPRECATED \
(_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 60200)
#define _ONEDPL_LIBSYCL_SUB_GROUP_MASK_PRESENT (_ONEDPL_LIBSYCL_VERSION >= 50700)
#define _ONEDPL_LIBSYCL_KNOWN_IDENTITY_PRESENT (_ONEDPL_LIBSYCL_VERSION == 50200)
#define _ONEDPL_SYCL_DEVICE_COPYABLE_SPECIALIZATION_BROKEN \
(_ONEDPL_LIBSYCL_VERSION < 70100) && (_ONEDPL_LIBSYCL_VERSION != 0)
#define _ONEDPL_SYCL_DEVICE_COPYABLE_SPECIALIZATION_BROKEN (_ONEDPL_LIBSYCL_VERSION < 70100)
// TODO: determine which compiler configurations provide subgroup load/store
#define _ONEDPL_SYCL_SUB_GROUP_LOAD_STORE_PRESENT false
#define _ONEDPL_SYCL2020_SUB_GROUP_PRESENT _ONEDPL_LIBSYCL_ZERO_OR_GE(50700)
// Macro to check if we are compiling for SPIR-V devices. This macro must only be used within
// SYCL kernels for determining SPIR-V compilation. Using this macro on the host may lead to incorrect behavior.
#ifndef _ONEDPL_DETECT_SPIRV_COMPILATION // Check if overridden for testing
Expand All @@ -84,7 +89,7 @@
# endif
#endif // _ONEDPL_DETECT_SPIRV_COMPILATION
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(50300)
#if _ONEDPL_LIBSYCL_VERSION >= 50300 || _ONEDPL_GENERIC_SYCL_LIBRARY
# define _ONEDPL_SYCL_REQD_SUB_GROUP_SIZE(SIZE) sycl::reqd_sub_group_size(SIZE)
#else
# define _ONEDPL_SYCL_REQD_SUB_GROUP_SIZE(SIZE) intel::reqd_sub_group_size(SIZE)
Expand All @@ -101,7 +106,7 @@
// The unified future supporting USM memory and buffers is only supported after DPCPP 2023.1
// but not by 2023.2.
#if (_ONEDPL_LIBSYCL_ZERO_OR_GE(60100) && _ONEDPL_LIBSYCL_VERSION != 60200)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || (_ONEDPL_LIBSYCL_VERSION >= 50300 && _ONEDPL_LIBSYCL_VERSION != 60200)
# define _ONEDPL_SYCL_UNIFIED_USM_BUFFER_PRESENT 1
#else
# define _ONEDPL_SYCL_UNIFIED_USM_BUFFER_PRESENT 0
Expand Down Expand Up @@ -165,7 +170,7 @@ template <typename _Buffer>
constexpr auto
__get_buffer_size(const _Buffer& __buffer)
{
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(50300)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50300
return __buffer.size();
#else
return __buffer.get_count();
Expand All @@ -176,7 +181,7 @@ template <typename _Accessor>
constexpr auto
__get_accessor_size(const _Accessor& __accessor)
{
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(50300)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50300
return __accessor.size();
#else
return __accessor.get_count();
Expand All @@ -187,7 +192,7 @@ template <typename _Item>
constexpr void
__group_barrier(_Item __item)
{
#if 0 //_ONEDPL_LIBSYCL_ZERO_OR_GE(50300)
#if 0 //_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50300
//TODO: usage of sycl::group_barrier: probably, we have to revise SYCL parallel patterns which use a group_barrier.
// 1) sycl::group_barrier() implementation is not ready
// 2) sycl::group_barrier and sycl::item::group_barrier are not quite equivalent
Expand Down Expand Up @@ -373,29 +378,29 @@ inline auto __fpga_selector()
#endif // _ONEDPL_FPGA_DEVICE
using __target =
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(50400)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50400
sycl::target;
#else
sycl::access::target;
#endif
constexpr __target __target_device =
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(50400)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50400
__target::device;
#else
__target::global_buffer;
#endif
constexpr __target __host_target =
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(60200)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 60200
__target::host_task;
#else
__target::host_buffer;
#endif
template <typename _DataT>
using __buffer_allocator =
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(60000)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 60000
sycl::buffer_allocator<_DataT>;
#else
sycl::buffer_allocator;
Expand All @@ -414,7 +419,7 @@ struct __atomic_ref : sycl::atomic<_AtomicType, _Space>
template <typename _DataT, int _Dimensions = 1>
using __local_accessor =
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(60000)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 60000
sycl::local_accessor<_DataT, _Dimensions>;
#else
sycl::accessor<_DataT, _Dimensions, sycl::access::mode::read_write, __dpl_sycl::__target::local>;
Expand All @@ -424,7 +429,7 @@ template <typename _Buf>
auto
__get_host_access(_Buf&& __buf)
{
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(60200)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 60200
return ::std::forward<_Buf>(__buf).get_host_access(sycl::read_only);
#else
return ::std::forward<_Buf>(__buf).template get_access<sycl::access::mode::read>();
Expand All @@ -435,7 +440,7 @@ template <typename _Acc>
auto
__get_accessor_ptr(const _Acc& __acc)
{
#if _ONEDPL_LIBSYCL_ZERO_OR_GE(70000)
#if _ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 70000
return __acc.template get_multi_ptr<sycl::access::decorated::no>().get();
#else
return __acc.get_pointer();
Expand Down
2 changes: 1 addition & 1 deletion include/oneapi/dpl/pstl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ __dpl_bit_cast(const _Src& __src) noexcept
{
#if __cpp_lib_bit_cast >= 201806L
return ::std::bit_cast<_Dst>(__src);
#elif _ONEDPL_BACKEND_SYCL && (_ONEDPL_LIBSYCL_VERSION >= 50300 || _ONEDPL_LIBSYCL_VERSION == 0)
#elif _ONEDPL_BACKEND_SYCL && (_ONEDPL_GENERIC_SYCL_LIBRARY || _ONEDPL_LIBSYCL_VERSION >= 50300)
return sycl::bit_cast<_Dst>(__src);
#elif __has_builtin(__builtin_bit_cast)
return __builtin_bit_cast(_Dst, __src);
Expand Down

0 comments on commit 24571ce

Please sign in to comment.