Reputation: 25
When a kernel argument is set using clSetKernelArg(memory_object) and call the kernel multiple times using clEnqueueNDKernelRangeKernel( ), will the memory_object that you had previously set as the argument in clSetKernelArg( ) for the kernel, be transferred from the host to the GPU, for every invocation of the kernel?
status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &inbuf);
size_t num_total_wi = M * N;
size_t num_wg = num_elem/N + ((num_elem/N == 0) ? 0 : 1);
size_t num_iter = num_elem/(num_total_wi) + (((num_elem % (num_total_wi)) == 0) ? 0 : 1);
for(i = 0; i < num_iter; i++) {
size_t global_work_size[3] = {num_total_wi, 1, 1};
size_t local_ws[3] = {N, 1, 1};
size_t global_offset[3] = {i * num_total_wi, 0, 0};
clEnqueueNDRangeKernel(queue, kernel, 1, global_offset, global_work_size, local_ws, 0, NULL, NULL);
}
Upvotes: 1
Views: 464
Reputation: 2181
A memory transfer is initiated by a call to clEnqueueWriteBuffer
or clEnqueueWriteImage
but will most likely be started when clEnqueueNDRangeKernel
is called. Once the data is transferred, you can re-use the memory objects as often as you like and it won't be transferred again if you don't state it explicitly again.
Upvotes: 1