Using CL_MEM_USE_HOST_PTR with clEnqueueReadBuffer

Suppose I first create a buffer using CL_MEM_USE_HOST_PTR:

  mybuffer = clCreateBuffer(context, CL_MEM_READ_WRITE| CL_MEM_USE_HOST_PTR, sizeof(float)*n,myvec,&err);

where myvec is a float array of length n.

Next, some operations are performed in a kernel involving writing on array y.

Next, read the results using:

  clEnqueueReadBuffer(queue, mybuffer, CL_TRUE, 0, sizeof(float)*n, myvec, 0, NULL, NULL);

Is this defined? Is this valid?

Yes, this is valid under the following requirements, as explained in the OpenCL specification document:

[ul]
[li]All commands that use this buffer object have finished execution before the read command begins execution.[/:m:v56mx2ur][/li][li]The buffer object is not mapped.[/:m:v56mx2ur][/li][]The buffer object is not used by any command-queue until the read command has finished execution.[/:m:v56mx2ur][/ul]

All right, thank you for the reply.