This is my SYCL program on windows to check if SYCL works fine in my system
#include <iostream>
#include <cl/sycl.hpp>
#include <Windows.h>
int main()
{
int array[5];
{
sycl::buffer<int,1> int_buffer(array, sycl::range<1>(5));
std::cout << "Buffer created" << std::endl;
sycl::queue queue(sycl::gpu_selector_v); //This is the line that is causing the error
std::cout << "Queue created" << std::endl;
queue.submit([&](sycl::handler &cgh) {
sycl::accessor<int, 1, sycl::access::mode::read_write> b(int_buffer, cgh);
cgh.parallel_for(sycl::range<1>(5),[=](sycl::id<1> id){
b[id] = id;
});
});
std::cout << "Command submitted" << std::endl;
queue.wait();
}
std::cout << "Task finished" << std::endl;
for (auto& a : array)
{
std::cout << a;
}
return 0;
}
It was compiled with the command
icpx -std=c++20 -fsycl -fsycl-targets=spir64_gen -MD -o main.exe main.cpp -g -O0 -Xsycl-target-backend=spir64_gen "-device gen9-"
But when I compiled and debug it with oneapi gdb debugger this program it just crashes, saying that an exception was thrown.
(gdb) run gpu
Starting program: A:\game\SG\SYCL practising\main.exe gpu
[New Thread 11972.0x2e0c]
[New Thread 11972.0x2e00]
[New Thread 11972.0x2cec]
Buffer created
[New Thread 11972.0x2bd8]
[New Thread 11972.0x243c]
[Thread 11972.0x2e0c exited with code 0]
[Thread 11972.0x2cec exited with code 0]
[Thread 11972.0x2e00 exited with code 0]
[New Thread 11972.0x2b40]
[New Thread 11972.0x29c8]
[New Thread 11972.0x6a4]
[New Thread 11972.0x2680]
gdb: unknown target exception 0xe06d7363 at 0x7ffbee4cb699
Thread 1 received signal ?, Unknown signal.
0x00007ffbee4cb699 in RaiseException () from C:\Windows\System32\KernelBase.dll
This has to be with creating a queue as Queue created was not printed.
But I make the slight change of using cpu selectors instead my program works completely fine and it gives me the expected result
01234
In case anyone wants to know the devices on my system (given by sycl-ls) are
[opencl:gpu:0] Intel(R) OpenCL, Intel(R) HD Graphics 500 1.2 [22.20.16.4708]
[opencl:cpu:1] Intel(R) OpenCL, Intel(R) Celeron(R) CPU J3355 @ 2.00GHz 3.0 [2023.16.6.0.28_042959]
[opencl:acc:2] Intel(R) FPGA Emulation Platform for OpenCL(TM), Intel(R) FPGA Emulation Device 1.2 [2023.16.6.0.28_042959]
It clearly shows I have a working gpu device
Overall, I was expecting the output 01234 but instead I got an unexpected exception thrown by KernelBase.dll
arrayare unspecified while the buffer exists. You can use{}to limit the scope of the buffer, and then when the buffer goes out of scope it will make sure that reults are copied back toarray. You can drop thequeue.wait(): the buffer will do the wait automatically when it's destructor is called.0xe06d7363is just SEH code for C++ exceptions (see Raymond Chen's article). Did you try totry {...} catch (const std::exception& ex) { std::cout << ex.what() << std::endl; }, to see the description of exception being thrown?q.wait();there is redundant) so that the buffer object gets destructed at the end of it. The destructor takes care of synchronization, see documentation.