I'd like to run a parallel for loop to initialize a 2 dimensional buffer with random values. But I get an EXC_BAD_ACCESS (code=EXC_I386_GPFLT) exception in the first line of the kernel.
This is the Code (the Pixel struct is from the PixelGameEngine Library):
namespace olc
{
struct Pixel
{
union
{
uint32_t n = nDefaultPixel;
struct
{
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
};
enum Mode
{
NORMAL, MASK, ALPHA, CUSTOM
};
Pixel()
{
r = 0;
g = 0;
b = 0;
a = nDefaultAlpha;
}
Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = nDefaultAlpha)
{
n = red | (green << 8) | (blue << 16) | (alpha << 24);
}
Pixel(uint32_t p) { n = p; }
};
}
int main()
{
auto* screenBuffer = new olc::Pixel[256 * 240];
cl::sycl::queue queue;
{
cl::sycl::buffer<olc::Pixel, 2> b_screenBuffer(screenBuffer,
cl::sycl::range<2>(256, 240));
queue.submit([&](cl::sycl::handler& cgh) {
auto screenBuffer_acc = b_screenBuffer.get_access<cl::sycl::access::mode::write>(cgh);
cgh.parallel_for(cl::sycl::range<2>(256, 240), [&](cl::sycl::id<2> index) {
screenBuffer_acc[index] = olc::Pixel(rand() % 256, //Here I get the exception
rand() % 256,
rand() % 256);
});
});
}
return 0;
}
I'm using triSYCL 0.1.0 on Mac OS Catalina with boost 1.74 and C++20. I've tried to change the data type of the buffer from old::Pixel to float and to make the buffer 1 dimensional but I always got the same exception. Does anybody have an idea what I could try?