Results 1 to 2 of 2

Thread: Assigning a number to a __global int *p and resolving it

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    20

    Assigning a number to a __global int *p and resolving it

    Thanks for taking time to read this. I have 2 kernels. To both these kernels I send the same 2 memory buffers as arguments, where each of the memory buffers have the size -> sizeof(int) * 10.

    I call init_mpm( ) first and I set m[i] to the subsequent address locations in bmasks. Basically I am holding an array of addresses.

    I next call resolve_address( ) and I assign the value m[i], which actually now holds the address values from bmasks from the previous call to init_mpm( ) to a pointer p. But now when I try to resolve the pointer as p[0], I get clBuildProgram error of -42. Can't I resolve the address like this? Isn't p now holding the address and can't it be resolved as an integer using p[0]? I am actually trying to hold an array of address from a memory object across multiple kernel invocations and later resolve these addresses in another kernel.

    __kernel void init_mpm(__global int *m, __global int *bmasks)
    {
    unsigned int i = 0;

    for (i = 0; i < 10; i++) {
    bmasks[i] = i;
    m[i] = bmasks + i;
    }
    }

    __kernel void resolve_address(__global int *m, __global int *bmasks)
    {
    unsigned int i = 0;
    __global int *p;

    for (i = 0; i < 10; i++) {
    p = m[i];
    m[i] = p[0]; <-- this line gives me an error. If I comment this line I get no errors during compilation
    }

    }

  2. #2
    Junior Member
    Join Date
    Apr 2009
    Posts
    27

    Re: Assigning a number to a __global int *p and resolving it

    There seems to be few issues with the code as presented. Firstly, in the first kernel you are assigning a value (bmasks + i) of type __global int * to a value (m[i]) of type int:

    t1.cl(7): warning: a value of type "__global int *" cannot be assigned to an
    entity of type "int"
    m[i] = bmasks + i;
    ^
    This can be fixed by assigning the correct type to the argument m, with something like:

    typedef __global int * globalInt;

    __kernel void init_mpm(__global globalInt *m, __global int *bmasks)
    {
    unsigned int i = 0;

    for (i = 0; i < 10; i++) {
    bmasks[i] = i;
    m[i] = bmasks + i;
    }
    }


    The bigger problem is with the 2nd kernel as it does not seem to be
    valid. This is made clearer if we change it to also use the typedef
    globalInt:

    __kernel void resolve_address(__global globalInt *m, __global int *bmasks)
    {
    unsigned int i = 0;
    __global int *p;

    for (i = 0; i < 10; i++) {
    p = (globalInt)m[i];
    m[i] = p[0];
    }
    }

    Compiling this we get:

    t1.cl(20): warning: a value of type "int" cannot be assigned to an entity of
    type "globalInt"
    m[i] = p[0];

    The problem is that you are assigning m[i] (__global * int) to p (also
    a __global * int) and then on the following line dereferencing p[0]
    and assigning back to the the same m[i] on the previous line. Of
    course, this is a type error and while you could probalby get it to
    statically compile it is not clear this is the expected behaviour. On the other hand it is completly valid to do something like:

    int foo = p[0];

    A useful OpenCL API call is clGetProgramBuildInfo in conjunction with
    the flag CL_PROGRAM_BUILD_LOG that can be used to obtain the log for a
    particular call to clBuildProgram.

Similar Threads

  1. Can't see error: Assigning texture to 2 triangles
    By Phopojijo in forum Developers Coding:Beginner
    Replies: 3
    Last Post: 03-19-2012, 05:09 PM
  2. unsigned int or cl_uint?
    By mihzaha in forum OpenCL
    Replies: 1
    Last Post: 08-18-2010, 12:07 AM
  3. precision highp int?
    By qqca in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 1
    Last Post: 07-01-2010, 02: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
  •