**Hello, I´m trying to code a kernel using opencl. But Im stuck with a stranger error inside of the kernel function. The flow is more or less like this:
__kernel function1() {
struct mytype;
function2(&mytype);
}
function2(struct *mytype) {
uchar *ptr = mytype->value2;
function3(ptr);
}
function3(byte* ptr) {
uint16 v1 = 10;
uint16* ptr2 = (uint16*) ptr;
*ptr2 = v1 >> 8;
}
struct mytype {
uchar value1[8];
uchar value2[8];
uint key[52];
uint bufleft;
}
The code fails when executing the assignment:
*ptr2 = v1 >> 8;
But the only message I receive is "clFlush(): CL_UNKNOWN_ERROR" If I try to assign a value and not an expression, than it works. I´m using OpenCL 1.2 CUDA in Ubuntu
I think this might be undefined behaviour; if you need to reference the same memory as 2 different types, use a union type. Note that uint16 is a vector of 16 uints, not a ushort (16-bit unsigned integer), and needs to be aligned accordingly. value2
is only guaranteed to be aligned on a 4-byte boundary (because of the uint
members of the struct) so this won't be enough.