OpenCl wrong values when reading from multiple GPU

53 views Asked by At

I have a kernel function that only writes number to a __global int* c To be specific it looks like this:

__kernel void Add1(__global int* c)
{
    *c = 3;
}

and in host code I have allocated memory for C value:

cl_mem bufferC[deviceNumber]; // deviceNumber = 8
for(int i = 0; i< deviceNumber; i++){
bufferC[i] = clCreateBuffer(context[i], CL_MEM_WRITE_ONLY, sizeof(cl_int) * global_size, NULL, &error);
}

for(int i = 0; i< deviceNumber; i++){
    error = clSetKernelArg(kernel[i], 0, sizeof(cl_mem), (void*)&bufferC[i]);
}

for(int i = 0; i< deviceNumber; i++){
    error = clEnqueueReadBuffer(commandQueue[i], bufferC[i], CL_TRUE, 0, sizeof(cl_int) * global_size, &c[i], 0, NULL, NULL);
}

and I print it like:

for (size_t i = 0; i < deviceNumber; ++i)
{
    std::cout<< "delta = " << c[i] << std::endl;
}

and output:

delta = 3
delta = 11165
delta = -1329524360
delta = 11165
delta = 0
delta = 0
delta = -1329520352
delta = 11165

so first value is ok, rest is sort of garbage, do you know what mistake I made writing it? Of course it is only a partial code, but I think I pasted all the lines regarding that 'c' value. Global size is set to 1.

1

There are 1 answers

0
Gzyniu On

Well, my mistake was creating number of contexts but in argument I put one device instead of a array of them. But I found it by printing error codes in program - try to do that if you have some problems! Cheers