computecpp-sdk
computecpp-sdk copied to clipboard
Error when running SYCL program with ComputeCpp on CMake : 'cl::sycl::invalid_object_error'
I have been using ComputeCPP successfully, however after a restart I have started receiving this error without further clarification, even on the basic vector addition sample.
I am using ComputeCPP with CMake. Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(cmptcpp_test)
set(CMAKE_CXX_STANDARD 14)
set(ComputeCpp_DIR /opt/ComputeCpp-CE)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
include(FindComputeCpp)
include_directories(${COMPUTECPP_INCLUDE_DIRECTORY})
find_package(ComputeCpp REQUIRED)
add_executable(cmptcpp_test main.cpp)
add_sycl_to_target(TARGET ${PROJECT_NAME} main.cpp)
and here is the content of main.cpp:
#include <iostream>
#include <CL/sycl.hpp>
namespace sycl = cl::sycl;
int main() {
sycl::float4 a = {1.0, 2.0, 3.0, 4.0};
sycl::float4 b = {4.0, 3.0, 2.0, 3.0};
sycl::float4 c = {.0, 0.0, 0.0, 0.0};
sycl::default_selector device_selector;
sycl::queue queue(device_selector);
std::cout << "Running on "
<< queue.get_device().get_info<sycl::info::device::name>()
<< "\n";
sycl::buffer<sycl::float4, 1> a_sycl(&a, sycl::range<1>(1));
sycl::buffer<sycl::float4, 1> b_sycl(&b, sycl::range<1>(1));
sycl::buffer<sycl::float4, 1> c_sycl(&c, sycl::range<1>(1));
queue.submit([&] (sycl::handler& cgh) {
auto a_acc = a_sycl.get_access<sycl::access::mode::read>(cgh);
auto b_acc = b_sycl.get_access<sycl::access::mode::read>(cgh);
auto c_acc = c_sycl.get_access<sycl::access::mode::discard_write>(cgh);
cgh.single_task<class vector_addition>([=] () {
c_acc[0] = a_acc[0] + b_acc[0];
});
});
std::cout << " A { " << a.x() << ", " << a.y() << ", " << a.z() << ", " << a.w() << " }\n"
<< "+ B { " << b.x() << ", " << b.y() << ", " << b.z() << ", " << b.w() << " }\n"
<< "------------------\n"
<< "= C { " << c.x() << ", " << c.y() << ", " << c.z() << ", " << c.w() << " }"
<< std::endl;
return 0;
}
Here is the output of computecpp_info :
********************************************************************************
ComputeCpp Info (CE 1.3.0)
SYCL 1.2.1 revision 3
********************************************************************************
Toolchain information:
GLIBC version: 2.33
GLIBCXX: 20160609
This version of libstdc++ is supported.
********************************************************************************
Device Info:
Discovered 2 devices matching:
platform : <any>
device type : <any>
--------------------------------------------------------------------------------
Device 0:
Device is supported : UNTESTED - Untested OS
Bitcode targets : ptx64
CL_DEVICE_NAME : GeForce GTX 1070 Ti
CL_DEVICE_VENDOR : NVIDIA Corporation
CL_DRIVER_VERSION : 460.39
CL_DEVICE_TYPE : CL_DEVICE_TYPE_GPU
--------------------------------------------------------------------------------
Device 1:
Device is supported : UNTESTED - Untested OS
Bitcode targets : spir64
CL_DEVICE_NAME : AMD Ryzen 7 1700 Eight-Core Processor
CL_DEVICE_VENDOR : AuthenticAMD
CL_DRIVER_VERSION : 1800.8 (sse2,avx)
CL_DEVICE_TYPE : CL_DEVICE_TYPE_CPU
If you encounter problems when using any of these OpenCL devices, please consult
this website for known issues:
https://computecpp.codeplay.com/releases/v1.3.0/platform-support-notes
********************************************************************************
I get this error both on the using default_selector and cpu_selector.
@rasmysamy could you please post here the complete command used to build your project? You can get this by running make VERBOSE=1 if using makefiles or ninja -v if using ninja.
Here is the output of make VERBOSE=1:
/usr/bin/cmake -S/home/username/CLionProjects/cmptcpp-test -B/home/username/CLionProjects/cmptcpp-test --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/username/CLionProjects/cmptcpp-test/CMakeFiles /home/username/CLionProjects/cmptcpp-test//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/username/CLionProjects/cmptcpp-test'
make -f CMakeFiles/cmptcpp_test.dir/build.make CMakeFiles/cmptcpp_test.dir/depend
make[2]: Entering directory '/home/username/CLionProjects/cmptcpp-test'
cd /home/username/CLionProjects/cmptcpp-test && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/username/CLionProjects/cmptcpp-test /home/username/CLionProjects/cmptcpp-test /home/username/CLionProjects/cmptcpp-test /home/username/CLionProjects/cmptcpp-test /home/username/CLionProjects/cmptcpp-test/CMakeFiles/cmptcpp_test.dir/DependInfo.cmake --color=
Dependee "/home/username/CLionProjects/cmptcpp-test/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/username/CLionProjects/cmptcpp-test/CMakeFiles/cmptcpp_test.dir/depend.internal".
Scanning dependencies of target cmptcpp_test
make[2]: Leaving directory '/home/username/CLionProjects/cmptcpp-test'
make -f CMakeFiles/cmptcpp_test.dir/build.make CMakeFiles/cmptcpp_test.dir/build
make[2]: Entering directory '/home/username/CLionProjects/cmptcpp-test'
[ 50%] Building CXX object CMakeFiles/cmptcpp_test.dir/main.cpp.o
/usr/bin/c++ -isystem /opt/ComputeCpp-CE/include -g -std=gnu++14 -o CMakeFiles/cmptcpp_test.dir/main.cpp.o -c /home/username/CLionProjects/cmptcpp-test/main.cpp
In file included from /usr/include/CL/cl.h:20,
from /opt/ComputeCpp-CE/include/SYCL/include_opencl.h:34,
from /opt/ComputeCpp-CE/include/SYCL/common.h:21,
from /opt/ComputeCpp-CE/include/SYCL/cl_types.h:23,
from /opt/ComputeCpp-CE/include/SYCL/deduce.h:25,
from /opt/ComputeCpp-CE/include/SYCL/cpp_to_cl_cast.h:12,
from /opt/ComputeCpp-CE/include/SYCL/sycl_builtins.h:27,
from /opt/ComputeCpp-CE/include/CL/../SYCL/sycl.hpp:20,
from /opt/ComputeCpp-CE/include/CL/sycl.hpp:1,
from /home/username/CLionProjects/cmptcpp-test/main.cpp:2:
/usr/include/CL/cl_version.h:22:104: note: ‘#pragma message: cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)’
22 | #pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)")
| ^
[100%] Linking CXX executable cmptcpp_test
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmptcpp_test.dir/link.txt --verbose=1
/usr/bin/c++ -g CMakeFiles/cmptcpp_test.dir/main.cpp.o -o cmptcpp_test -Wl,-rpath,/opt/ComputeCpp-CE/lib /opt/ComputeCpp-CE/lib/libComputeCpp.so /usr/lib/libOpenCL.so
make[2]: Leaving directory '/home/username/CLionProjects/cmptcpp-test'
[100%] Built target cmptcpp_test
make[1]: Leaving directory '/home/username/CLionProjects/cmptcpp-test'
/usr/bin/cmake -E cmake_progress_start /home/username/CLionProjects/cmptcpp-test/CMakeFiles 0
I noticed that there isn't a call to compute++ in your list of commands, so I went back to your CMake and I remember that you need to add SOURCES in add_sycl_to_target, so it should be like this
add_sycl_to_target(TARGET ${PROJECT_NAME} SOURCES main.cpp)
You can see an example of this here in CMakeLists.txt
That did indeed do the trick. I'm still having some issues with Qt/fPIC but that might be something I can fix myself. In any case, the syntax you have presented now doesn't match this documentation page : https://developer.codeplay.com/products/computecpp/ce/guides/integration-guide#UsingCmake
It might also be useful to add an error message to FindComputeCpp.
Good catch, we will try to fix the documentation as soon as possible.
It might also be useful to add an error message to FindComputeCpp.
This is a tricky one because add_sycl_to_target is also used to link the ComputeCpp runtime into the specified target and there are cases where you don't need to call compute++ in a source file, but you still want to link the runtime so that is still a valid use case