Float4 usage



I have been reading about the float4 usage in opencl and why it is to prefer over the normal float in some cases.

I cant figure out how to generate the float4 input in java and use jocl where the kernel argument is float4 data.

Does anyone know how to generate float4 input in java with jocl?





In the simplest case, a float4 is just 4 floats. So when you have a kernel that receives a [inline]float4[/inline] as one argument, you can just pass in a 4-element float array:
[inline]clSetKernelArg(kernel, a++, Sizeof.cl_float4, Pointer.to(new float[] { 1,2,3,4}));[/inline]

For arrays of (i.e. pointers to) [inline]float4[/inline], you can analogously create a [inline]cl_mem[/inline] with the desired size, e.g. [inline]count * Sizeof.cl_float4[/inline].

Of course, handling a [inline]float[n*4][/inline] array on Java side is not as convenient as handling an array of [inline]cl_float4[/inline] in C. But that’s hard to avoid. I once created utlities that, to some extent, allow “emulating” [inline]float4[/inline] as “structs”, at jocl.org - Utilities . But you should not consider this as a stable, universally applicable solution. There may be options to make the handling of something-like-a-[inline]float4[/inline] in Java more convenient, but these will depend on the application case.




Ok, that simple :slight_smile:

Thanks for the help, Ill try it when I get home