Results 1 to 2 of 2

Thread: how can I load arrays to constant memory space

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    27

    how can I load arrays to constant memory space

    I'm confused about how to load read-only array values into the device constant memory space versus global memory space. The moderately sized array nodes_x in the below kernel meets all the criteria such that some hardware should perform better if the array is loaded to constant memory instead of global memory.

    Code :
    __kernel void sequenceKernel_00(  constant const float * nodes_x, global float * const restrict density_n)
    { /* etc. */ }

    My code already works with the first nodes_x argument being declared global. I have been passing the flag CL_MEM_READ_ONLY to clCreateBuffer().
    I'm surprised that clCreateBuffer() does not take an additional argument that specifies the desired memory space.

    So, it seems insufficient to me, that all I have to change to move nodes_x array into constant memory is the kernel argument declaration from global to constant.

    As an experiment, I changed the flag for my nodes_x buffer creation to CL_MEM_WRITE_ONLY. Nevertheless, clSetKernelArg() still reports CL_SUCCESS when setting the constant nodes_x argument to that buffer. This is clearly wrong and makes me think I'm missing something.

    Since cl_buffers are created independent of a particular kernel, and clEnqueueWriteBuffer() can be called before clSetKernelArg(), I don't see how any late-binding can be in play

    (running Mac OS X 10.8 and an NVIDIA Tesla GPU)

  2. #2

    Re: how can I load arrays to constant memory space

    Quote Originally Posted by noah_r
    So, it seems insufficient to me, that all I have to change to move nodes_x array into constant memory is the kernel argument declaration from global to constant.
    But it is. When the kernel is executed and the memory object is larger than CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, you will get an error. Moreover, if you specify CL_MEM_WRITE_ONLY you'll get "undefined behaviour" as per section 5.2.1 of the OpenCL 1.1 specification.

Similar Threads

  1. address space qualifiers and pointers to arrays
    By romein in forum Interoperability issues
    Replies: 4
    Last Post: 11-14-2012, 08:27 PM
  2. Load texture via streaming from user space buffer
    By john_q61 in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 10-19-2010, 09:10 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
  •