Unittesting Image Read an write

Hi there,

i’m not really shure if my assumption is correct so maybe some can clearify it.
I’m Writing unittests for an OpenCL Abstraction layer including alle the basics. I Wont to test if reading and writing vor images and buffers works fine. For that i do the following (in pseudocode)


float fData[8];
fData[0] = 1.f;
fData[7] = 1.f;
createBuffer();//Create the buffer in correct size
writeData(fData);//Write the Data to OpenCL
memset(fData,0,8*4);//Clear the host mem
readData(fData);//Read back the data from OpenCL

I’m asking myself if the Data will be transported to CL without any usage of that buffer. If I remember correctly, the data doesn’t have to be pushed to the openCl device until its used. So will that code really test the memory transfer? Or does it only copies the values in host memory address space?

Regards,
clint3112

Hard to tell from pseudocode!

In particular, is writeData using a blocking write? If so, you should be good. If not, you will likely be clearing the buffer in the next line before the transfer happens.

readData also needs to be blocking.

For a unit test, I’d recommend using a different buffer for the readback, so when you compare values you’ll be sure that they really came from the GPU and not “left over” in memory.