cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

shingoxlf
Journeyman III

memcpy in OpenCL kernel

Hi, I was trying to implement a simple memcpy function in the opencl kernel:

void memcpyint(__global int *dest, const __global int *src, int len)

{

    for(int i=0;i<len;i++) dest=src;

    return;

}

and here is my kenel:

__kernel void simple(__global int *a; __global int *b)

{

int id=get_global_id(0);

memcpyint(a[id*10],b[id*10],10)

return;

}

But I got error "CL_OUT_OF_RESOURCES " when I try to copy GPU memory back to CPU

If I do not call the memcpyint function and change the kernel to:

__kernel void simple(__global int *a; __global int *b)

{

int id=get_global_id(0);

for(int i =0;i<10;i++)

    {

        a[id*10+i] = b[id*10+i];

    }

return;

}

the code is working. Can anyone tell me why the function memcpyint does not work? Thanks!

0 Likes
3 Replies
notzed
Challenger

this:

memcpyint(a[id*10],b[id*10],10)

is not the same as

this:

a[id*10+i] = b[id*10+i];

you probably intended:

memcpyint(&a[id*10],&b[id*10],10)

or

memcpyint(a+id*10,b+id*10,10)

next time paste the actual code, this is obivously not even going to compile with ; in the argument lists, and missing characters.

BTW this is not a very good solution: check the bits of any opencl guide/book which talks about memory coalescing.  Also look at related memory copying examples in the sdks.

0 Likes

if there is any memory copying examples in the sdk?

0 Likes

Yes there are.  And the amd opencl programming guide goes into memory issues in excruciating detail, e.g. chapter 4.6.

0 Likes