Results 1 to 3 of 3

Thread: My kernel returns # of bytes instead of value of variable

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    10

    My kernel returns # of bytes instead of value of variable

    Hi,

    I've setups my kernel to return a simple value to test wether the kernel is working, but I think its returning bits instead of the value.

    In main, I prepped the variable passing like this:

    double distances[NUM_ATOMS];

    memObjects[0] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, NUM_RAYS*sizeof(double), rayA, NULL);
    memObjects[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, NUM_ATOMS*sizeof(double), NULL, NULL);

    errNum = clSetKernelArg(CheckKernel, 0, sizeof(cl_mem), &memObjects[0]);
    errNum |= clSetKernelArg(CheckKernel, 1, sizeof(cl_mem), &memObjects[1]);

    size_t globalWorkSize[1] = { NUM_ATOMS };
    size_t localWorkSize[1] = { 1 };

    errNum = clEnqueueNDRangeKernel(commandQueue, CheckKernel, 1, NULL, globalWorkSize, localWorkSize, 0, NULL, NULL);

    clFinish(commandQueue);

    errNum = clEnqueueReadBuffer(commandQueue, memObjects[1], CL_TRUE, 0, NUM_ATOMS*sizeof(double), distances, 0, NULL, NULL);

    for(t=0;t<NUM_ATOMS;t++)
    {
    cout << distances[t] << endl;
    }


    The kernel:

    __kernel void Check_for_intersection(__global const double rayA,
    __global double *distances){
    int gid = get_global_id(0);
    distances[gid] = 0;
    }


    I've tried many different values for distances and got this:

    distances[gid] = 0; returns 0.0078125
    distances[gid] = 1; returns 32
    distances[gid] = 2; returns 2048
    distances[gid] = 3; returns 32768
    distances[gid] = 4; returns 262144
    distances[gid] = 5; returns 1.04858e+06
    distances[gid] = 6; returns 4.19431e+06
    distances[gid] = 7; returns 1.67772e+07
    distances[gid] = 8; returns 5.03317e+07
    distances[gid] = 9; returns 1.00663e+08

    Also, if I do math in the kernel with a passed variable like:

    double a = 1;
    distances[AtomID] = a + rayA;


    I get this error:

    Error in kernel:
    <program source>:16:27: error: invalid operands to binary expression ('double' and 'double const __attribute__((address_space(1))) *')
    distances[AtomID] = a + rayA;
    ' ~ ^ ~~~~


    Does anyone have a clue what's wrong?

  2. #2
    Junior Member
    Join Date
    Nov 2011
    Posts
    10

    Re: My kernel returns # of bytes instead of value of variabl

    So I switched the double to float and solved that problem, but I'm having trouble passing anything of int type. Any suggestions?

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    10

    Re: My kernel returns # of bytes instead of value of variabl

    int index = 0;
    memObjects[9] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int), &index, NULL);

    __kernel void hello_kernel(__global const float *phiC,
    __global const float *psiC,
    __global float *distances,
    __global const float *phiS,
    __global const float *psiS,
    __global const float *atomX,
    __global const float *atomY,
    __global const float *atomZ,
    __global const float *radii,
    __global const int *index){
    int gid = get_global_id(0);
    distances[gid] = index;
    }

    The rest of my variables work fine

    Error in kernel:
    <program source>:12:20: error: incompatible type assigning 'int const __attribute__((address_space(1))) *', expected 'float __attribute__((address_space(1)))'
    distances[gid] = index;

Similar Threads

  1. kernel execution returns CL_INVALID_VALUE
    By acolubri in forum OpenCL
    Replies: 5
    Last Post: 02-16-2010, 09:20 AM
  2. Passing variable length structure to kernel
    By kungen85 in forum OpenCL
    Replies: 4
    Last Post: 10-08-2009, 12:47 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
  •