Skip to content

Commit 2b0ebab

Browse files
authored
[SYCL] Introduce backend macros (#4636)
According to SYCL spec: backend macro should be specified for all supported backends (defined in the Khronos group). It also refers to extension macros (aka feature test macro) for other backends introduced by a vendor. Khronos group defines only OpenCL backend and other backends supported by DPC++ should be treated as extensions. The following macros are defined when the compiler is built with the corresponding backend. OpenCL and Level_Zero backends are always available, others are enabled on build time: OpenCL backed: SYCL_BACKEND_OPENCL Level Zero backend: SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO CUDA backend: SYCL_EXT_ONEAPI_BACKEND_CUDA ESIMD_CPU backend: SYCL_EXT_INTEL_BACKEND_ESIMD_EMULATOR HIP backend: SYCL_EXT_ONEAPI_BACKEND_HIP backend::esimd_cpu is renamed to backend::ext_intel_esimd_emulator. Old naming was marked as deprecated.
1 parent 0a65cb4 commit 2b0ebab

File tree

16 files changed

+109
-13
lines changed

16 files changed

+109
-13
lines changed

buildbot/configure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def do_configure(args):
2929
libclc_targets_to_build = ''
3030
libclc_gen_remangled_variants = 'OFF'
3131
sycl_build_pi_cuda = 'OFF'
32-
sycl_build_pi_esimd_cpu = 'OFF'
32+
sycl_build_pi_esimd_emulator = 'OFF'
3333
sycl_build_pi_hip = 'OFF'
3434
sycl_build_pi_hip_platform = 'AMD'
3535
sycl_clang_extra_flags = ''
@@ -53,7 +53,7 @@ def do_configure(args):
5353
llvm_targets_to_build = 'ARM;AArch64'
5454

5555
if args.enable_esimd_cpu_emulation:
56-
sycl_build_pi_esimd_cpu = 'ON'
56+
sycl_build_pi_esimd_emulator = 'ON'
5757

5858
if args.cuda or args.hip:
5959
llvm_enable_projects += ';libclc'
@@ -128,7 +128,7 @@ def do_configure(args):
128128
"-DBUILD_SHARED_LIBS={}".format(llvm_build_shared_libs),
129129
"-DSYCL_ENABLE_XPTI_TRACING={}".format(sycl_enable_xpti_tracing),
130130
"-DLLVM_ENABLE_LLD={}".format(llvm_enable_lld),
131-
"-DSYCL_BUILD_PI_ESIMD_CPU={}".format(sycl_build_pi_esimd_cpu),
131+
"-DSYCL_BUILD_PI_ESIMD_EMULATOR={}".format(sycl_build_pi_esimd_emulator),
132132
"-DXPTI_ENABLE_WERROR={}".format(xpti_enable_werror),
133133
"-DSYCL_CLANG_EXTRA_FLAGS={}".format(sycl_clang_extra_flags)
134134
]

sycl/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
include/CL/sycl/version.hpp
2+
include/CL/sycl/feature_test.hpp

sycl/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ set(sycl_plugin_dir ${CMAKE_CURRENT_SOURCE_DIR}/plugins)
100100
string(TIMESTAMP __SYCL_COMPILER_VERSION "%Y%m%d")
101101
set(version_header "${sycl_inc_dir}/CL/sycl/version.hpp")
102102
configure_file("${version_header}.in" "${version_header}")
103+
set(feature_header "${sycl_inc_dir}/CL/sycl/feature_test.hpp")
104+
configure_file("${feature_header}.in" "${feature_header}")
103105

104106
# This is workaround to detect changes (add or modify) in subtree which
105107
# are not detected by copy_directory command.
@@ -310,7 +312,7 @@ endif()
310312
# TODO : Remove 'if (NOT MSVC)' when CM_EMU supports Windows
311313
# environment
312314
if (NOT MSVC)
313-
if (SYCL_BUILD_PI_ESIMD_CPU)
315+
if (SYCL_BUILD_PI_ESIMD_EMULATOR)
314316
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS pi_esimd_cpu libcmrt-headers)
315317
if (MSVC)
316318
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libcmrt-libs libcmrt-dlls)

sycl/include/CL/sycl/backend_types.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ enum class backend : char {
2626
ext_oneapi_level_zero,
2727
cuda = 3,
2828
all = 4,
29-
esimd_cpu = 5,
29+
ext_intel_esimd_emulator = 5,
30+
esimd_cpu __SYCL2020_DEPRECATED("use 'ext_oneapi_esimd_emulator' instead") =
31+
ext_intel_esimd_emulator,
3032
hip = 6,
3133
};
3234

