cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

Mimics "va_list" in OpenCL

Hi,

I would like to be able to write some methods like this. I need a way to manage "dynamic parameters" like we do with va_list ...

I know that internally you do this (with printf) but can we use this feature in OpenCL kernels ?

 

Thanks

 

Shading() { floaf f = Integrate(scene, 0, Kd); } float4 Integrate(Scene* scene, int type, ...) { float4 f; switch(type) { case 0: f = closure_diffuse(scene, ...); break; case 1: f = closure_refraction(scene, ...); break; case 2: f = closure_reflection(scene, ...); break; } return f; } closure_diffuse(scene, float4 Kd) { } closure_refraction(scene, float eta) { } closure_reflection(scene, float etai, float etao) { }

0 Likes
6 Replies
nou
Exemplar

what about union as parameter?

0 Likes

Thanks nou,

It is the way I do now ! But it is not always easy to use 😛

0 Likes

nou,

Can you explain how va_list is implemented using unions.

viewon01,

As per openCL spec stdarg is not supported.

 

"The library functions defined in the C99 standard headers

assert.h, ctype.h, complex.h, errno.h, fenv.h, float.h, inttypes.h, limits.h, locale.h, setjmp.h, signal.h, stdarg.h, stdio.h, stdlib.h, string.h, tgmath.h, time.h, wchar.h and wctype.h are not available"





0 Likes

of course not arbitrary number of arguments.

but create struct for each set of parameters. then put this structs into one union.

0 Likes

Got it.

Thanks Nou

0 Likes

Since OpenCL allows you to compile kernels at runtime, one thing you can do is write the function at runtime with the appropriate number of arguments, compile it, and run it. This allows an arbitrary (within driver limitations) number of parameters.

0 Likes