Best way to transform for every __global__ function in the codebase


I have a fairly large C++ + CUDA codebase. I am hoping to make a simple transformation for every CUDA __global__ function call in the codebase by having each one of them accept an extra argument. E.g.,

// Before
__global__ void foo(float *)
// After
__global__ void foo(float *, float * /* my extra argument */)

May I know whether there is any advice on how this could be possibly achieved? Thank you.

So you are looking to apply a a textual change at source code level? Changing __global__ function declarations and definitions should be easy enough by using Perl to do the rewrite. What are you planning to do about the call sites where these kernels are invoked, though, to make the code compiler after this change? Pass a constant? Pass a variable? Wrap all kernels invocations in a macro?

What is the purpose of this exercise? Maybe there are more straightforward ways to accomplish whatever it is you are trying to do.