Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SYCL backend detection more portable #1881

Merged
merged 30 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3df0848
Do not expect a genetic compiler to define SYCL_LANGUAGE_VERSION
dmitriy-sobolev Oct 4, 2024
3d2c931
Align the approach with the review suggestions
dmitriy-sobolev Oct 14, 2024
ebda341
Try include sycl.hpp, refactor
dmitriy-sobolev Oct 18, 2024
1ddec1c
Adjust tests_config according to hetero_backend_config
dmitriy-sobolev Oct 18, 2024
f9c4cc7
Add hetero_backend_config.h
dmitriy-sobolev Oct 18, 2024
b57dd63
Add symmetric undef
dmitriy-sobolev Oct 21, 2024
556ce51
Add a set of safe configurations to include SYCL
dmitriy-sobolev Oct 21, 2024
24d7182
Spelling
dmitriy-sobolev Oct 21, 2024
1d59f08
clang-format
dmitriy-sobolev Oct 21, 2024
aeb1863
Unify logic for dpcpp compilers
dmitriy-sobolev Oct 21, 2024
85d7c67
Small fix
dmitriy-sobolev Oct 21, 2024
b2ba8d7
Remove _ONEDPL_HETERO_BACKEND hack in test_config
dmitriy-sobolev Oct 22, 2024
85c82ef
Comment clarifications
dmitriy-sobolev Oct 22, 2024
420269e
Fix for acpp
dmitriy-sobolev Oct 22, 2024
41aec8c
Fix possible case
dmitriy-sobolev Oct 22, 2024
95f19ba
Get rid of heter_backend_config.h
dmitriy-sobolev Oct 24, 2024
58b7d92
Prepend missing _ONEDPL to some macros, rearrange macros
dmitriy-sobolev Oct 25, 2024
be1568c
Get rid of DPCPP compiler check, move the error into sycl_defs.h
dmitriy-sobolev Nov 6, 2024
cae7bb6
Adjust documentation
dmitriy-sobolev Nov 7, 2024
e260551
Bullet list -> plain text for cohesiveness
dmitriy-sobolev Nov 7, 2024
0fece8a
Get rid of implementaiton details in the documentation
dmitriy-sobolev Nov 7, 2024
0de5e95
Add a note for usage of disabled policies
dmitriy-sobolev Nov 7, 2024
a0fa36d
Move USE_RADIX sort closer to the useage place
dmitriy-sobolev Nov 7, 2024
c51e2a9
Correct a comment about absence of SYCL_LANGUAGE_VERSION
dmitriy-sobolev Nov 7, 2024
07479d7
Simplify documentation
dmitriy-sobolev Nov 7, 2024
580f3d1
Simplify SYCL backend enablement
dmitriy-sobolev Nov 7, 2024
b644e81
Return a check in sycl_defs.h
dmitriy-sobolev Nov 7, 2024
f91a5ba
clang-format
dmitriy-sobolev Nov 7, 2024
70cf886
Simplify macros more
dmitriy-sobolev Nov 7, 2024
3284e95
Add comments after #endif
dmitriy-sobolev Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 105 additions & 55 deletions include/oneapi/dpl/pstl/onedpl_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,11 @@
#ifndef _ONEDPL_CONFIG_H
#define _ONEDPL_CONFIG_H

#include "../internal/version_impl.h"
// The version header also defines a few configuration macros used in this file
#include "../internal/version_impl.h"

#if defined(ONEDPL_FPGA_DEVICE)
# undef _ONEDPL_FPGA_DEVICE
# define _ONEDPL_FPGA_DEVICE ONEDPL_FPGA_DEVICE
#endif

#if defined(ONEDPL_FPGA_EMULATOR)
# undef _ONEDPL_FPGA_EMU
# define _ONEDPL_FPGA_EMU ONEDPL_FPGA_EMULATOR
#endif

