From 3df08482f81cdf090b76efa10ba2d6ff68077bbd Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Fri, 4 Oct 2024 09:11:06 -0500 Subject: [PATCH 01/30] Do not expect a genetic compiler to define SYCL_LANGUAGE_VERSION Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/onedpl_config.h | 12 +++++++++--- test/support/test_config.h | 11 +++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 2ef13c46f83..23dbbcb43aa 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -54,9 +54,15 @@ 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() || __has_include()) -# define _ONEDPL_SYCL_AVAILABLE 1 +#if defined(__INTEL_LLVM_COMPILER) && (defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION)) +# define _ONEDPL_SYCL_ENABLED_FOR_INTEL_LLVM 1 +#endif +#if (__has_include() || __has_include()) +// Intel(R) oneAPI DPC++/C++ Compiler is known to provide SYCL_LANGUAGE_VERSION with certain compiler options, +// while other implementations may require inclusion of sycl/sycl.hpp, which is not desired in onedpl_config.h +# if _ONEDPL_SYCL_ENABLED_FOR_INTEL_LLVM || !defined(__INTEL_LLVM_COMPILER) +# define _ONEDPL_SYCL_AVAILABLE 1 +# endif #endif #if ONEDPL_USE_DPCPP_BACKEND && !_ONEDPL_SYCL_AVAILABLE # error "Device execution policies are enabled, \ diff --git a/test/support/test_config.h b/test/support/test_config.h index 5814a4a4a07..d4813656466 100644 --- a/test/support/test_config.h +++ b/test/support/test_config.h @@ -89,12 +89,15 @@ #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() || __has_include())) && \ +#if defined(__INTEL_LLVM_COMPILER) && (defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION)) +# define TEST_SYCL_ENABLED_FOR_INTEL_LLVM 1 +#endif +#if __has_include() || __has_include() && \ + (TEST_SYCL_ENABLED_FOR_INTEL_LLVM || !defined(__INTEL_LLVM_COMPILER)) && \ (!defined(ONEDPL_USE_DPCPP_BACKEND) || ONEDPL_USE_DPCPP_BACKEND != 0) -#define TEST_DPCPP_BACKEND_PRESENT 1 +# define TEST_DPCPP_BACKEND_PRESENT 1 #else -#define TEST_DPCPP_BACKEND_PRESENT 0 +# define TEST_DPCPP_BACKEND_PRESENT 0 #endif #ifdef __SYCL_UNNAMED_LAMBDA__ From 3d2c931f46addc0716bc831c7f57a98bdf511c23 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Mon, 14 Oct 2024 11:45:31 -0500 Subject: [PATCH 02/30] Align the approach with the review suggestions Signed-off-by: Dmitriy Sobolev --- CMakeLists.txt | 1 + include/oneapi/dpl/pstl/onedpl_config.h | 36 ++++++++++++++++--------- test/support/test_config.h | 30 ++++++++++++++------- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9742ae33a3f..190de1701b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -301,6 +301,7 @@ if (ONEDPL_BACKEND MATCHES "^(tbb|dpcpp|dpcpp_only)$") target_compile_definitions(oneDPL INTERFACE $<$,$>:ONEDPL_FPGA_DEVICE> $<$:ONEDPL_FPGA_EMULATOR> + ONEDPL_USE_DPCPP_BACKEND=1 ) # DPC++ specific link options diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 23dbbcb43aa..e10dd9dd088 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -54,20 +54,34 @@ but OpenMP headers are not found or the compiler does not support OpenMP" #endif -#if defined(__INTEL_LLVM_COMPILER) && (defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION)) -# define _ONEDPL_SYCL_ENABLED_FOR_INTEL_LLVM 1 -#endif +// Preliminary check SYCL availability #if (__has_include() || __has_include()) -// Intel(R) oneAPI DPC++/C++ Compiler is known to provide SYCL_LANGUAGE_VERSION with certain compiler options, -// while other implementations may require inclusion of sycl/sycl.hpp, which is not desired in onedpl_config.h -# if _ONEDPL_SYCL_ENABLED_FOR_INTEL_LLVM || !defined(__INTEL_LLVM_COMPILER) -# define _ONEDPL_SYCL_AVAILABLE 1 -# endif +# define _ONEDPL_SYCL_HEADER_PRESENT 1 +#endif +#if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) +# define _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT 1 +#endif +#if _ONEDPL_SYCL_HEADER_PRESENT && _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT +# define _ONEDPL_SYCL_AVAILABLE 1 #endif -#if ONEDPL_USE_DPCPP_BACKEND && !_ONEDPL_SYCL_AVAILABLE +// Intel(R) oneAPI DPC++/C++ Compiler provides SYCL_LANGUAGE_VERSION without sycl.hpp inclusion +#if _ONEDPL_SYCL_HEADER_PRESENT && !_ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT && !defined(__INTEL_LLVM_COMPILER) +# define _ONEDPL_SYCL_POSSIBLY_AVAILABLE 1 +#endif + +// If DPCPP backend is explicitly requested and SYCL is (possibly) available, enable it +#if ONEDPL_USE_DPCPP_BACKEND && (_ONEDPL_SYCL_AVAILABLE || _ONEDPL_SYCL_POSSIBLY_AVAILABLE) +# define _ONEDPL_BACKEND_SYCL 1 +#endif +// If DPCPP backend is explicitly requested and SYCL is definitely not available, throw an error +#if ONEDPL_USE_DPCPP_BACKEND && !(_ONEDPL_SYCL_AVAILABLE || _ONEDPL_SYCL_POSSIBLY_AVAILABLE) # error "Device execution policies are enabled, \ but SYCL* headers are not found or the compiler does not support SYCL" #endif +// If DPCPP backend is not requested explicitly and SYCL is definitely available, enable it +#if !defined(ONEDPL_USE_DPCPP_BACKEND) && _ONEDPL_SYCL_AVAILABLE +# define _ONEDPL_BACKEND_SYCL 1 +#endif // Check the user-defined macro for warnings #if !defined(_PSTL_USAGE_WARNINGS) && defined(PSTL_USAGE_WARNINGS) @@ -258,10 +272,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 diff --git a/test/support/test_config.h b/test/support/test_config.h index d4813656466..d85301b2270 100644 --- a/test/support/test_config.h +++ b/test/support/test_config.h @@ -88,16 +88,28 @@ #define _PSTL_SYCL_TEST_USM 1 -// Enable test when the DPC++ backend is available -#if defined(__INTEL_LLVM_COMPILER) && (defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION)) -# define TEST_SYCL_ENABLED_FOR_INTEL_LLVM 1 +// If DPCPP is requested, enable its testing +#if ONEDPL_USE_DPCPP_BACKEND +# define TEST_DPCPP_BACKEND_PRESENT 1 #endif -#if __has_include() || __has_include() && \ - (TEST_SYCL_ENABLED_FOR_INTEL_LLVM || !defined(__INTEL_LLVM_COMPILER)) && \ - (!defined(ONEDPL_USE_DPCPP_BACKEND) || ONEDPL_USE_DPCPP_BACKEND != 0) -# define TEST_DPCPP_BACKEND_PRESENT 1 -#else -# define TEST_DPCPP_BACKEND_PRESENT 0 + +// If DPCPP backend is not explicitly requested, repeat oneDPL behavior +// which enables DPCPP backend when SYCL is definitely available +#if (__has_include() || __has_include()) +# define TEST_SYCL_HEADER_PRESENT 1 +#endif +#if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) +# define TEST_SYCL_LANGUAGE_VERSION_PRESENT 1 +#endif +#if TEST_SYCL_HEADER_PRESENT && TEST_SYCL_LANGUAGE_VERSION_PRESENT +# define TEST_SYCL_AVAILABLE 1 +#endif +#if !defined(ONEDPL_USE_DPCPP_BACKEND) && TEST_SYCL_AVAILABLE +# define TEST_DPCPP_BACKEND_PRESENT 1 +#endif + +#if !defined(TEST_DPCPP_BACKEND_PRESENT) +# define TEST_DPCPP_BACKEND_PRESENT 0 #endif #ifdef __SYCL_UNNAMED_LAMBDA__ From ebda341125023a0532cbd71b2982c7855f9c3dcd Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Fri, 18 Oct 2024 12:55:37 -0500 Subject: [PATCH 03/30] Try include sycl.hpp, refactor Move hetero backend configuration into a separate file Signed-off-by: Dmitriy Sobolev --- CMakeLists.txt | 1 - include/oneapi/dpl/pstl/onedpl_config.h | 78 +------------------------ 2 files changed, 3 insertions(+), 76 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 190de1701b0..9742ae33a3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -301,7 +301,6 @@ if (ONEDPL_BACKEND MATCHES "^(tbb|dpcpp|dpcpp_only)$") target_compile_definitions(oneDPL INTERFACE $<$,$>:ONEDPL_FPGA_DEVICE> $<$:ONEDPL_FPGA_EMULATOR> - ONEDPL_USE_DPCPP_BACKEND=1 ) # DPC++ specific link options diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index e10dd9dd088..6d904e0d7c5 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -16,25 +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 the heterogenous backends, configure if available +#include "oneapi/dpl/pstl/hetero_backend_config.h" // Check availability of parallel backends #if __has_include() @@ -54,35 +40,6 @@ but OpenMP headers are not found or the compiler does not support OpenMP" #endif -// Preliminary check SYCL availability -#if (__has_include() || __has_include()) -# define _ONEDPL_SYCL_HEADER_PRESENT 1 -#endif -#if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) -# define _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT 1 -#endif -#if _ONEDPL_SYCL_HEADER_PRESENT && _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT -# define _ONEDPL_SYCL_AVAILABLE 1 -#endif -// Intel(R) oneAPI DPC++/C++ Compiler provides SYCL_LANGUAGE_VERSION without sycl.hpp inclusion -#if _ONEDPL_SYCL_HEADER_PRESENT && !_ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT && !defined(__INTEL_LLVM_COMPILER) -# define _ONEDPL_SYCL_POSSIBLY_AVAILABLE 1 -#endif - -// If DPCPP backend is explicitly requested and SYCL is (possibly) available, enable it -#if ONEDPL_USE_DPCPP_BACKEND && (_ONEDPL_SYCL_AVAILABLE || _ONEDPL_SYCL_POSSIBLY_AVAILABLE) -# define _ONEDPL_BACKEND_SYCL 1 -#endif -// If DPCPP backend is explicitly requested and SYCL is definitely not available, throw an error -#if ONEDPL_USE_DPCPP_BACKEND && !(_ONEDPL_SYCL_AVAILABLE || _ONEDPL_SYCL_POSSIBLY_AVAILABLE) -# error "Device execution policies are enabled, \ - but SYCL* headers are not found or the compiler does not support SYCL" -#endif -// If DPCPP backend is not requested explicitly and SYCL is definitely available, enable it -#if !defined(ONEDPL_USE_DPCPP_BACKEND) && _ONEDPL_SYCL_AVAILABLE -# define _ONEDPL_BACKEND_SYCL 1 -#endif - // Check the user-defined macro for warnings #if !defined(_PSTL_USAGE_WARNINGS) && defined(PSTL_USAGE_WARNINGS) # define _PSTL_USAGE_WARNINGS PSTL_USAGE_WARNINGS @@ -272,33 +229,6 @@ #define _ONEDPL_HAS_NUMERIC_SERIAL_IMPL \ (__GLIBCXX__ && (_GLIBCXX_RELEASE < 9 || (_GLIBCXX_RELEASE == 9 && __GLIBCXX__ < 20200312))) -// 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 \ @@ -327,8 +257,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 From 1ddec1c84b786f29ad39d7741f0fe9dd10fc03a0 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Fri, 18 Oct 2024 14:29:24 -0500 Subject: [PATCH 04/30] Adjust tests_config according to hetero_backend_config Signed-off-by: Dmitriy Sobolev --- test/support/test_config.h | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/test/support/test_config.h b/test/support/test_config.h index d85301b2270..e2b1d7c1484 100644 --- a/test/support/test_config.h +++ b/test/support/test_config.h @@ -91,25 +91,13 @@ // If DPCPP is requested, enable its testing #if ONEDPL_USE_DPCPP_BACKEND # define TEST_DPCPP_BACKEND_PRESENT 1 -#endif - -// If DPCPP backend is not explicitly requested, repeat oneDPL behavior -// which enables DPCPP backend when SYCL is definitely available -#if (__has_include() || __has_include()) -# define TEST_SYCL_HEADER_PRESENT 1 -#endif -#if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) -# define TEST_SYCL_LANGUAGE_VERSION_PRESENT 1 -#endif -#if TEST_SYCL_HEADER_PRESENT && TEST_SYCL_LANGUAGE_VERSION_PRESENT -# define TEST_SYCL_AVAILABLE 1 -#endif -#if !defined(ONEDPL_USE_DPCPP_BACKEND) && TEST_SYCL_AVAILABLE -# define TEST_DPCPP_BACKEND_PRESENT 1 -#endif - -#if !defined(TEST_DPCPP_BACKEND_PRESENT) +#elif !defined(ONEDPL_USE_DPCPP_BACKEND) # define TEST_DPCPP_BACKEND_PRESENT 0 +#else +// Hack: delayed expansion based on _ONEDPL_HETERO_BACKEND, defined in oneDPL +// TODO: avoid the hack by moving TEST_DPCPP_BACKEND_PRESENT into separate header and including after oneDPL headers +// this will require to update all tests to include the new header +# define TEST_DPCPP_BACKEND_PRESENT (_ONEDPL_HETERO_BACKEND) #endif #ifdef __SYCL_UNNAMED_LAMBDA__ From f9c4cc7d276bd944a5a1c4132b6106224ed5738c Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Fri, 18 Oct 2024 14:30:59 -0500 Subject: [PATCH 05/30] Add hetero_backend_config.h Signed-off-by: Dmitriy Sobolev --- .../oneapi/dpl/pstl/hetero_backend_config.h | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100755 include/oneapi/dpl/pstl/hetero_backend_config.h diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h new file mode 100755 index 00000000000..04989275f15 --- /dev/null +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -0,0 +1,120 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Copyright (C) Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// This file incorporates work covered by the following copyright and permission +// notice: +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// +//===----------------------------------------------------------------------===// + +// This header checks for heterogeneous backend availability, and configures them if available + +#ifndef _ONEDPL_HETERO_BACKEND_CONFIG +#define _ONEDPL_HETERO_BACKEND_CONFIG + +// -------------------------------------------------------------------------------------------------------------------- +// Enablement of heterogeneous backends +// -------------------------------------------------------------------------------------------------------------------- + +// Preliminary check SYCL availability +#define _ONEDPL_SYCL_HEADER_PRESENT (__has_include() || __has_include()) +#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 +// Intel(R) oneAPI DPC++/C++ Compiler pre-defines SYCL_LANGUAGE_VERSION with -fsycl option +# elif !defined(__INTEL_LLVM_COMPILER) +// Other implementations might define the macro in the SYCL header +# define _ONEDPL_SYCL_POSSIBLY_AVAILABLE 1 +# endif +#endif + +// If DPCPP backend is not explicitly turned off and SYCL is definitely available, enable it +#if (ONEDPL_USE_DPCPP_BACKEND || !defined(ONEDPL_USE_DPCPP_BACKEND)) && _ONEDPL_SYCL_AVAILABLE +# define _ONEDPL_BACKEND_SYCL 1 +#endif + +// Try checking SYCL_LANGUAGE_VERSION after sycl.hpp inclusion if SYCL availability has not been proven yet +#if defined(_ONEDPL_SYCL_POSSIBLY_AVAILABLE) +# if __has_include() +# include +# else +# include +# endif +# if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) +# define _ONEDPL_BACKEND_SYCL 1 +# endif +#endif // _ONEDPL_SYCL_POSSIBLY_AVAILABLE + +// If DPCPP backend is explicitly requested and SYCL is definitely 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" +#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 +#else +# define _ONEDPL_HETERO_BACKEND 0 +#endif + +// -------------------------------------------------------------------------------------------------------------------- +// Configuration of 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 + +// -------------------------------------------------------------------------------------------------------------------- +// Configuration of SYCL heterogeneous backend +// -------------------------------------------------------------------------------------------------------------------- + +#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) + +// 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 + +# define _ONEDPL_BUILT_IN_STABLE_NAME_PRESENT __has_builtin(__builtin_sycl_unique_stable_name) +#endif // _ONEDPL_BACKEND_SYCL + +#endif // _ONEDPL_HETERO_BACKEND_CONFIG From b57dd637e1883c4d04280e174cbf2b6e54494fde Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Mon, 21 Oct 2024 09:40:42 +0100 Subject: [PATCH 06/30] Add symmetric undef Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero_backend_config.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index 04989275f15..8b5c8d55925 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -65,6 +65,9 @@ # endif # define _ONEDPL_HETERO_BACKEND 1 #else +# if _ONEDPL_HETERO_BACKEND +# undef _ONEDPL_HETERO_BACKEND +# endif # define _ONEDPL_HETERO_BACKEND 0 #endif From 556ce51f06179ac742d430e0860f8ec0da3f2aa9 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Mon, 21 Oct 2024 11:15:40 +0100 Subject: [PATCH 07/30] Add a set of safe configurations to include SYCL Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero_backend_config.h | 8 +++++++- include/oneapi/dpl/pstl/onedpl_config.h | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index 8b5c8d55925..510d53109f6 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -41,7 +41,13 @@ #endif // Try checking SYCL_LANGUAGE_VERSION after sycl.hpp inclusion if SYCL availability has not been proven yet -#if defined(_ONEDPL_SYCL_POSSIBLY_AVAILABLE) +// Include SYCL headers for relyable configurations only, the set can be extended in the future +#if defined(__ADAPTIVECPP__) +# define _ONEDPL_SAFE_TO_INCLUDE_SYCL 1 +#else +# define _ONEDPL_SAFE_TO_INCLUDE_SYCL 0 +#endif +#if defined(_ONEDPL_SYCL_POSSIBLY_AVAILABLE) && _ONEDPL_SAFE_TO_INCLUDE_SYCL # if __has_include() # include # else diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 6d904e0d7c5..955564f98de 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -19,9 +19,6 @@ // The version header also defines a few configuration macros used in this file #include "../internal/version_impl.h" -// Check availability of the heterogenous backends, configure if available -#include "oneapi/dpl/pstl/hetero_backend_config.h" - // Check availability of parallel backends #if __has_include() # define _ONEDPL_TBB_AVAILABLE 1 @@ -277,4 +274,7 @@ # define _ONEDPL_STD_RANGES_ALGO_CPP_FUN 0 #endif +// Check availability of the heterogenous backends, configure if available +#include "oneapi/dpl/pstl/hetero_backend_config.h" + #endif // _ONEDPL_CONFIG_H From 24d718295f73a88538cc667c7e2f42ba5eed7e2e Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Mon, 21 Oct 2024 11:32:37 +0100 Subject: [PATCH 08/30] Spelling Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero_backend_config.h | 2 +- include/oneapi/dpl/pstl/onedpl_config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index 510d53109f6..17d78ad99d4 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -41,7 +41,7 @@ #endif // Try checking SYCL_LANGUAGE_VERSION after sycl.hpp inclusion if SYCL availability has not been proven yet -// Include SYCL headers for relyable configurations only, the set can be extended in the future +// Include SYCL headers for reliable configurations only, the set can be extended in the future #if defined(__ADAPTIVECPP__) # define _ONEDPL_SAFE_TO_INCLUDE_SYCL 1 #else diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 955564f98de..4bd31093e58 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -274,7 +274,7 @@ # define _ONEDPL_STD_RANGES_ALGO_CPP_FUN 0 #endif -// Check availability of the heterogenous backends, configure if available +// Check availability of the heterogeneous backends, configure if available #include "oneapi/dpl/pstl/hetero_backend_config.h" #endif // _ONEDPL_CONFIG_H From 1d59f08ad84a0e869413130eb233b4900c8f0250 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Mon, 21 Oct 2024 11:33:37 +0100 Subject: [PATCH 09/30] clang-format Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero_backend_config.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index 17d78ad99d4..06630584cc9 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -26,13 +26,13 @@ #define _ONEDPL_SYCL_HEADER_PRESENT (__has_include() || __has_include()) #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 +# if _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT +# define _ONEDPL_SYCL_AVAILABLE 1 // Intel(R) oneAPI DPC++/C++ Compiler pre-defines SYCL_LANGUAGE_VERSION with -fsycl option -# elif !defined(__INTEL_LLVM_COMPILER) +# elif !defined(__INTEL_LLVM_COMPILER) // Other implementations might define the macro in the SYCL header -# define _ONEDPL_SYCL_POSSIBLY_AVAILABLE 1 -# endif +# define _ONEDPL_SYCL_POSSIBLY_AVAILABLE 1 +# endif #endif // If DPCPP backend is not explicitly turned off and SYCL is definitely available, enable it @@ -49,9 +49,9 @@ #endif #if defined(_ONEDPL_SYCL_POSSIBLY_AVAILABLE) && _ONEDPL_SAFE_TO_INCLUDE_SYCL # if __has_include() -# include +# include # else -# include +# include # endif # if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) # define _ONEDPL_BACKEND_SYCL 1 From aeb1863a1ac837f3c4010be08abc5923b2ed94b5 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Mon, 21 Oct 2024 10:56:07 -0500 Subject: [PATCH 10/30] Unify logic for dpcpp compilers Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero_backend_config.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index 06630584cc9..77463c5c0bf 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -18,6 +18,14 @@ #ifndef _ONEDPL_HETERO_BACKEND_CONFIG #define _ONEDPL_HETERO_BACKEND_CONFIG +// Detect both Intel(R) oneAPI DPC++/C++ Compiler and oneAPI DPC++ compiler +// Rely on an extension attribute, which is present in both compilers +#if __has_cpp_attribute(intel::kernel_args_restrict) +# define _ONEDPL_DPCPP_COMPILER 1 +#else +# define _ONEDPL_DPCPP_COMPILER 0 +#endif + // -------------------------------------------------------------------------------------------------------------------- // Enablement of heterogeneous backends // -------------------------------------------------------------------------------------------------------------------- @@ -28,8 +36,8 @@ #if _ONEDPL_SYCL_HEADER_PRESENT # if _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT # define _ONEDPL_SYCL_AVAILABLE 1 -// Intel(R) oneAPI DPC++/C++ Compiler pre-defines SYCL_LANGUAGE_VERSION with -fsycl option -# elif !defined(__INTEL_LLVM_COMPILER) +// DPC++/C++ Compiler pre-defines 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 From 85d7c674fa4ab31118cd8ff8d92981fcbb090cda Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Mon, 21 Oct 2024 13:27:19 -0500 Subject: [PATCH 11/30] Small fix Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero_backend_config.h | 2 +- test/support/test_config.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index 77463c5c0bf..8d1e3d9670a 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -37,7 +37,7 @@ # if _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT # define _ONEDPL_SYCL_AVAILABLE 1 // DPC++/C++ Compiler pre-defines SYCL_LANGUAGE_VERSION with -fsycl option -# elif _ONEDPL_DPCPP_COMPILER +# elif !_ONEDPL_DPCPP_COMPILER // Other implementations might define the macro in the SYCL header # define _ONEDPL_SYCL_POSSIBLY_AVAILABLE 1 # endif diff --git a/test/support/test_config.h b/test/support/test_config.h index e2b1d7c1484..f306291bcfb 100644 --- a/test/support/test_config.h +++ b/test/support/test_config.h @@ -91,13 +91,13 @@ // If DPCPP is requested, enable its testing #if ONEDPL_USE_DPCPP_BACKEND # define TEST_DPCPP_BACKEND_PRESENT 1 -#elif !defined(ONEDPL_USE_DPCPP_BACKEND) -# define TEST_DPCPP_BACKEND_PRESENT 0 -#else // Hack: delayed expansion based on _ONEDPL_HETERO_BACKEND, defined in oneDPL // TODO: avoid the hack by moving TEST_DPCPP_BACKEND_PRESENT into separate header and including after oneDPL headers // this will require to update all tests to include the new header +#elif !defined(ONEDPL_USE_DPCPP_BACKEND) # define TEST_DPCPP_BACKEND_PRESENT (_ONEDPL_HETERO_BACKEND) +#else +# define TEST_DPCPP_BACKEND_PRESENT 0 #endif #ifdef __SYCL_UNNAMED_LAMBDA__ From b2ba8d7927c29c8002aee9bc011a8db7ffc28f7d Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Tue, 22 Oct 2024 10:04:32 -0500 Subject: [PATCH 12/30] Remove _ONEDPL_HETERO_BACKEND hack in test_config Signed-off-by: Dmitriy Sobolev --- .../oneapi/dpl/pstl/hetero_backend_config.h | 5 ----- test/support/test_config.h | 20 +++++++++++-------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index 8d1e3d9670a..e517d53011e 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -78,11 +78,6 @@ # undef _ONEDPL_HETERO_BACKEND # endif # define _ONEDPL_HETERO_BACKEND 1 -#else -# if _ONEDPL_HETERO_BACKEND -# undef _ONEDPL_HETERO_BACKEND -# endif -# define _ONEDPL_HETERO_BACKEND 0 #endif // -------------------------------------------------------------------------------------------------------------------- diff --git a/test/support/test_config.h b/test/support/test_config.h index f306291bcfb..4722cdf3532 100644 --- a/test/support/test_config.h +++ b/test/support/test_config.h @@ -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. @@ -88,14 +88,18 @@ #define _PSTL_SYCL_TEST_USM 1 -// If DPCPP is requested, enable its testing -#if ONEDPL_USE_DPCPP_BACKEND +#define TEST_SYCL_HEADER_PRESENT (__has_include() || __has_include()) +#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 proved +// 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 -// Hack: delayed expansion based on _ONEDPL_HETERO_BACKEND, defined in oneDPL -// TODO: avoid the hack by moving TEST_DPCPP_BACKEND_PRESENT into separate header and including after oneDPL headers -// this will require to update all tests to include the new header -#elif !defined(ONEDPL_USE_DPCPP_BACKEND) -# define TEST_DPCPP_BACKEND_PRESENT (_ONEDPL_HETERO_BACKEND) +// Define to 0 in other cases since some tests may rely at the macro value at runtime #else # define TEST_DPCPP_BACKEND_PRESENT 0 #endif From 85c82ef05c1cf9e7d99d712be6381b995b613383 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Tue, 22 Oct 2024 10:23:51 -0500 Subject: [PATCH 13/30] Comment clarifications Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero_backend_config.h | 5 +++-- test/support/test_config.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index e517d53011e..b0f2b9b9929 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -13,13 +13,14 @@ // //===----------------------------------------------------------------------===// -// This header checks for heterogeneous backend availability, and configures them if available +// This header checks availability of heterogeneous backends, and configures them if available #ifndef _ONEDPL_HETERO_BACKEND_CONFIG #define _ONEDPL_HETERO_BACKEND_CONFIG // 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 @@ -36,7 +37,7 @@ #if _ONEDPL_SYCL_HEADER_PRESENT # if _ONEDPL_SYCL_LANGUAGE_VERSION_PRESENT # define _ONEDPL_SYCL_AVAILABLE 1 -// DPC++/C++ Compiler pre-defines SYCL_LANGUAGE_VERSION with -fsycl option +// 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 diff --git a/test/support/test_config.h b/test/support/test_config.h index 4722cdf3532..b0fe4c8a9c9 100644 --- a/test/support/test_config.h +++ b/test/support/test_config.h @@ -95,7 +95,7 @@ // 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 proved +// 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 From 420269e9214f3bfd1d6644711f1141a3c64c8706 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Tue, 22 Oct 2024 11:41:55 -0500 Subject: [PATCH 14/30] Fix for acpp Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero_backend_config.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index b0f2b9b9929..d65b09d6e51 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -49,14 +49,16 @@ # define _ONEDPL_BACKEND_SYCL 1 #endif -// Try checking SYCL_LANGUAGE_VERSION after sycl.hpp inclusion if SYCL availability has not been proven yet -// Include SYCL headers for reliable configurations only, the set can be extended in the future +// 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 -#if defined(_ONEDPL_SYCL_POSSIBLY_AVAILABLE) && _ONEDPL_SAFE_TO_INCLUDE_SYCL +// 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() # include # else @@ -67,10 +69,10 @@ # endif #endif // _ONEDPL_SYCL_POSSIBLY_AVAILABLE -// If DPCPP backend is explicitly requested and SYCL is definitely not available, throw an error +// 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 at least one heterogeneous backend is available, enable them From 41aec8c1d032cf77f0fd6e5186e1113beb784666 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Tue, 22 Oct 2024 12:36:33 -0500 Subject: [PATCH 15/30] Fix possible case Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero_backend_config.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h index d65b09d6e51..8bd33761371 100755 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ b/include/oneapi/dpl/pstl/hetero_backend_config.h @@ -44,11 +44,6 @@ # endif #endif -// If DPCPP backend is not explicitly turned off and SYCL is definitely available, enable it -#if (ONEDPL_USE_DPCPP_BACKEND || !defined(ONEDPL_USE_DPCPP_BACKEND)) && _ONEDPL_SYCL_AVAILABLE -# define _ONEDPL_BACKEND_SYCL 1 -#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__) @@ -65,7 +60,7 @@ # include # endif # if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) -# define _ONEDPL_BACKEND_SYCL 1 +# define _ONEDPL_SYCL_AVAILABLE 1 # endif #endif // _ONEDPL_SYCL_POSSIBLY_AVAILABLE @@ -75,6 +70,11 @@ 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 From 95f19bab2b4c3d05ce54fcb714597668293b81a3 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 24 Oct 2024 05:59:55 -0500 Subject: [PATCH 16/30] Get rid of heter_backend_config.h Signed-off-by: Dmitriy Sobolev --- .../oneapi/dpl/pstl/hetero_backend_config.h | 135 ------------------ include/oneapi/dpl/pstl/onedpl_config.h | 112 ++++++++++++++- 2 files changed, 109 insertions(+), 138 deletions(-) delete mode 100755 include/oneapi/dpl/pstl/hetero_backend_config.h diff --git a/include/oneapi/dpl/pstl/hetero_backend_config.h b/include/oneapi/dpl/pstl/hetero_backend_config.h deleted file mode 100755 index 8bd33761371..00000000000 --- a/include/oneapi/dpl/pstl/hetero_backend_config.h +++ /dev/null @@ -1,135 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Copyright (C) Intel Corporation -// -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// This file incorporates work covered by the following copyright and permission -// notice: -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// -//===----------------------------------------------------------------------===// - -// This header checks availability of heterogeneous backends, and configures them if available - -#ifndef _ONEDPL_HETERO_BACKEND_CONFIG -#define _ONEDPL_HETERO_BACKEND_CONFIG - -// 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 - -// -------------------------------------------------------------------------------------------------------------------- -// Enablement of heterogeneous backends -// -------------------------------------------------------------------------------------------------------------------- - -// Preliminary check SYCL availability -#define _ONEDPL_SYCL_HEADER_PRESENT (__has_include() || __has_include()) -#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() -# include -# else -# include -# endif -# if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) -# define _ONEDPL_SYCL_AVAILABLE 1 -# endif -#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 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 - -// -------------------------------------------------------------------------------------------------------------------- -// Configuration of 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 - -// -------------------------------------------------------------------------------------------------------------------- -// Configuration of SYCL heterogeneous backend -// -------------------------------------------------------------------------------------------------------------------- - -#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) - -// 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 - -# define _ONEDPL_BUILT_IN_STABLE_NAME_PRESENT __has_builtin(__builtin_sycl_unique_stable_name) -#endif // _ONEDPL_BACKEND_SYCL - -#endif // _ONEDPL_HETERO_BACKEND_CONFIG diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 4bd31093e58..69420b6dfab 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -19,7 +19,8 @@ // The version header also defines a few configuration macros used in this file #include "../internal/version_impl.h" -// Check availability of parallel backends +// -- Check availability of parallel backends -- + #if __has_include() # define _ONEDPL_TBB_AVAILABLE 1 #endif @@ -37,6 +38,71 @@ but OpenMP headers are not found or the compiler does not support OpenMP" #endif +// -- 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 + +// Preliminary check SYCL availability +#define _ONEDPL_SYCL_HEADER_PRESENT (__has_include() || __has_include()) +#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() +# include +# else +# include +# endif +# if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) +# define _ONEDPL_SYCL_AVAILABLE 1 +# endif +#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 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 @@ -274,7 +340,47 @@ # define _ONEDPL_STD_RANGES_ALGO_CPP_FUN 0 #endif -// Check availability of the heterogeneous backends, configure if available -#include "oneapi/dpl/pstl/hetero_backend_config.h" +// -- 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 + +#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) + +// 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 + +# define _ONEDPL_BUILT_IN_STABLE_NAME_PRESENT __has_builtin(__builtin_sycl_unique_stable_name) +#endif // _ONEDPL_BACKEND_SYCL #endif // _ONEDPL_CONFIG_H From 58b7d92f7649a8b009dd541d9f3a891f55ba8042 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Fri, 25 Oct 2024 12:17:26 -0500 Subject: [PATCH 17/30] Prepend missing _ONEDPL to some macros, rearrange macros Signed-off-by: Dmitriy Sobolev --- .../dpcpp/parallel_backend_sycl_utils.h | 2 +- .../pstl/hetero/dpcpp/unseq_backend_sycl.h | 6 ++--- include/oneapi/dpl/pstl/onedpl_config.h | 25 +++++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_utils.h b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_utils.h index 9bd195a80a9..29e2a24f44c 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_utils.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_utils.h @@ -77,7 +77,7 @@ __slm_adjusted_work_group_size(const _ExecutionPolicy& __policy, _Size __local_m return sycl::min(__local_mem_size / __local_mem_per_wi, __wg_size); } -#if _USE_SUB_GROUPS +#if _ONEDPL_USE_SUB_GROUPS template ::std::size_t __max_sub_group_size(const _ExecutionPolicy& __policy) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/unseq_backend_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/unseq_backend_sycl.h index d180e00fc27..e877ff45419 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/unseq_backend_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/unseq_backend_sycl.h @@ -30,7 +30,7 @@ namespace dpl namespace unseq_backend { -#if _USE_GROUP_ALGOS && defined(SYCL_IMPLEMENTATION_INTEL) +#if _ONEDPL_USE_GROUP_ALGOS && defined(SYCL_IMPLEMENTATION_INTEL) //This optimization depends on Intel(R) oneAPI DPC++ Compiler implementation such as support of binary operators from std namespace. //We need to use defined(SYCL_IMPLEMENTATION_INTEL) macro as a guard. @@ -71,12 +71,12 @@ using __has_known_identity = ::std::conditional_t< # endif //_ONEDPL_LIBSYCL_VERSION >= 50200 ::std::false_type>; // This is for the case of __can_use_known_identity<_Tp>==false -#else //_USE_GROUP_ALGOS && defined(SYCL_IMPLEMENTATION_INTEL) +#else //_ONEDPL_USE_GROUP_ALGOS && defined(SYCL_IMPLEMENTATION_INTEL) template using __has_known_identity = std::false_type; -#endif //_USE_GROUP_ALGOS && defined(SYCL_IMPLEMENTATION_INTEL) +#endif //_ONEDPL_USE_GROUP_ALGOS && defined(SYCL_IMPLEMENTATION_INTEL) template struct __known_identity_for_plus diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 69420b6dfab..87adeee2448 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -342,20 +342,10 @@ // -- 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 @@ -363,15 +353,24 @@ # define _ONEDPL_PREDEFINED_POLICIES 1 #endif +#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 _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 +# define _ONEDPL_USE_SUB_GROUPS 1 +# define _ONEDPL_USE_GROUP_ALGOS 1 # endif -# define _USE_RADIX_SORT (_USE_SUB_GROUPS && _USE_GROUP_ALGOS) +# define _USE_RADIX_SORT (_ONEDPL_USE_SUB_GROUPS && _ONEDPL_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 From be1568c75e87d33d0d0038dfea0d5ff9ed04dab5 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Wed, 6 Nov 2024 14:35:55 -0600 Subject: [PATCH 18/30] Get rid of DPCPP compiler check, move the error into sycl_defs.h Signed-off-by: Dmitriy Sobolev --- .../oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h | 7 ++++ include/oneapi/dpl/pstl/onedpl_config.h | 41 ++++--------------- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h index 83c44a8a07d..f6e6240f8de 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h @@ -26,6 +26,13 @@ #else # include #endif + +// If DPCPP backend is explicitly requested and SYCL is not available, issue a warning +#if !(SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION) +# error "Device execution policies are enabled, \ + but SYCL_LANGUAGE_VERSION/CL_SYCL_LANGUAGE_VERSION macros are not defined" +#endif + #include // Combine SYCL runtime library version diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 87adeee2448..dfed6122457 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -40,52 +40,25 @@ // -- 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 - // Preliminary check SYCL availability #define _ONEDPL_SYCL_HEADER_PRESENT (__has_include() || __has_include()) #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 +# else # 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() -# include -# else -# include -# endif -# if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) +// If DPCPP backend is explicitly requested, optimistically assume SYCL availability +#if ONEDPL_USE_DPCPP_BACKEND +# if _ONEDPL_SYCL_POSSIBLY_AVAILABLE # define _ONEDPL_SYCL_AVAILABLE 1 # endif -#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 SYCL implementation does not define SYCL_LANGUAGE_VERSION macro" +# if !_ONEDPL_SYCL_HEADER_PRESENT +# error "Device execution policies are enabled, but SYCL* headers are not found" +# endif #endif // If DPCPP backend is not explicitly turned off and SYCL is available, enable it From cae7bb641a70af163526bd744e52e5ac3910b882 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 04:53:45 -0600 Subject: [PATCH 19/30] Adjust documentation Signed-off-by: Dmitriy Sobolev --- documentation/library_guide/macros.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/documentation/library_guide/macros.rst b/documentation/library_guide/macros.rst index 2a1b5e4f8b2..241f777c171 100644 --- a/documentation/library_guide/macros.rst +++ b/documentation/library_guide/macros.rst @@ -99,12 +99,15 @@ Macro Description If all parallel backends are disabled by setting respective macros to 0, algorithms with parallel policies are executed sequentially by the calling thread. ---------------------------------- ------------------------------ -``ONEDPL_USE_DPCPP_BACKEND`` This macro enables the use of the device execution policies. - When the macro is not defined (by default) - or evaluates to non-zero, device policies are enabled. - When the macro is set to 0 there is no dependency on - the |dpcpp_cpp| and runtime libraries. - Trying to use device policies will lead to compilation errors. +``ONEDPL_USE_DPCPP_BACKEND`` This macro enables the use of device execution policies: + + - Not defined (default): the policies are enabled only if SYCL is present + (indicated by the presence of SYCL headers and the SYCL_LANGUAGE_VERSION macro); + otherwise, they are disabled. + - Set to a non-zero value: the policies are enabled. + - Set to 0: the policies are disabled. + + When device execution policies are disabled, no dependency on SYCL is introduced. ---------------------------------- ------------------------------ ``ONEDPL_USE_PREDEFINED_POLICIES`` This macro enables the use of predefined device policy objects, such as ``dpcpp_default`` and ``dpcpp_fpga``. When the macro is not defined (by default) From e2605511188e59e1e247401b9c9aaec5299fab31 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 05:17:55 -0600 Subject: [PATCH 20/30] Bullet list -> plain text for cohesiveness Signed-off-by: Dmitriy Sobolev --- documentation/library_guide/macros.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/documentation/library_guide/macros.rst b/documentation/library_guide/macros.rst index 241f777c171..19360d8ba74 100644 --- a/documentation/library_guide/macros.rst +++ b/documentation/library_guide/macros.rst @@ -99,15 +99,16 @@ Macro Description If all parallel backends are disabled by setting respective macros to 0, algorithms with parallel policies are executed sequentially by the calling thread. ---------------------------------- ------------------------------ -``ONEDPL_USE_DPCPP_BACKEND`` This macro enables the use of device execution policies: +``ONEDPL_USE_DPCPP_BACKEND`` This macro enables the use of device execution policies. - - Not defined (default): the policies are enabled only if SYCL is present - (indicated by the presence of SYCL headers and the SYCL_LANGUAGE_VERSION macro); - otherwise, they are disabled. - - Set to a non-zero value: the policies are enabled. - - Set to 0: the policies are disabled. + When the macro is not defined (default), + device policies are enabled only if SYCL is present, + indicated by the definition of ``SYCL_LANGUAGE_VERSION`` macro + and the availability of SYCL headers; otherwise, device policies are disabled. + If the macro is set to a non-zero value, device policies are enabled. + Setting the macro to 0 disables device policies. - When device execution policies are disabled, no dependency on SYCL is introduced. + When device execuiton policies are disabled, no dependency on SYCL is introduced. ---------------------------------- ------------------------------ ``ONEDPL_USE_PREDEFINED_POLICIES`` This macro enables the use of predefined device policy objects, such as ``dpcpp_default`` and ``dpcpp_fpga``. When the macro is not defined (by default) From 0fece8a98860f3dff7858fcf69baa0e3b12a25f5 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 08:15:33 -0600 Subject: [PATCH 21/30] Get rid of implementaiton details in the documentation Signed-off-by: Dmitriy Sobolev --- documentation/library_guide/macros.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/documentation/library_guide/macros.rst b/documentation/library_guide/macros.rst index 19360d8ba74..962d5b8403b 100644 --- a/documentation/library_guide/macros.rst +++ b/documentation/library_guide/macros.rst @@ -102,13 +102,12 @@ Macro Description ``ONEDPL_USE_DPCPP_BACKEND`` This macro enables the use of device execution policies. When the macro is not defined (default), - device policies are enabled only if SYCL is present, - indicated by the definition of ``SYCL_LANGUAGE_VERSION`` macro - and the availability of SYCL headers; otherwise, device policies are disabled. - If the macro is set to a non-zero value, device policies are enabled. + device policies are enabled only if SYCL support is detected, when possible; + otherwise, they are disabled. + If the macro is set to a non-zero value, device policies are enabled unconditionally. Setting the macro to 0 disables device policies. - When device execuiton policies are disabled, no dependency on SYCL is introduced. + When device execution policies are disabled, no dependency on SYCL is introduced. ---------------------------------- ------------------------------ ``ONEDPL_USE_PREDEFINED_POLICIES`` This macro enables the use of predefined device policy objects, such as ``dpcpp_default`` and ``dpcpp_fpga``. When the macro is not defined (by default) From 0de5e953389463177b9d18bd9a2a914155fcf87c Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 08:26:07 -0600 Subject: [PATCH 22/30] Add a note for usage of disabled policies Signed-off-by: Dmitriy Sobolev --- documentation/library_guide/macros.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/library_guide/macros.rst b/documentation/library_guide/macros.rst index 962d5b8403b..912fa389354 100644 --- a/documentation/library_guide/macros.rst +++ b/documentation/library_guide/macros.rst @@ -107,7 +107,8 @@ Macro Description If the macro is set to a non-zero value, device policies are enabled unconditionally. Setting the macro to 0 disables device policies. - When device execution policies are disabled, no dependency on SYCL is introduced. + When device policies are disabled, no SYCL dependency is introduced, + and their usage will lead to compilation errors. ---------------------------------- ------------------------------ ``ONEDPL_USE_PREDEFINED_POLICIES`` This macro enables the use of predefined device policy objects, such as ``dpcpp_default`` and ``dpcpp_fpga``. When the macro is not defined (by default) From a0fa36da2e95d882dd889d091d401ac086ded128 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 11:10:10 -0600 Subject: [PATCH 23/30] Move USE_RADIX sort closer to the useage place Signed-off-by: Dmitriy Sobolev --- .../oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h | 8 +++++--- include/oneapi/dpl/pstl/onedpl_config.h | 2 -- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h index 93a5c8c2496..5ecadf91ccd 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h @@ -44,7 +44,9 @@ #include "unseq_backend_sycl.h" #include "utils_ranges_sycl.h" -#if _USE_RADIX_SORT +#define _ONEDPL_USE_RADIX_SORT (_ONEDPL_USE_SUB_GROUPS && _ONEDPL_USE_GROUP_ALGOS) + +#if _ONEDPL_USE_RADIX_SORT # include "parallel_backend_sycl_radix_sort.h" #endif @@ -1892,7 +1894,7 @@ template struct __is_radix_sort_usable_for_type { static constexpr bool value = -#if _USE_RADIX_SORT +#if _ONEDPL_USE_RADIX_SORT (::std::is_arithmetic_v<_T> || ::std::is_same_v) && (__internal::__is_comp_ascending<::std::decay_t<_Compare>>::value || __internal::__is_comp_descending<::std::decay_t<_Compare>>::value); @@ -1901,7 +1903,7 @@ struct __is_radix_sort_usable_for_type #endif }; -#if _USE_RADIX_SORT +#if _ONEDPL_USE_RADIX_SORT template < typename _ExecutionPolicy, typename _Range, typename _Compare, typename _Proj, ::std::enable_if_t< diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index dfed6122457..8bebe0c3c27 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -343,8 +343,6 @@ # define _ONEDPL_USE_GROUP_ALGOS 1 # endif -# define _USE_RADIX_SORT (_ONEDPL_USE_SUB_GROUPS && _ONEDPL_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. From c51e2a98f2e98472d54eff65cf6ac297803c6a0b Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 11:17:48 -0600 Subject: [PATCH 24/30] Correct a comment about absence of SYCL_LANGUAGE_VERSION Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h index f6e6240f8de..fbe9bd24080 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h @@ -27,7 +27,7 @@ # include #endif -// If DPCPP backend is explicitly requested and SYCL is not available, issue a warning +// If SYCL_LANGUAGE_VERSION is still not set after including the SYCL header, issue an error #if !(SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION) # error "Device execution policies are enabled, \ but SYCL_LANGUAGE_VERSION/CL_SYCL_LANGUAGE_VERSION macros are not defined" From 07479d753ae75259d7e01d1c3958fa9e63755a66 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 11:45:15 -0600 Subject: [PATCH 25/30] Simplify documentation Signed-off-by: Dmitriy Sobolev --- documentation/library_guide/macros.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/library_guide/macros.rst b/documentation/library_guide/macros.rst index 912fa389354..a18ba670ee5 100644 --- a/documentation/library_guide/macros.rst +++ b/documentation/library_guide/macros.rst @@ -102,7 +102,7 @@ Macro Description ``ONEDPL_USE_DPCPP_BACKEND`` This macro enables the use of device execution policies. When the macro is not defined (default), - device policies are enabled only if SYCL support is detected, when possible; + device policies are enabled only if SYCL support can be detected; otherwise, they are disabled. If the macro is set to a non-zero value, device policies are enabled unconditionally. Setting the macro to 0 disables device policies. From 580f3d162b9d92269a23edfecb59c7fcf10fa676 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 14:27:39 -0600 Subject: [PATCH 26/30] Simplify SYCL backend enablement Signed-off-by: Dmitriy Sobolev --- .../oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h | 7 ------- include/oneapi/dpl/pstl/onedpl_config.h | 20 ++++++------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h index fbe9bd24080..83c44a8a07d 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h @@ -26,13 +26,6 @@ #else # include #endif - -// If SYCL_LANGUAGE_VERSION is still not set after including the SYCL header, issue an error -#if !(SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION) -# error "Device execution policies are enabled, \ - but SYCL_LANGUAGE_VERSION/CL_SYCL_LANGUAGE_VERSION macros are not defined" -#endif - #include // Combine SYCL runtime library version diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 8bebe0c3c27..908b2eb292c 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -40,24 +40,16 @@ // -- Check availability of heterogeneous backends -- -// Preliminary check SYCL availability #define _ONEDPL_SYCL_HEADER_PRESENT (__has_include() || __has_include()) -#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 -# else -# define _ONEDPL_SYCL_POSSIBLY_AVAILABLE 1 -# endif -#endif - -// If DPCPP backend is explicitly requested, optimistically assume SYCL availability -#if ONEDPL_USE_DPCPP_BACKEND -# if _ONEDPL_SYCL_POSSIBLY_AVAILABLE + // If DPCPP backend is explicitly requested, optimistically assume SYCL availability; + // otherwise, make sure that it is definitely available through SYCL_LANGUAGE_VERSION macros +# if SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION || ONEDPL_USE_DPCPP_BACKEND # define _ONEDPL_SYCL_AVAILABLE 1 # endif -# if !_ONEDPL_SYCL_HEADER_PRESENT -# error "Device execution policies are enabled, but SYCL* headers are not found" +#else +# if ONEDPL_USE_DPCPP_BACKEND +# error "Device execution policies are requested, but SYCL* headers are not found" # endif #endif From b644e81832ed7e4edbf46ecdb3098fe8fc096bff Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 14:41:59 -0600 Subject: [PATCH 27/30] Return a check in sycl_defs.h Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h index 83c44a8a07d..fbe9bd24080 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/sycl_defs.h @@ -26,6 +26,13 @@ #else # include #endif + +// If SYCL_LANGUAGE_VERSION is still not set after including the SYCL header, issue an error +#if !(SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION) +# error "Device execution policies are enabled, \ + but SYCL_LANGUAGE_VERSION/CL_SYCL_LANGUAGE_VERSION macros are not defined" +#endif + #include // Combine SYCL runtime library version From f91a5ba6dab2af0ec339ddf0a33bc01e46db548d Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 14:46:18 -0600 Subject: [PATCH 28/30] clang-format Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/onedpl_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 908b2eb292c..1738131e051 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -42,8 +42,8 @@ #define _ONEDPL_SYCL_HEADER_PRESENT (__has_include() || __has_include()) #if _ONEDPL_SYCL_HEADER_PRESENT - // If DPCPP backend is explicitly requested, optimistically assume SYCL availability; - // otherwise, make sure that it is definitely available through SYCL_LANGUAGE_VERSION macros +// If DPCPP backend is explicitly requested, optimistically assume SYCL availability; +// otherwise, make sure that it is definitely available through SYCL_LANGUAGE_VERSION macros # if SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION || ONEDPL_USE_DPCPP_BACKEND # define _ONEDPL_SYCL_AVAILABLE 1 # endif From 70cf886edb80d2709351d67cdd2f7967028702f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Thu, 7 Nov 2024 14:58:52 -0600 Subject: [PATCH 29/30] Simplify macros more Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/onedpl_config.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/oneapi/dpl/pstl/onedpl_config.h b/include/oneapi/dpl/pstl/onedpl_config.h index 1738131e051..05b91087078 100644 --- a/include/oneapi/dpl/pstl/onedpl_config.h +++ b/include/oneapi/dpl/pstl/onedpl_config.h @@ -40,10 +40,9 @@ // -- Check availability of heterogeneous backends -- -#define _ONEDPL_SYCL_HEADER_PRESENT (__has_include() || __has_include()) -#if _ONEDPL_SYCL_HEADER_PRESENT // If DPCPP backend is explicitly requested, optimistically assume SYCL availability; -// otherwise, make sure that it is definitely available through SYCL_LANGUAGE_VERSION macros +// otherwise, make sure that it is definitely available additionally checking SYCL_LANGUAGE_VERSION +#if __has_include() || __has_include() # if SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION || ONEDPL_USE_DPCPP_BACKEND # define _ONEDPL_SYCL_AVAILABLE 1 # endif From 3284e956e4f3d30c3683271fe8854494a07c92b4 Mon Sep 17 00:00:00 2001 From: Dmitriy Sobolev Date: Fri, 15 Nov 2024 02:38:56 -0600 Subject: [PATCH 30/30] Add comments after #endif Signed-off-by: Dmitriy Sobolev --- include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h | 4 ++-- .../dpl/pstl/hetero/dpcpp/parallel_backend_sycl_utils.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h index 5ecadf91ccd..63eec9964d1 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl.h @@ -1900,7 +1900,7 @@ struct __is_radix_sort_usable_for_type __internal::__is_comp_descending<::std::decay_t<_Compare>>::value); #else false; -#endif +#endif // _ONEDPL_USE_RADIX_SORT }; #if _ONEDPL_USE_RADIX_SORT @@ -1915,7 +1915,7 @@ __parallel_stable_sort(oneapi::dpl::__internal::__device_backend_tag __backend_t return __parallel_radix_sort<__internal::__is_comp_ascending<::std::decay_t<_Compare>>::value>( __backend_tag, ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng), __proj); } -#endif +#endif // _ONEDPL_USE_RADIX_SORT template < typename _ExecutionPolicy, typename _Range, typename _Compare, typename _Proj, diff --git a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_utils.h b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_utils.h index 29e2a24f44c..208ee4444c8 100644 --- a/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_utils.h +++ b/include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_utils.h @@ -86,7 +86,7 @@ __max_sub_group_size(const _ExecutionPolicy& __policy) //The result of get_info() can be empty; if so, return 0 return __supported_sg_sizes.empty() ? 0 : __supported_sg_sizes.back(); } -#endif +#endif // _ONEDPL_USE_SUB_GROUPS template ::std::uint32_t