Skip to content

Commit 501f165

Browse files
committed
Introduce CELERITY_SYCL_IS_* macros
1 parent bb9b31e commit 501f165

File tree

8 files changed

+30
-17
lines changed

8 files changed

+30
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ See our [platform support guide](docs/platform-support.md) for a complete list o
2121
- Add support for SimSYCL as a SYCL implementation (#238)
2222
- Extend compiler support to GCC (optionally with sanitizers) and C++20 code bases (#238)
2323
- Add support for profiling with [Tracy](https://github.com/wolfpld/tracy), via `CELERITY_TRACY_SUPPORT` and environment variable `CELERITY_TRACY` (#267)
24+
- The active SYCL implementation can now be queried via `CELERITY_SYCL_IS_*` macros (#??)
2425

2526
### Changed
2627

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@ elseif(UNIX)
241241
set(SOURCES ${SOURCES} src/platform_specific/named_threads.unix.cc)
242242
endif()
243243

244+
# Read by configure_file()
245+
set(CELERITY_SYCL_IS_ACPP OFF)
246+
set(CELERITY_SYCL_IS_DPCPP OFF)
247+
set(CELERITY_SYCL_IS_SIMSYCL OFF)
248+
if(CELERITY_SYCL_IMPL STREQUAL "AdaptiveCpp")
249+
set(CELERITY_SYCL_IS_ACPP ON)
250+
elseif(CELERITY_SYCL_IMPL STREQUAL "DPC++")
251+
set(CELERITY_SYCL_IS_DPCPP ON)
252+
elseif(CELERITY_SYCL_IMPL STREQUAL "SimSYCL")
253+
set(CELERITY_SYCL_IS_SIMSYCL ON)
254+
endif()
255+
244256
configure_file(include/version.h.in include/version.h @ONLY)
245257
list(APPEND INCLUDES "${CMAKE_CURRENT_BINARY_DIR}/include/version.h")
246258

cmake/AddToTarget.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ if(CELERITY_SYCL_IMPL STREQUAL "DPC++")
1313
-fsycl
1414
-sycl-std=2020
1515
"-fsycl-targets=${CELERITY_DPCPP_TARGETS}"
16-
-DCELERITY_DPCPP=1
1716
-Wno-sycl-strict # -Wsycl-strict produces false-positive warnings in DPC++'s own SYCL headers as of 2022-10-06
1817
)
1918
target_compile_options(${ADD_SYCL_TARGET} PUBLIC ${DPCPP_FLAGS})
@@ -30,8 +29,6 @@ elseif(CELERITY_SYCL_IMPL STREQUAL "SimSYCL")
3029
"${multi_value_args}"
3130
${ARGN}
3231
)
33-
target_compile_options(${ADD_SYCL_TARGET} PUBLIC -DCELERITY_SIMSYCL=1)
34-
target_link_options(${ADD_SYCL_TARGET} PUBLIC -DCELERITY_SIMSYCL=1)
3532
endfunction()
3633
endif()
3734

examples/matmul/matmul.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <celerity.h>
44

5-
#if !defined(NDEBUG) || CELERITY_SIMSYCL
5+
#if !defined(NDEBUG) || CELERITY_SYCL_IS_SIMSYCL
66
const size_t MAT_SIZE = 128;
77
#else
88
const size_t MAT_SIZE = 1024;

include/version.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#pragma once
22

3+
#cmakedefine01 CELERITY_SYCL_IS_ACPP
4+
#cmakedefine01 CELERITY_SYCL_IS_DPCPP
5+
#cmakedefine01 CELERITY_SYCL_IS_SIMSYCL
6+
37
// CELERITY_DETAIL_ENABLE_DEBUG is specified on the command line
48
#cmakedefine01 CELERITY_USE_MIMALLOC
59
#cmakedefine01 CELERITY_DETAIL_HAS_NAMED_THREADS

include/workaround.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
#include <sycl/sycl.hpp>
88

9-
#if defined(CELERITY_DPCPP)
9+
#if CELERITY_SYCL_IS_DPCPP
1010
#define CELERITY_WORKAROUND_DPCPP 1
1111
#else
1212
#define CELERITY_WORKAROUND_DPCPP 0
1313
#endif
1414

15-
#if defined(__HIPSYCL__)
15+
#if CELERITY_SYCL_IS_ACPP
1616
#define CELERITY_WORKAROUND_ACPP 1
1717
#define CELERITY_WORKAROUND_VERSION_MAJOR HIPSYCL_VERSION_MAJOR
1818
#define CELERITY_WORKAROUND_VERSION_MINOR HIPSYCL_VERSION_MINOR
@@ -21,7 +21,7 @@
2121
#define CELERITY_WORKAROUND_ACPP 0
2222
#endif
2323

24-
#if defined(CELERITY_SIMSYCL)
24+
#if CELERITY_SYCL_IS_SIMSYCL
2525
#define CELERITY_WORKAROUND_SIMSYCL 1
2626
#else
2727
#define CELERITY_WORKAROUND_SIMSYCL 0

src/backend/sycl_cuda_backend.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include "system_info.h"
99
#include "tracy.h"
1010
#include "utils.h"
11-
#include "workaround.h"
12-
11+
#include "version.h"
1312

1413
#define CELERITY_STRINGIFY2(f) #f
1514
#define CELERITY_STRINGIFY(f) CELERITY_STRINGIFY2(f)
@@ -75,7 +74,7 @@ void nd_copy_device_async(cudaStream_t stream, const void* const source_base, vo
7574
// - There are no real thread-safety guarantees. DPC++ currently does not submit kernels from background threads, but if it ever starts doing so, this will
7675
// break more-or-less silently.
7776
// There is an open GitHub issue on the matter: https://github.com/intel/llvm/issues/13706
78-
#if defined(CELERITY_DPCPP)
77+
#if CELERITY_SYCL_IS_DPCPP
7978

8079
struct cuda_native_event_deleter {
8180
void operator()(const cudaEvent_t evt) const { CELERITY_CUDA_CHECK(cudaEventDestroy, evt); }
@@ -117,7 +116,7 @@ class cuda_event final : public async_event_impl {
117116
unique_cuda_native_event m_after;
118117
};
119118

120-
#endif // defined(CELERITY_DPCPP)
119+
#endif // CELERITY_SYCL_IS_DPCPP
121120

122121
bool can_enable_peer_access(const int id_device, const int id_peer) {
123122
// RTX 30xx and 40xx GPUs do not support peer access, but Nvidia Driver < 550 incorrectly reports that it does, causing kernel panics when enabling it
@@ -151,15 +150,15 @@ namespace celerity::detail::sycl_backend_detail {
151150
async_event nd_copy_device_cuda(sycl::queue& queue, const void* const source_base, void* const dest_base, const box<3>& source_box, const box<3>& dest_box,
152151
const region<3>& copy_region, const size_t elem_size, bool enable_profiling) //
153152
{
154-
#if defined(__HIPSYCL__)
153+
#if CELERITY_SYCL_IS_ACPP
155154
// AdaptiveCpp provides first-class custom backend op submission without a host round-trip like sycl::queue::host_task would require.
156155
auto event = queue.AdaptiveCpp_enqueue_custom_operation([=](sycl::interop_handle handle) {
157156
const auto stream = handle.get_native_queue<sycl::backend::cuda>();
158157
cuda_backend_detail::nd_copy_device_async(stream, source_base, dest_base, source_box, dest_box, copy_region, elem_size);
159158
});
160159
sycl_backend_detail::flush(queue);
161160
return make_async_event<sycl_event>(std::move(event), enable_profiling);
162-
#elif defined(CELERITY_DPCPP)
161+
#elif CELERITY_SYCL_IS_DPCPP
163162
// With DPC++, we must submit from the executor thread - see the comment on cuda_native_event above.
164163
const auto stream = sycl::get_native<sycl::backend::ext_oneapi_cuda>(queue);
165164
auto before = enable_profiling ? cuda_backend_detail::record_native_event(stream, enable_profiling) : nullptr;
@@ -171,7 +170,7 @@ async_event nd_copy_device_cuda(sycl::queue& queue, const void* const source_bas
171170
#endif
172171
}
173172

174-
#if defined(CELERITY_DPCPP)
173+
#if CELERITY_SYCL_IS_DPCPP
175174
constexpr sycl::backend sycl_cuda_backend = sycl::backend::ext_oneapi_cuda;
176175
#else
177176
constexpr sycl::backend sycl_cuda_backend = sycl::backend::cuda;

src/runtime.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ namespace detail {
9696
}
9797

9898
static std::string get_sycl_version() {
99-
#if defined(__HIPSYCL__) || defined(__HIPSYCL_TRANSFORM__)
99+
#if CELERITY_SYCL_IS_ACPP
100100
return fmt::format("AdaptiveCpp {}.{}.{}", HIPSYCL_VERSION_MAJOR, HIPSYCL_VERSION_MINOR, HIPSYCL_VERSION_PATCH);
101-
#elif CELERITY_DPCPP
101+
#elif CELERITY_SYCL_IS_DPCPP
102102
return "DPC++ / Clang " __clang_version__;
103-
#elif CELERITY_SIMSYCL
103+
#elif CELERITY_SYCL_IS_SIMSYCL
104104
return "SimSYCL " SIMSYCL_VERSION;
105105
#else
106106
#error "unknown SYCL implementation"

0 commit comments

Comments
 (0)