Results 1 to 2 of 2

Thread: Pass scalars to kernel and avoid creating CLBuffer each time

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    29

    Pass scalars to kernel and avoid creating CLBuffer each time

    I have to execute a kernel many times where the only change is that two buffer are exchanged and one is updated before the call: For example the first call would be
    Code :
    myContext.program.myKernel(
        myContext.queue,
        (NThreads,),
        None,
        bufferA,
        bufferB,
        bufferState)

    and the next

    Code :
    myContext.program.myKernel(
        myContext.queue,
        (NThreads,),
        None,
        bufferB,
        bufferA,
        bufferState)

    but bufferState contains actually only one interger which is increased by 1 each call. Can I somehow avoid creating a new clBuffer each time to pass this integer? All threads have to be sychron. So increasing this integer inside the kernel each call is not possible due to asynchron access.

    I'm also wondering if I can pass only scalar values instead of arrays. Up to now I create a numpy array, then a clBuffer and after passing it to the kernel I extract the scalar out of the array inside the kernel. This seems a bit to much effort. Maybe this is specific to pyopencl, I don't know.

  2. #2
    Junior Member
    Join Date
    Mar 2012
    Posts
    29

    Re: Pass scalars to kernel and avoid creating CLBuffer each

    Ok, I found a solution and it didn't speed up anything.

    Anyway: To pass only a variable instead of a whole array when using pyopencl one has to use the numpy datatypes. Example:
    Code :
    __kernel void foo(int x, int y)
    {
        y = x + 1;
    }
    To call this kernel in python one has to write:
    Code :
    x = 17
    y = 14
    program.foo(queue, (1,), None, numpy.int32(x), numpy.int32(y))
    The ushort corresponds to numpy.int16 and so on ...

Similar Threads

  1. How to pass complex structures to kernel?
    By chanakya.sun in forum OpenCL
    Replies: 2
    Last Post: 07-22-2011, 04:21 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
  •