Results 1 to 4 of 4

Thread: creating objects in shared memory

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    26

    creating objects in shared memory

    Hi all,
    I need to create an array in shared memory so that it could be accessed by all my program threads and they could perform computations on it or search for some value in it...
    how can I do this?
    I thought of something like writing a kernel function that creates initializes this array in the shared memory (__local)... then calling my main kernel function (another kernel) afterwards that would work on this array... is this feasible? if so how can I do this?

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

    Re: creating objects in shared memory

    I thought of something like writing a kernel function that creates initializes this array in the shared memory (__local)... then calling my main kernel function (another kernel) afterwards that would work on this array... is this feasible?
    __local memory is not persistent across multiple calls to clEnqueueNDRangeKernel(), so it's not possible to initialize __local memory with one NDRange and then perform some computation with another NDRange.

    However, what you can do is create a kernel function that calls into two functions: the first one to initialize the __local storage and the second one to perform the actual computation.

    It would look something like this:

    Code :
    void initLocalMem(__local float* localMem, int localMemSize)
    {
        // Initialize local memory here.
        // Remember to call "barrier(CLK_LOCAL_MEM_FENCE)"
        // at the end to ensure that all work-items have finished initializing
        // the local memory
    }
     
    void compute(__local float* localMem, int localMemSize, __global float *in, __global float *out)
    {
        // Process data here
    }
     
    __kernel void doSomething(__local float* localMem, int localMemSize, __global float *in, __global float *out)
    {
        initLocalMem(localMem, localMemSize);
     
        compute(localMem, localMemSize, in, out);
    }
    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
    Junior Member
    Join Date
    Apr 2010
    Posts
    27

    Re: creating objects in shared memory

    Hi.

    This tutorial may help you understand how to use shared memories.

    http://gpgpu-computing4.blogspot.com...-3-opencl.html

  4. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    26

    Re: creating objects in shared memory

    Thanks a lot david.garcia and wonwoolee

Similar Threads

  1. Shared objects between devices...
    By yurtesen in forum OpenCL
    Replies: 0
    Last Post: 03-11-2012, 04:06 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
  •