Results 1 to 3 of 3

Thread: Global Arrays in OpenCL

  1. #1
    Member
    Join Date
    Mar 2010
    Location
    Raleigh, NC
    Posts
    55

    Global Arrays in OpenCL

    Hello,

    I am trying to find an example somewhere to let me know if this theory of mine is plausible or not. I have an OpenCL program consisting of multiple kernels that use multiple arrays, several of which are constant throughout the entire run of the program. I am comfortable setting up the arrays and passing them to the device using either

    Code :
    cl_mem clbMemA = clCreateBuffer(oclContext, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(cl_float4)*(size), HostMemA, &oclError);
     
    or
     
    oclError= clEnqueueWriteBuffer(oclCmdQueue, clbMemA, CL_FALSE, 0, sizeof(cl_float4)*(size), HostMemA, 0, NULL, NULL);

    I then would use the clSetKernelArg to set the argument for the kernel. This is pretty standard.

    However, I am wondering if it is possible to write an OpenCL program that has, generally, the following form:

    Code :
    __global const float2 *Points;
     
    __kernel void CalcSomething(__global float *Values)
    {
    int i = get_global_id(0);
    int j = get_global_id(1);
    Values[i] = Points[i].x + Points[j].y;
    }
     
    __kernel void CalcSomethingElse(__global float *Values)
    {
    int i = get_global_id(0);
    int j = get_global_id(1);
    Values[j] = Points[j].x+Points[i].y;
    }

    Obviously, the code doesn't do anything important -it is just a sample, but can I declare "Points" outside of the kernel, and then use either clEnqueueWriteBuffer to store an array (allocated on the host) there? If so, how would I go about doing that?

    The reason I ask is that I have four or five kernels that use the same five or six constant arrays throughout the course of obtaining a solution, and it would be convenient to only have to set them up once, instead of as an additional argument for every kernel.

    Thank you in advance!

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Global Arrays in OpenCL

    However, I am wondering if it is possible to write an OpenCL program that has, generally, the following form
    I'm afraid that's not allowed by the spec. Variables at global scope have to be constants.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3
    Member
    Join Date
    Mar 2010
    Location
    Raleigh, NC
    Posts
    55

    Re: Global Arrays in OpenCL

    That would explain why I could not find any examples

    Thank you again!

Similar Threads

  1. global work offset in OpenCL 1.1
    By dominik in forum OpenCL
    Replies: 2
    Last Post: 01-13-2011, 01:13 AM
  2. Global variables in OpenCL
    By Considerate in forum OpenCL
    Replies: 1
    Last Post: 05-03-2010, 03:12 PM

Posting Permissions

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