Reputation: 831
I want to query the size of an OpenCL kernel argument so that I can ensure that I send it a variable of the correct size. I am able to query lots of other properties of each kernel argument using clGetKernelArgInfo, as follows:
clGetKernelArgInfo(k, argc, CL_KERNEL_ARG_TYPE_NAME, sizeof(argType), &argType, &retSize);
This will tell me the string name of the type, for example. But that's not good enough, especially in complex cases where it's a struct and the string name is the same on host and device, but the packing is different, so the size is different. The things that I can query, according to https://man.opencl.org/clGetKernelArgInfo.html , are:
CL_KERNEL_ARG_ADDRESS_QUALIFIER
CL_KERNEL_ARG_ACCESS_QUALIFIER
CL_KERNEL_ARG_TYPE_NAME
CL_KERNEL_ARG_TYPE_QUALIFIER
CL_KERNEL_ARG_NAME
Any ideas?
FYI, this is NOT a duplicate of Get OpenCL Kernel-argument information because that is asking how to use the argument query function, not asking how to query the argument size.
Upvotes: 1
Views: 390
Reputation: 5919
There's no standard way to check before setting the argument as far as I'm aware, but the clSetKernelArg
call will return CL_INVALID_ARG_SIZE
if the sizes don't match properly, so that should allow you to detect and handle errors accordingly:
CL_INVALID_ARG_SIZE if arg_size does not match the size of the data type for an argument that is not a memory object or if the argument is a memory object and arg_size != sizeof(cl_mem) or if arg_size is zero and the argument is declared with the __local qualifier or if the argument is a sampler and arg_size != sizeof(cl_sampler).
Upvotes: 2