@@ -55,8 +57,8 @@ inline std::ostream &operator<<(std::ostream &Out, backend be) {
5557
case backend::cuda:
5658
Out << "cuda";
5759
break;
58-
case backend::esimd_cpu:
59-
Out << "esimd_cpu";
60+
case backend::ext_intel_esimd_emulator:
61+
Out << "ext_intel_esimd_emulator";
6062
break;
6163
case backend::hip:
6264
Out << "hip";

sycl/include/CL/sycl/feature_test.hpp renamed to sycl/include/CL/sycl/feature_test.hpp.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
__SYCL_INLINE_NAMESPACE(cl) {
1111
namespace sycl {
1212

13+
#define SYCL_BACKEND_OPENCL 1
1314
// Feature test macro definitions
1415

1516
// TODO: Move these feature-test macros to compiler driver.
@@ -29,6 +30,18 @@ namespace sycl {
2930
#define SYCL_EXT_INTEL_MEM_CHANNEL_PROPERTY 1
3031
#define SYCL_EXT_INTEL_USM_ADDRESS_SPACES 1
3132
#define SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO 1
33+
#cmakedefine01 SYCL_BUILD_PI_CUDA
34+
#if SYCL_BUILD_PI_CUDA
35+
#define SYCL_EXT_ONEAPI_BACKEND_CUDA 1
36+
#endif
37+
#cmakedefine01 SYCL_BUILD_PI_ESIMD_EMULATOR
38+
#if SYCL_BUILD_PI_ESIMD_EMULATOR
39+
#define SYCL_EXT_INTEL_BACKEND_ESIMD_EMULATOR 1
40+
#endif
41+
#cmakedefine01 SYCL_BUILD_PI_HIP
42+
#if SYCL_BUILD_PI_HIP
43+
#define SYCL_EXT_ONEAPI_BACKEND_HIP 1
44+
#endif
3245

3346
} // namespace sycl
3447
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/sycl/ext/intel/experimental/esimd/emu/detail/esimdcpu_device_interface.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ ESIMDDeviceInterface *getESIMDDeviceInterface() {
7575
// tight loop)
7676
void *PIOpaqueData = nullptr;
7777

78-
PIOpaqueData = getPluginOpaqueData<cl::sycl::backend::esimd_cpu>(nullptr);
78+
PIOpaqueData =
79+
getPluginOpaqueData<cl::sycl::backend::ext_oneapi_esimd_emulator>(
80+
nullptr);
7981

8082
ESIMDEmuPluginOpaqueData *OpaqueData =
8183
reinterpret_cast<ESIMDEmuPluginOpaqueData *>(PIOpaqueData);

sycl/plugins/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ add_subdirectory(level_zero)
1818
# TODO : Remove 'if (NOT MSVC)' when CM_EMU supports Windows
1919
# environment
2020
if (NOT MSVC)
21-
if (SYCL_BUILD_PI_ESIMD_CPU)
21+
if (SYCL_BUILD_PI_ESIMD_EMULATOR)
2222
add_subdirectory(esimd_cpu)
2323
endif()
2424
endif()

sycl/source/detail/pi.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void *getPluginOpaqueData(void *OpaqueDataParam) {
7474
}
7575

7676
template __SYCL_EXPORT void *
77-
getPluginOpaqueData<cl::sycl::backend::esimd_cpu>(void *);
77+
getPluginOpaqueData<cl::sycl::backend::ext_intel_esimd_emulator>(void *);
7878

7979
namespace pi {
8080

@@ -504,7 +504,8 @@ template <backend BE> const plugin &getPlugin() {
504504

505505
template __SYCL_EXPORT const plugin &getPlugin<backend::opencl>();
506506
template __SYCL_EXPORT const plugin &getPlugin<backend::level_zero>();
507-
template __SYCL_EXPORT const plugin &getPlugin<backend::esimd_cpu>();
507+
template __SYCL_EXPORT const plugin &
508+
getPlugin<backend::ext_intel_esimd_emulator>();
508509

509510
// Report error and no return (keeps compiler from printing warnings).
510511
// TODO: Probably change that to throw a catchable exception,

sycl/test/basic_tests/exceptions-SYCL-2020.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ int main() {
9191
sycl::backend_traits<sycl::backend::cuda>::errc someCUDAErrCode{EC};
9292
sycl::errc_for<sycl::backend::cuda> anotherCUDAErrCode{EC};
9393
assert(someCUDAErrCode == anotherCUDAErrCode);
94-
sycl::backend_traits<sycl::backend::esimd_cpu>::errc someESIMDErrCode{EC};
95-
sycl::errc_for<sycl::backend::esimd_cpu> anotherESIMDErrCode{EC};
94+
sycl::backend_traits<sycl::backend::ext_intel_esimd_emulator>::errc
95+
someESIMDErrCode{EC};
96+
sycl::errc_for<sycl::backend::ext_intel_esimd_emulator> anotherESIMDErrCode{
97+
EC};
9698
assert(someESIMDErrCode == anotherESIMDErrCode);
9799
sycl::backend_traits<sycl::backend::hip>::errc someHIPErrCode{EC};
98100
sycl::errc_for<sycl::backend::hip> anotherHIPErrCode{EC};

sycl/test/extensions/macro.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@
55
#include <CL/sycl.hpp>
66
#include <iostream>
77
int main() {
8+
#if SYCL_BACKEND_OPENCL == 1
9+
std::cout << "SYCL_BACKEND_OPENCL=1" << std::endl;
10+
#else
11+
std::cerr << "SYCL_BACKEND_OPENCL!=1" << std::endl;
12+
exit(1);
13+
#endif
814
#if SYCL_EXT_ONEAPI_SUB_GROUP_MASK == 1
915
std::cout << "SYCL_EXT_ONEAPI_SUB_GROUP_MASK=1" << std::endl;
1016
#else
1117
std::cerr << "SYCL_EXT_ONEAPI_SUB_GROUP_MASK!=1" << std::endl;
1218
exit(1);
19+
#endif
20+
#if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO == 1
21+
std::cout << "SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO=1" << std::endl;
22+
#else
23+
std::cerr << "SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO!=1" << std::endl;
24+
exit(1);
1325
#endif
1426
exit(0);
1527
}

sycl/test/extensions/macro_cuda.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This test checks presence of macros for available extensions.
2+
// RUN: %clangxx -fsycl %s -o %t.out
3+
// RUN: %t.out
4+
// REQUIRES: cuda_be
5+
#include <CL/sycl.hpp>
6+
#include <iostream>
7+
int main() {
8+
#if SYCL_EXT_ONEAPI_BACKEND_CUDA == 1
9+
std::cout << "SYCL_EXT_ONEAPI_BACKEND_CUDA=1" << std::endl;
10+
#else
11+
std::cerr << "SYCL_EXT_ONEAPI_BACKEND_CUDA!=1" << std::endl;
12+
exit(1);
13+
#endif
14+
exit(0);
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This test checks presence of macros for available extensions.
2+
// RUN: %clangxx -fsycl %s -o %t.out
3+
// RUN: %t.out
4+
// REQUIRES: esimd_emulator_be
5+
#include <CL/sycl.hpp>
6+
#include <iostream>
7+
int main() {
8+
#if SYCL_EXT_INTEL_BACKEND_ESIMD_EMULATOR == 1
9+
std::cout << "SYCL_EXT_INTEL_BACKEND_ESIMD_EMULATOR=1" << std::endl;
10+
#else
11+
std::cerr << "SYCL_EXT_INTEL_BACKEND_ESIMD_EMULATOR!=1" << std::endl;
12+
exit(1);
13+
#endif
14+
exit(0);
15+
}

sycl/test/extensions/macro_hip.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This test checks presence of macros for available extensions.
2+
// RUN: %clangxx -fsycl %s -o %t.out
3+
// RUN: %t.out
4+
// REQUIRES: hip_be
5+
#include <CL/sycl.hpp>
6+
#include <iostream>
7+
int main() {
8+
#if SYCL_EXT_ONEAPI_BACKEND_HIP == 1
9+
std::cout << "SYCL_EXT_ONEAPI_BACKEND_HIP=1" << std::endl;
10+
#else
11+
std::cerr << "SYCL_EXT_ONEAPI_BACKEND_HIP!=1" << std::endl;
12+
exit(1);
13+
#endif
14+
exit(0);
15+
}

sycl/test/lit.cfg.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@
100100
lit_config.note("Triple: {}".format(triple))
101101
config.substitutions.append( ('%sycl_triple', triple ) )
102102

103+
if config.cuda_be == "ON":
104+
config.available_features.add('cuda_be')
105+
106+
if config.hip_be == "ON":
107+
config.available_features.add('hip_be')
108+
109+
if config.esimd_emulator_be == "ON":
110+
config.available_features.add('esimd_emulator_be')
111+
103112
if triple == 'nvptx64-nvidia-cuda':
104113
config.available_features.add('cuda')
105114

sycl/test/lit.site.cfg.py.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ config.llvm_enable_projects = "@LLVM_ENABLE_PROJECTS@"
2424
config.sycl_threads_lib = '@SYCL_THREADS_LIB@'
2525
config.sycl_use_libcxx = '@SYCL_USE_LIBCXX@'
2626
config.extra_environment = lit_config.params.get("extra_environment", "@LIT_EXTRA_ENVIRONMENT@")
27+
config.cuda_be = '@SYCL_BUILD_PI_CUDA@'
28+
config.esimd_emulator_be = '@SYCL_BUILD_PI_ESIMD_EMULATOR@'
29+
config.hip_be = '@SYCL_BUILD_PI_HIP@'
2730

2831
import lit.llvm
2932
lit.llvm.initialize(lit_config, config)

sycl/test/warnings/sycl_2020_deprecations.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ int main() {
158158
auto LevelZeroBackend = sycl::backend::level_zero;
159159
(void)LevelZeroBackend;
160160

161+
// expected-warning@+1{{'esimd_cpu' is deprecated: use 'ext_oneapi_esimd_emulator' instead}}
162+
auto ESIMDCPUBackend = sycl::backend::esimd_cpu;
163+
(void)ESIMDCPUBackend;
164+
161165
sycl::half Val = 1.0f;
162166
// expected-warning@+1{{'bit_cast<unsigned short, sycl::detail::half_impl::half>' is deprecated: use 'sycl::bit_cast' instead}}
163167
auto BitCastRes = sycl::detail::bit_cast<unsigned short>(Val);

0 commit comments

Comments
 (0)