#if defined(ONEDPL_USE_PREDEFINED_POLICIES)
# undef _ONEDPL_PREDEFINED_POLICIES
# define _ONEDPL_PREDEFINED_POLICIES ONEDPL_USE_PREDEFINED_POLICIES
#elif !defined(_ONEDPL_PREDEFINED_POLICIES)
# define _ONEDPL_PREDEFINED_POLICIES 1
#endif
// -- Check availability of parallel backends --

// Check availability of parallel backends
#if __has_include(<tbb/tbb.h>)
# define _ONEDPL_TBB_AVAILABLE 1
#endif
Expand All @@ -54,15 +38,71 @@
but OpenMP headers are not found or the compiler does not support OpenMP"
#endif

#if (defined(SYCL_LANGUAGE_VERSION) || defined(CL_SYCL_LANGUAGE_VERSION)) && \
(__has_include(<sycl/sycl.hpp>) || __has_include(<CL/sycl.hpp>))
# define _ONEDPL_SYCL_AVAILABLE 1
// -- Check availability of heterogeneous backends --

// Detect both Intel(R) oneAPI DPC++/C++ Compiler and oneAPI DPC++ compiler
// Rely on an extension attribute, which is present in both compilers
// A predefined macro cannot be used since oneAPI DPC++/C++ Compiler provides the same set of macros as Clang
#if __has_cpp_attribute(intel::kernel_args_restrict)
# define _ONEDPL_DPCPP_COMPILER 1
#else
# define _ONEDPL_DPCPP_COMPILER 0
#endif
akukanov marked this conversation as resolved.
Show resolved Hide resolved

// Preliminary check SYCL availability
#define _ONEDPL_SYCL_HEADER_PRESENT (__has_include(<sycl/sycl.hpp>) || __has_include(<CL/sycl.hpp>))
#define _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT (SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION)
#if _ONEDPL_SYCL_HEADER_PRESENT
# if _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT
# define _ONEDPL_SYCL_AVAILABLE 1
// DPC++/C++ Compilers pre-define SYCL_LANGUAGE_VERSION with -fsycl option
# elif !_ONEDPL_DPCPP_COMPILER
// Other implementations might define the macro in the SYCL header
# define _ONEDPL_SYCL_POSSIBLY_AVAILABLE 1
# endif
#endif

// Include SYCL headers for "possible" case with reliable configurations only
// Even if the headers are available, their inclusion may be dangerous if the compiler does not support SYCL
#if defined(__ADAPTIVECPP__)
# define _ONEDPL_SAFE_TO_INCLUDE_SYCL 1
#else
# define _ONEDPL_SAFE_TO_INCLUDE_SYCL 0
#endif
// Try checking SYCL_LANGUAGE_VERSION after sycl.hpp inclusion if SYCL availability has not been proven yet
// Proceed to inclusion only if it is safe or the backend was explicitly requested
#if _ONEDPL_SYCL_POSSIBLY_AVAILABLE && (ONEDPL_USE_DPCPP_BACKEND || _ONEDPL_SAFE_TO_INCLUDE_SYCL)
# if __has_include(<sycl/sycl.hpp>)
# include <sycl/sycl.hpp>
# else
# include <CL/sycl.hpp>
# endif
# if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION)
# define _ONEDPL_SYCL_AVAILABLE 1
# endif
akukanov marked this conversation as resolved.
Show resolved Hide resolved
#endif // _ONEDPL_SYCL_POSSIBLY_AVAILABLE

// If DPCPP backend is explicitly requested and SYCL is not available, throw an error
#if ONEDPL_USE_DPCPP_BACKEND && !_ONEDPL_SYCL_AVAILABLE
# error "Device execution policies are enabled, \
but SYCL* headers are not found or the compiler does not support SYCL"
but SYCL* headers are not found or the SYCL implementation does not define SYCL_LANGUAGE_VERSION macro"
#endif

