Results 1 to 4 of 4

Thread: Passing a global parameter from kernel into a function

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    11

    Passing a global parameter from kernel into a function

    I'm just playing around with OpenCL and trying to get some simple c++ routines adapted for opencl.

    Basically - i'm trying to do something of the kind:

    Code :
     
    // function prototype
    int CL_TestFunction(float2 *pts)
     
    // opencl kernel
    kernel void CL_TestKernel(global float2 *pts)
    {
      // so let's do some stuff 
      int id = get_global_id(0);
      // blah
      float x = pts[id].x;
      float y = pts[id].y;
      // and then let's use a c style function, which passes in the array of float2 
      int num = CL_TestFunction(pts);  
    }
     
    int CL_TestFunction(float2 *pts)
    {
      // do some things in here:
      return 0;
    }

    Now - the problem i'm getting is when i try passing in the pts array into the CL_TestFunction. I get a build error.
    When i've used other functions, which don't use the global parameters, it's absolutely fine (to my knowledge anyway).

    So - i'm guessing that i'm unable to do this. So - is there a way around this? I imagine i'm missing the point somewhat in regards global variables etc, so any help would be really appreciated.
    The code i'm working on is a lot more complicated than what i've displayed above, so there are good reasons (to me) for trying to pass the pts array.

    Hope that makes some sort of sense.

  2. #2
    Senior Member
    Join Date
    Oct 2012
    Posts
    165

    Re: Passing a global parameter from kernel into a function

    Ran into the same problem without any solution. I think it is because this funktion will loose the qualifier global. But I'm not really shure. I think i found someting in the spec, regarding that topic

  3. #3
    Senior Member
    Join Date
    Oct 2012
    Posts
    109

    Re: Passing a global parameter from kernel into a function

    Your function should be declared as "CL_TestFunction(global float2 *pts)"

    Without an explicit address space qualifier, a pointer is considered as private, so "CL_TestFunction(float2 *pts)" really means "CL_TestFunction(private float2 *pts)".

  4. #4
    Junior Member
    Join Date
    Dec 2012
    Posts
    11

    Re: Passing a global parameter from kernel into a function

    Thanks, i got that to build!

    Now to sort the rest of it out

Similar Threads

  1. passing an array of char* to kernel function
    By naroqueen in forum OpenCL
    Replies: 15
    Last Post: 12-16-2010, 09:26 AM
  2. Replies: 0
    Last Post: 05-05-2010, 05:13 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
  •