Cmake file for sycl CUDA backend

190 views Asked by At

I am having trouble writing a CMake file to offload SYCL code to the NVIDIA backend. My CMake file currently looks like this

cmake_minimum_required(VERSION 3.22.1)
set(CMAKE_C_COMPILER /opt/intel/oneapi/compiler/latest/linux/bin/icx)
set(CMAKE_CXX_COMPILER /opt/intel/oneapi/compiler/latest/linux/bin/icpx)
project(HELLOESycl)

set(SYCL_FLAGS "-fsycl"
      "-fsycl-targets=nvptx64-nvidia-cuda"
      "-fsycl-unnamed-lambda"
      "-Wno-linker-warnings")
FIND_PACKAGE(IntelSYCL REQUIRED)

ADD_EXECUTABLE(${PROJECT_NAME} ${CMAKE_SOURCE_DIR} test1.cpp)

TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC sycl ${SYCL_FLAGS})
target_compile_options(${PROJECT_NAME} PUBLIC ${SYCL_FLAGS})
ADD_SYCL_TO_TARGET(TARGET ${PROJECT_NAME} SOURCES ${CMAKE_SOURCE_DIR} test1.cpp)

The error message is

terminate called after throwing an instance of 'sycl::_V1::runtime_error'
  what():  Native API failed. Native API returns: -42 (PI_ERROR_INVALID_BINARY) -42 (PI_ERROR_INVALID_BINARY)
Aborted

The code can be compiled and executed with the following command in the terminal, so the problem is not with the code

dpcpp -fsycl -fsycl-targets=nvptx64-nvidia-cuda test1.cpp -o test

correct the cmakefile so it offload code to nvidia hardware.

2

There are 2 answers

2
Joe Todd On BEST ANSWER

I think you are running afoul of CMake string concatenation rules. Your ${SYCL_FLAGS} is actually:

-fsycl-fsycl-targets=nvptx64-nvidia-cuda-fsycl-unnamed-lambda-Wno-linker-warnings

Try putting a space after each one.

0
peizhao qiu On

The issue lies with the SYCL compilation options (SYCL_FLAGS). When you use find_package(IntelSYCL), it can potentially overwrite the SYCL_FLAGS to use the -fsycl flag, which is specific to the Intel SYCL implementation. As a result, it may prevent SYCL from using the NVIDIA backend through the -fsycl-targets=nvptx64-nvidia-cuda flag.