From fae8bdbcac1ce82915bbcf617e8c96da3fa19873 Mon Sep 17 00:00:00 2001 From: Nicolas Miller Date: Thu, 8 Aug 2024 16:56:11 +0100 Subject: [PATCH] [SYCL][CUDA][HIP] Define backend macros based on compiler Currently the backend macros are only defined when the runtime adapters for the given backend are built. It's more accurate to use whether or not the compiler can target these backends, regardless of whether the runtime elements are present. It should be possible to compile an application for a backend without having to install the matching runtime. --- sycl/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index aa1f49ff1a6b6..55507cb467ccb 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -169,11 +169,9 @@ option(SYCL_ENABLE_MAJOR_RELEASE_PREVIEW_LIB "Enable build of the SYCL major rel # Needed for feature_test.hpp if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS) set(SYCL_BUILD_BACKEND_CUDA ON) - set(SYCL_EXT_ONEAPI_BACKEND_CUDA ON) endif() if ("hip" IN_LIST SYCL_ENABLE_PLUGINS) set(SYCL_BUILD_BACKEND_HIP ON) - set(SYCL_EXT_ONEAPI_BACKEND_HIP ON) endif() if ("opencl" IN_LIST SYCL_ENABLE_PLUGINS) set(SYCL_BUILD_BACKEND_OPENCL ON) @@ -185,6 +183,11 @@ if ("native_cpu" IN_LIST SYCL_ENABLE_PLUGINS) set(SYCL_BUILD_BACKEND_NATIVE_CPU ON) endif() +# Set backend macros based on whether we can compile kernels for the target +# rather than if we're building the runtime adapter. +set(SYCL_EXT_ONEAPI_BACKEND_CUDA ${LLVM_HAS_NVPTX_TARGET}) +set(SYCL_EXT_ONEAPI_BACKEND_HIP ${LLVM_HAS_AMDGPU_TARGET}) + # Configure SYCL version macro set(sycl_inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include) set(sycl_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/source)