问题
I have an OpenCL kernel that gets built at runtime from a PTX-kernel string with clCreateProgramWithBinary
, and then built. Now at a later point, I am trying to set the kernel Arguments. I retrieve those arguments in an array of void *
, so I do not know the size/type of each individual entry. However, that information is stored in the PTX-kernel string, ie. with:
.visible .entry my_kernel(
.param .u64 param_1,
.param .u32 param_2,
.param .f64 param_3
)
I can correctly query the number of arguments with
clGetKernelInfo(kernel, CL_KERNEL_NUM_ARGS, sizeof(cl_uint), &num_args, NULL);
However, I also need to know the size of each argument, to correctly pass it in to the clSetKernelArg
call. To my understanding, I can get the size of each argument by querying it with:
char name_buff[100];
clGetKernelArgInfo(kernel, current_index, CL_KERNEL_ARG_TYPE_NAME, 100 * sizeof(char), &name_buff, NULL);
But that call fails with the error code CL_KERNEL_ARG_INFO_NOT_AVAILABLE
.
Intuitively, this does not make sense to me, because that information is clearly stored in the kernel, even though I have not yet set those arguments specifically.
Is this correct behavior, and is there a way to get that information, other than to parse the PTX string?
回答1:
According to clGetKernelArgInfo the argument info is only available if the program is built with clCreateProgramWithSource
and built with the option -cl-kernel-arg-info
.
Kernel argument information is only available if the program object associated with kernel is created with
clCreateProgramWithSource
and the program executable is built with the-cl-kernel-arg-info
option specified in options argument to clBuildProgram or clCompileProgram.
That said, some implementations (e.g. Intel HD) will generate the info without the option and will even retain it in the binary so that clCreateProgramWithBinary
programs can fetch it too. Alas it doesn't seem NVidia's driver does this. Can you parse the PTX even ad-hoc to extra the information you need?
回答2:
With out you telling us what exactly you are putting into the args, its going to be hard to figure out what is going on. My rep doesn't allow me to comment on your post... so I'm forced to post an answer if I want to help.
Lets review https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/clGetKernelArgInfo.html
Its clear that the error code for this has nothing to do with index being out of range or other issue. Therefore the kernel argument information must not be found. Have you tried every index 0->2? try clSetKernelArg(...) and before hand and see if that helps, if you get errors with clSetKernelArg, you'll get closer to why this doesn't work, otherwise try to do the same thing you were doing with clSetKernelArg first.
https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/clSetKernelArg.html
can't find 2.0+ docs for this function, but I've not noticed regression with it.
来源:https://stackoverflow.com/questions/42854602/get-opencl-kernel-argument-information