OpenCL not reading all of device memory back to host

Sometimes I find that when I read device memory back to the host, that the last so many elements of the array are zeros, like it failed to read all the memory. Has anyone experienced this or know what might be causing it?

I thought maybe I had to restrict buffer size to < MAX_MEM_ALLOC_SIZE, but I’ve had this happen when the buffer size is less than this value.

The first thing to check is probably to make sure the copy has finished before reading the data. This can be ensured by using a blocking ReadBuffer or by waiting on the ReadBuffer event or by clFinish()ing the queue where the command was enqueued.