// If DPCPP backend is not explicitly turned off and SYCL is available, enable it
#if (ONEDPL_USE_DPCPP_BACKEND || !defined(ONEDPL_USE_DPCPP_BACKEND)) && _ONEDPL_SYCL_AVAILABLE
# define _ONEDPL_BACKEND_SYCL 1
#endif

// If at least one heterogeneous backend is available, enable them
#if _ONEDPL_BACKEND_SYCL
# if _ONEDPL_HETERO_BACKEND
# undef _ONEDPL_HETERO_BACKEND
# endif
# define _ONEDPL_HETERO_BACKEND 1
#endif

// -- Configure host backends and common parts --

// Check the user-defined macro for warnings
#if !defined(_PSTL_USAGE_WARNINGS) && defined(PSTL_USAGE_WARNINGS)
# define _PSTL_USAGE_WARNINGS PSTL_USAGE_WARNINGS
Expand Down Expand Up @@ -252,37 +292,6 @@
#define _ONEDPL_HAS_NUMERIC_SERIAL_IMPL \
(__GLIBCXX__ && (_GLIBCXX_RELEASE < 9 || (_GLIBCXX_RELEASE == 9 && __GLIBCXX__ < 20200312)))

#if ONEDPL_USE_DPCPP_BACKEND || (!defined(ONEDPL_USE_DPCPP_BACKEND) && _ONEDPL_SYCL_AVAILABLE)
# define _ONEDPL_BACKEND_SYCL 1
#endif

// if SYCL policy switch on then let's switch hetero policy macro on
#if _ONEDPL_BACKEND_SYCL
# if _ONEDPL_HETERO_BACKEND
# undef _ONEDPL_HETERO_BACKEND
# endif
# define _ONEDPL_HETERO_BACKEND 1
// Include sycl specific options
// FPGA doesn't support sub-groups
# if !(_ONEDPL_FPGA_DEVICE)
# define _USE_SUB_GROUPS 1
# define _USE_GROUP_ALGOS 1
# endif

# define _USE_RADIX_SORT (_USE_SUB_GROUPS && _USE_GROUP_ALGOS)

// Compilation of a kernel is requiried to obtain valid work_group_size
// when target devices are CPU or FPGA emulator. Since CPU and GPU devices
// cannot be distinguished during compilation, the macro is enabled by default.
# if !defined(_ONEDPL_COMPILE_KERNEL)
# define _ONEDPL_COMPILE_KERNEL 1
# endif
#endif

#if !defined(ONEDPL_ALLOW_DEFERRED_WAITING)
# define ONEDPL_ALLOW_DEFERRED_WAITING 0
#endif

//'present' macros
// shift_left, shift_right; GCC 10; VS 2019 16.1
#define _ONEDPL_CPP20_SHIFT_LEFT_RIGHT_PRESENT \
Expand Down Expand Up @@ -311,8 +320,6 @@
# define _ONEDPL_CPP20_REQUIRES(req)
#endif

#define _ONEDPL_BUILT_IN_STABLE_NAME_PRESENT __has_builtin(__builtin_sycl_unique_stable_name)

#if defined(_MSC_VER) && __INTEL_LLVM_COMPILER < 20240100
# define _ONEDPL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN 1
#else
Expand All @@ -333,4 +340,47 @@
# define _ONEDPL_STD_RANGES_ALGO_CPP_FUN 0
#endif

// -- Configure heterogeneous backends --

#if defined(ONEDPL_FPGA_DEVICE)
# undef _ONEDPL_FPGA_DEVICE
# define _ONEDPL_FPGA_DEVICE ONEDPL_FPGA_DEVICE
#endif

#if !defined(ONEDPL_ALLOW_DEFERRED_WAITING)
# define ONEDPL_ALLOW_DEFERRED_WAITING 0
#endif

#if defined(ONEDPL_FPGA_EMULATOR)
# undef _ONEDPL_FPGA_EMU
# define _ONEDPL_FPGA_EMU ONEDPL_FPGA_EMULATOR
#endif

