read multiple exits using function clEnqueueTask

hi!! I have a problem, I am using the function clEnqueueTask() to execute many kernels, but, I need take the result in a certain order.
For example:
for(int i=0;i<12;i++)
clEnqueueTask(queueCPU,kernel[i],0,NULL,NULL);
clFinish(queueCPU);

I need to take the results in the same order in that enqueue.
for(int i=0;i<12;i++)
clEnqueueReadBuffer(queueCPU, buffer, CL_TRUE, NULL, length* sizeof(float), array, NULL, NULL, NULL);
I put this way it, but the result are bad.
please help me!!!
thank!!!

I assume from your code that each of those tasks is writing the same buffer, and that you’re trying to get different results from each clEnqueueTask. If that’s the case, then you need to interleave the clEnqueueTask calls and the clEnqueueReadBuffer calls. As the code is written in the post, it will just read the same values every time (the values written by the last task execution).

hi, this is part of code.
for (int i=0;i<12;i++)
{
kernel[i]= clCreateKernel(programGPU, “function”, &ret);
ret=clSetKernelArg(kernel[i], 0, sizeof(cl_mem), &buffer);

ret=clSetKernelArg(kernel[i], 14, sizeof(float), &buffer_freq[i]);

ret=clSetKernelArg(kernel[i], 17, sizeof(cl_mem), &buffer_levels[i]);
}

for(int i=0;i<12;i++)
clEnqueueTask(queueCPU,kernel[i],0,NULL,NULL);
clFinish(queueCPU);
Now my question is: how I reed the buffers buffer_freq and buffer_levels.
I program this way it
for(int i=0;i<cantCudaCores;i++)
{
clEnqueueTask(queueCPU,kernel_Notch_Notch[i],0,NULL,NULL);
ret= clEnqueueReadBuffer(queueCPU, buffer_levels[i], CL_TRUE, NULL, lengthFreq * sizeof(float), levels[i].arreglo, 0, NULL, NULL);
ret= clEnqueueReadBuffer(queueCPU, buffer_freq[i], CL_TRUE, NULL, lengthFreq * sizeof(float), freq[i].arreglo, 0, NULL, NULL);
}
clFinish(queueCPU);
But, not work. Please help me!!!

      • Updated - - -

hi, this is part of code.
for (int i=0;i<12;i++)
{
kernel[i]= clCreateKernel(programGPU, “function”, &ret);
ret=clSetKernelArg(kernel[i], 0, sizeof(cl_mem), &buffer);

ret=clSetKernelArg(kernel[i], 14, sizeof(float), &buffer_freq[i]);

ret=clSetKernelArg(kernel[i], 17, sizeof(cl_mem), &buffer_levels[i]);
}

for(int i=0;i<12;i++)
clEnqueueTask(queueCPU,kernel[i],0,NULL,NULL);
clFinish(queueCPU);
Now my question is: how I reed the buffers buffer_freq and buffer_levels.
I program this way it
for(int i=0;i<cantCudaCores;i++)
{
clEnqueueTask(queueCPU,kernel_Notch_Notch[i],0,NULL,NULL);
ret= clEnqueueReadBuffer(queueCPU, buffer_levels[i], CL_TRUE, NULL, lengthFreq * sizeof(float), levels[i].arreglo, 0, NULL, NULL);
ret= clEnqueueReadBuffer(queueCPU, buffer_freq[i], CL_TRUE, NULL, lengthFreq * sizeof(float), freq[i].arreglo, 0, NULL, NULL);
}
clFinish(queueCPU);
But, not work. Please help me!!!

One thing I notice is this:

ret=clSetKernelArg(kernel[i], 14, sizeof(float), &buffer_freq[i]);

This should pass sizeof(cl_mem), not sizeof(float). Are the error codes being checked on this and the other calls? Could something be returning an error that the code is not checking?