Results 1 to 4 of 4

Thread: Passing scalar values to kernel

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    2

    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.

    The kernel code looks like: (pg 295)
    reduce(__global float *output, __global const float *input,
    __local float *shared, unsigned int n)

    The host code looks like: (pg 302)
    err |= clSetKernelArg(kernels[i], 3, sizeof(int), &entries);

    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.

    Link to specification:
    http://www.khronos.org/registry/cl/spec ... 1.0.33.pdf

    Thanks in advance.

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: Passing scalar values to kernel

    Quote Originally Posted by starapor
    I am trying to learn how an openCL implementation knows that the variable is a scalar value and not a pointer.
    OpenCL has to compile the program first, so it has all necessary information about any kernel.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    Feb 2009
    Posts
    2

    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.

  4. #4
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: Passing scalar values to kernel

    Quote 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.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

Similar Threads

  1. Replies: 1
    Last Post: 02-22-2010, 01:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •