Reputation: 1104
I'm porting some CUDA code to OpenCL. The CUDA code does something like this:
// GPU code...
__device__ int counter;
// CPU code...
int data;
cudaMemcpyFromSymbol(gpuData, &data, sizeof(int), 0, cudaMemcpyDeviceToHost);
What would be the equivalent in OpenCL? Similarly, how would I do this for an array? The only way I know involves allocating an extra buffer, copying to it on the GPU, then reading from it on the CPU.
Upvotes: 0
Views: 230
Reputation: 5764
Use the clEnqueueReadBuffer
command, or with the C++ bindings:
T* host_buffer = nullptr; // host buffer
cl::Buffer device_buffer; // device buffer
cl::CommandQueue cl_queue; // command queue
cl_queue.enqueueReadBuffer(device_buffer, blocking, offset*sizeof(T), length*sizeof(T), (void*)(host_buffer+offset));
For a quick overview of OpenCL API calls, see the OpenCL Reference Card. If you want to make using OpenCL in C++ way easier and less bloated, see this OpenCL-Wrapper.
Upvotes: 1