问题
I would like to make a kernel which takes a number of arguments, that is not set. Is this possible?
I guess this does not work? But why?
回答1:
if you are asking about typical C style vargs, then no.
But because kernels support C++ linkage, there are template and name mangling tricks which can be used to instantiate different versions of a kernel with length and different types of argument lists. Note also that CUDA 7.0 introduces C++11 variadic template support.
So there are options to do this, but probably not the ones you were thinking of when you asked the question.
[This answer assembled from comments and added as a community wiki entry to get the question off the unanswered queue]
来源:https://stackoverflow.com/questions/30628859/is-it-possible-to-have-a-cuda-kernel-with-varying-number-of-parameters