Cl::sycl::invalid_object_error on Intel UHD Graphics

Hi all!

I would like to switch my GPGPU work to SYCL, but I am running into some issues. I am following the codeplay tutorial, and although the code compiles just fine, I get a runtime error when submitting my command to the queue:

Running on Intel(R) Gen9 HD Graphics NEO
terminate called after throwing an instance of 'cl::sycl::invalid_object_error'

I am running Arch linux and would like to use my Intel iGPU (UHD Graphics 620 / Core i7-8550U). I am using the Neo OpenCL runtime. This is what I get when running computecpp_info:

$ computecpp_info  
********************************************************************************
ComputeCpp Info (CE 1.3.0)
SYCL 1.2.1 revision 3
********************************************************************************
Toolchain information:
GLIBC version: 2.31
GLIBCXX: 20160609
This version of libstdc++ is supported.
********************************************************************************
Device Info:
Discovered 1 devices matching:
  platform    : <any>
  device type : <any>
--------------------------------------------------------------------------------
Device 0:
  Device is supported                     : UNTESTED - Untested OS
  Bitcode targets                         : spir64 spirv64 
  CL_DEVICE_NAME                          : Intel(R) Gen9 HD Graphics NEO
  CL_DEVICE_VENDOR                        : Intel(R) Corporation
  CL_DRIVER_VERSION                       : 1.0.0
  CL_DEVICE_TYPE                          : CL_DEVICE_TYPE_GPU 

Looking at this topic, it might be a setup issue. Just in case, here is my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.15)

project(SYCLtest LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
find_package(ComputeCpp REQUIRED)

add_executable(SYCLtest)

target_sources(SYCLtest 
    PRIVATE 
        main.cpp
)

target_compile_features(SYCLtest PRIVATE cxx_std_17)

target_link_libraries(SYCLtest PRIVATE ComputeCpp::ComputeCpp)

I copied the FindComputeCpp.cmake and other CMake utilities in a cmake/ folder. The configuration runs ok, and I get:

[cmake] -- ...
[cmake] -- Looking for CL_VERSION_2_2
[cmake] -- Looking for CL_VERSION_2_2 - found
[cmake] -- Found OpenCL: /usr/lib/libOpenCL.so (found version "2.2")
[cmake] -- platform - your system can support ComputeCpp
[cmake] -- Found ComputeCpp: /opt/ComputeCpp-CE (found version "CE 1.3.0")
[cmake] -- compute++ flags - -O2;-mllvm;-inline-threshold=1000;-intelspirmetadata;-sycl-target;spir64
[cmake] -- Configuring done
[cmake] -- Generating done

Is there something I am missing? Thank you for your help!

Hi Joachim,
It looks like you are missing the
add_sycl_to_target step in your CMake file.

See the samples for an example

I’d also note that if you catch exceptions you would get more detailed error information on this, there is a guide here on how to add that to your code.

If that doesn’t help it would be good to see your CMake file and source or the generated .sycl file. I assume you have compiled and run the samples from GitHub successfully?

Hi Rod, and thank you for the answer.

Indeed, I simply called target_link_libraries(MyTarget PRIVATE ComputeCpp::ComputeCpp), assuming that would be enough (note that the CMake code I included in my original post is the entire CMakeLists.txt file. That’s all there is to it). I did not realize there was another function that was doing that + some other stuff. I guess that makes sense since the compilation process is quite different for SYCL and standard C++. I will try the add_sycl_to_target function asap and get back to you.

However, this begs the question: is there some work going on to fully integrate SYCL in CMake, just like CUDA? It would be nice to use only standard CMake features to compile my programs.

I did not see the tutorial on exceptions, as it follows the one I was trying to run. If the fix above does not work, I’ll get to it to extract more detailed error information.

Hi Joachim,
I hope that solves your problem.
We don’t have any current plans for a full integration with CMake but we are discussing how to make it easier to set things up to compile with the appropriate flags and options. Your example helps with that.
We’ve also been discussing how we might be able to output a better error on this scenario to make it more obvious how to fix it, again your input has helped with that so thank you.
Rod.

If you’re happy to use compute++ as your host compiler as well as device compiler (which is similar to what the CUDA CMake integration does with nvcc, if I remember correctly), you can add the -sycl-driver flag to your arguments and the add_sycl_to_target step isn’t needed.

Using add_sycl_to_target worked like a charm, thanks Rod!

Duncan, I am not sure I understand where to use this -sycl-driver flag. I can’t be passing that to the compiler because it would already be too late by then. Is there some kind of CMake variable I should be setting to activate something in ComputeCpp?

The add_sycl_to_target function invokes the compiler we distribute (compute++) on the source files in the target you specify. You can instead tell CMake to use compute++ as the host compiler, then add that flag to every file with a kernel in it. You can do this with something like

find_project(ComputeCpp REQUIRED)
set(CMAKE_CXX_COMPILER ${ComputeCpp_DEVICE_COMPILER_EXECUTABLE})

add_executable(foo foo.cc)
set_properties(TARGET foo APPEND COMPILE_FLAGS -sycl-driver)
target_link_libraries(foo PRIVATE ComputeCpp::ComputeCpp)

Something like that. I’m afraid that’s totally untested but might be closer to what you’re looking for. If you check the integration guide on our website (which should also be distributed with the package) there’s some information on what the compilation model is and how you can choose to integrate with it.

Just to add to this thread there is some information in one of our guides about using CMake and makefiles here.

I’ve started to gather some notes and will try to create a more prominent section to try to help people that have problems when getting started.