There are lots of questions about how to read an array from the device, but I only wanna read a single float value from the device. Or can it only read an array from the device?
I create a buffer for (float) sum like below.
ocl.sum = clCreateBuffer(context, CL_MEM_READ_WRITE, 1, NULL, &err);
Set the arg like this.
clSetKernelArg(kernel, 0, sizeof(cl_mem), &ocl.arr);
clSetKernelArg(kernel, 1, sizeof(cl_float), &ocl.sum);
In the kernel, I calculate the sum.
kernel calculate(global arr, float sum)
{
...
sum = 100.0f;
}
How can I get the sum from the device?
float result = 0.f;
err = clEnqueueReadBuffer(queue, ocl.sum, CL_TRUE, 0, 1, &result, 0, NULL, NULL);
print(result);