I am trying to allocate several SVM buffers and pass them to an OpenCL kernel using the following method. The kernel is run on Intel HD Graphics 530 and NVIDIA GTX 950M. I get different results on these GPUs, and I am not sure which behavior is correct (maybe, both?)
data0
, data1
, pointers
) with 3 clSVMAlloc() calls.data0
and data1
with data, and pointers
with pointers to data0
and data1
, so that pointers[0] == data0
and pointers[1] == data1
.data0
) + check for CL_SUCCESS (no failure here).pointers
) + check for CL_SUCCESS (no failure here).On NVIDIA card, the data is available through both pointers[0]
and pointers[1]
. This is the expected behavior.
On Intel chip, memory behind pointers[0]
is available (because data0
has been set as kernel argument), but memory behind pointers[1]
is all zeroes. If I set data1
as kernel argument, then it becomes available through pointers[1]
and memory behind pointers[0]
becomes zeroes.
The question is: is Intel approach a bug or a feature? I have not found any related information in the OpenCL 3.0 specification.
Intel works correctly and adheres to the specification. NVIDIA is more fool-proof, however.
To fix the problem in question, one needs to not forget to pass an array of SVM buffers to a kernel:
ret = clSetKernelExecInfo(kernel, CL_KERNEL_EXEC_INFO_SVM_PTRS, sizeof(svm_buffers), svm_buffers);
where svm_buffers
is void*[]
array of pointers to buffers allocated using clSVMAlloc() calls.
The OpenCL specification states the following for clSetKernelExecInfo
with parameter CL_KERNEL_EXEC_INFO_SVM_PTRS
:
SVM pointers must reference locations contained entirely within buffers that are passed to kernel as arguments, or that are passed through the execution information. Non-argument SVM buffers must be specified by passing pointers to those buffers via clSetKernelExecInfo for coarse-grain and fine- grain buffer SVM allocations but not for finegrain system SVM allocations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With