I have an OpenCL kernel code, which does not behave as expected. The similar C code compiled with gcc works fine.
struct data {
short* a;
};
typedef struct data Data;
inline void foo(Data* d) {
short b[1] = {99};
d->a = b;
}
__kernel void bar(__global short* output) {
Data d;
foo(&d);
short val = d.a[0];
int id = get_global_id(0);
output[id] = val;
}
Always outputs [0, 0, ..., 0]
.
If I initialize d.a
in __kernel bar
and only assign d->a[0] = 99
in foo
it works as expected and outputs [99, 99, ..., 99]
Thanks in advance!
UPDATE:
I'm using Java and JOCL for the host code.
As ScottD suggested I've changed d->a = b;
in function foo
to *d->a = *b;
.
And it works great in C version. But causes the following error for OpenCL on MacOS:
Exception in thread "main" org.jocl.CLException:
CL_BUILD_PROGRAM_FAILURE Build log for device 0:
CVMS_ERROR_COMPILER_FAILURE: CVMS compiler has crashed or hung building an element.
at org.jocl.CL.clBuildProgram(CL.java:9368)
...
Or a JVM termination on Windows with AMD CPU:
# A fatal error has been detected by the Java Runtime Environment:
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007fedfeb007a, pid=3816, tid=4124
# JRE version: 7.0-b147
# Java VM: Java HotSpot(TM) 64-Bit Server VM (21.0-b17 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [amdocl64.dll+0x60007a]