#if defined(ONEDPL_USE_PREDEFINED_POLICIES)
# undef _ONEDPL_PREDEFINED_POLICIES
# define _ONEDPL_PREDEFINED_POLICIES ONEDPL_USE_PREDEFINED_POLICIES
#elif !defined(_ONEDPL_PREDEFINED_POLICIES)
# define _ONEDPL_PREDEFINED_POLICIES 1
#endif

dmitriy-sobolev marked this conversation as resolved.
Show resolved Hide resolved
#if _ONEDPL_BACKEND_SYCL
// Include sycl specific options
// FPGA doesn't support sub-groups
# if !(_ONEDPL_FPGA_DEVICE)
# define _USE_SUB_GROUPS 1
# define _USE_GROUP_ALGOS 1
# endif

# define _USE_RADIX_SORT (_USE_SUB_GROUPS && _USE_GROUP_ALGOS)
dmitriy-sobolev marked this conversation as resolved.
Show resolved Hide resolved

// Compilation of a kernel is requiried to obtain valid work_group_size
// when target devices are CPU or FPGA emulator. Since CPU and GPU devices
// cannot be distinguished during compilation, the macro is enabled by default.
# if !defined(_ONEDPL_COMPILE_KERNEL)
# define _ONEDPL_COMPILE_KERNEL 1
# endif
akukanov marked this conversation as resolved.
Show resolved Hide resolved

# define _ONEDPL_BUILT_IN_STABLE_NAME_PRESENT __has_builtin(__builtin_sycl_unique_stable_name)
#endif // _ONEDPL_BACKEND_SYCL

#endif // _ONEDPL_CONFIG_H
21 changes: 14 additions & 7 deletions test/support/test_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//
// This section contains macros representing the "Latest" version of compilers, STL implementations, etc. for use in
// broken macros to represent the latest version of something which still has an ongoing issue. The intention is to
// update this section regularly to reflect the latest version.
// update this section regularly to reflect the latest version.
//
// When such an issue is fixed, we must replace the usage of these "Latest" macros with the appropriate version number
// before updating to the newest version in this section.
Expand Down Expand Up @@ -88,13 +88,20 @@

#define _PSTL_SYCL_TEST_USM 1

// Enable test when the DPC++ backend is available
#if ((defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION)) && \
(__has_include(<sycl/sycl.hpp>) || __has_include(<CL/sycl.hpp>))) && \
(!defined(ONEDPL_USE_DPCPP_BACKEND) || ONEDPL_USE_DPCPP_BACKEND != 0)
#define TEST_DPCPP_BACKEND_PRESENT 1
#define TEST_SYCL_HEADER_PRESENT (__has_include(<sycl/sycl.hpp>) || __has_include(<CL/sycl.hpp>))
#define TEST_SYCL_LANGUAGE_VERSION_PRESENT (SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION)
#define TEST_SYCL_AVAILABLE (TEST_SYCL_HEADER_PRESENT && TEST_SYCL_LANGUAGE_VERSION_PRESENT)

// If SYCL is available, and DPCPP backend is not explicitly turned off, enable its testing
#if TEST_SYCL_AVAILABLE && !defined(ONEDPL_USE_DPCPP_BACKEND)
# define TEST_DPCPP_BACKEND_PRESENT 1
// If DPCPP backend was explicitly requested, enable its testing, even if SYCL availability has not been proven
// this can be used to force DPCPP backend testing for environments where SYCL_LANGUAGE_VERSION is not predefined
#elif ONEDPL_USE_DPCPP_BACKEND
# define TEST_DPCPP_BACKEND_PRESENT 1
// Define to 0 in other cases since some tests may rely at the macro value at runtime
#else
#define TEST_DPCPP_BACKEND_PRESENT 0
# define TEST_DPCPP_BACKEND_PRESENT 0
#endif

#ifdef __SYCL_UNNAMED_LAMBDA__
Expand Down
Loading