Issue
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.
Solution
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.
Answered By - Joe Todd Answer Checked By - Mildred Charles (WPSolving Admin)