当使用clSetKernelArg(memory_object)设置内核参数并使用clEnqueueNDKernelRangeKernel()多次调用内核时,您之前在内核的clSetKernelArg()中设置为参数的memory_object是否会从主机转移到GPU,每次调用内核?
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);
}
答案 0 :(得分:0)
通过调用clEnqueueWriteBuffer
或clEnqueueWriteImage
启动内存转移,但最有可能在调用clEnqueueNDRangeKernel
时启动。传输数据后,您可以根据需要随时重复使用内存对象,如果您没有再次明确说明,则不会再次传输。