Reputation: 1115
A question regarding buffer transfer in OpenCL: I want to pass a buffer (cl_mem) from the host to the kernel (i.e. to the device). There are two host-functions:
I use clSetKernelArg to pass my buffer to one of the kernel arguments. But does this mean that the buffer is automatically transfered to the device? Further, there is the function clEnqueueWriteBuffer which writes a buffer to a device.
My question: is there any difference in using (a.) only clSetKernelArg or (b.) clSetKernelArg and clEnqueueWriteBuffer in combination for my use-case (pass buffers to kernel)?
Upvotes: 1
Views: 1288
Reputation: 1229
You have to call both functions before enqueuing a kernel for execution.
clSetKernelArg
Used to set the argument value for a specific argument of a kernel.
This one only sets the argument value, e.g. some pointer, for the called kernel. There are no implicit data transfers.
Think of the following examples:
clSetKernelArg()
between two calls of the same kernel (double buffering)
In general: Data transfers between host and compute device are very expensive, and hence should be avoided, which is best possible by explicitly triggering them.
Upvotes: 2