Im going to write a kernel which will be quite complex, can I separate it to several kernels that can invoke each other?
when I compile the following sample code, there is an error which i dont understand
error: illegal implicit cast between two pointers with different address spaces
Yes, you can have a kernel function call another kernel function. You can also call non-kernel functions.
The error code you see is because in OpenCL each variable stays in one of the four possible memory address spaces: global, local, private and constant. They are explained in section 6.5 of the OpenCL 1.1. spec.
You can try something like this:
void B(__private float *b) {
//do something
}
kernel void A () {
float b; // "b" by default is in private memory
B(&b);
}
Also notice that recursive function calls are not allowed. I say this because it looks like you are trying to implement a ray-tracing engine on OpenCL and simple ray-tracing engines are recursive.
Thank you david, yes I am writing the ray tracing engine, I have written a non-recursive C implementation and now need to implement with OpenCL, one kernel function is too complicated and lots of duplicated code.
Regarding to the previous post, when I assign a value in the device function B, the value does not update in the kernel A, which i dont know why:
void B(__private float *b) {
//do something
// if say b = 1, when I find b in kernel A, the value is still 0
*b = 1;
}
kernel void A () {
float b; // "b" by default is in private memory
B(&b);
}