The Khronos Group - a non-profit industry consortium to develop, publish and promote open standard, royalty-free media authoring and acceleration standards for desktop and handheld devices, combined with conformance qualification programs for platform and device interoperability.

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Passing scalar values to kernel

Hi,
While evaluating the reduction example in the specification one of the values is passed as a scalar value instead of a pointer. I am trying to learn how an openCL implementation knows that the variable is a scalar value and not a pointer.

How does the OpenCL clSetKernelArg command know that the kernel 4th kernel argument is passed as an unsigned int and should be placed directly in a register for use by the kernel rather than being placed in global memory and read in by each thread?

The clSetKernelArg command is identical to the previous 3 commands which are passing blocks of memory yet somehow, this clSetKernelArg command knows to place the value that &entries points to in unsigned int 'n' but in the other clSetKernelArg commands, 'output' and 'input' are set to pointers that point to the global memory location that hold the values of what is passed.

Re: Passing scalar values to kernel

I agree the compiler has all the necessary information, but how does it distinguish that an argument passed using clSetKernelArg (which takes the memory address) should be interpreted as a scalar value (in this case unsigned int) and not a reference to some buffer (in this case a buffer containing unsigned ints).

This is confusing to me because the usage of clSetKernelArgs for scalar values and buffers of memory is identical but there must be a determination to pass a value or pass an address when the kernel function is invoked at run time. My question is how is that determination made? Thanks.

Re: Passing scalar values to kernel

Originally Posted by starapor

I agree the compiler has all the necessary information, but how does it distinguish that an argument passed using clSetKernelArg (which takes the memory address) should be interpreted as a scalar value (in this case unsigned int) and not a reference to some buffer (in this case a buffer containing unsigned ints).

The compiler stores information about the signature of each kernel with the program object. clSetKernelArg simply looks up that information, so it knows the type of the parameters at each index. And it also knows the number of arguments so it can raise an error when you pass an invalid index.