3

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

12
  • 1
    Not related to your exception, but your code is not correct. The buffer constructed from a pointer "assumes exclusive access to this memory for the duration of its lifetime", so the content of array are 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 to array. You can drop the queue.wait(): the buffer will do the wait automatically when it's destructor is called. Commented May 17 at 11:51
  • @aland Should I put buffer inside the kernel so after all the tasks the buffer gets destructed, to copy contents back to the host? Commented May 18 at 3:21
  • 0xe06d7363 is just SEH code for C++ exceptions (see Raymond Chen's article). Did you try to try {...} catch (const std::exception& ex) { std::cout << ex.what() << std::endl; }, to see the description of exception being thrown? Commented May 18 at 3:42
  • 1
    As for the buffer question, no, buffer has to be defined outside of kernel and CGH. You can introduce scope (like in this example, except that 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. Commented May 18 at 3:53
  • @YurkoFlisk I didn't try try-catch earlier just because of seeing the exception being thrown from KernelBase.dll. I didn't knew before Win32 DLLs could raise C++ exceptions. Now I've tried updating the driver and code is working properly Commented May 18 at 5:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.