✅ Modify delegate for ILGPU acceptance
This is a long one, strap in!
So I’m incorporating ILGPU into a library I’m writing for very simple but powerful/expressive/flexible parallel programming. ILGPU is gonna help power the upcoming GPU API.
With that said, ILGPU accepts either a delegate or a static method as a GPU kernel. The method called has to incorporate an instantiation of the
With that the background out of the way, ILGPU kernels, if they are a delegate, do not support captures or objects. This poses a problem for me, since I need to pass a delegate to the ILGPU library with an
What I want to be able to do is have something like:
but the problem here is that the
I tried passing in a struct as one of the kernel arguments that contains
What I am thinking of is one of the following:
So I’m incorporating ILGPU into a library I’m writing for very simple but powerful/expressive/flexible parallel programming. ILGPU is gonna help power the upcoming GPU API.
With that said, ILGPU accepts either a delegate or a static method as a GPU kernel. The method called has to incorporate an instantiation of the
ILGPU.IIndex interface as the first parameter. For the sake of my API, I would like to avoid passing around ILGPU datatypes to delegates I accept, because that exposes implementation details to users of my library.With that the background out of the way, ILGPU kernels, if they are a delegate, do not support captures or objects. This poses a problem for me, since I need to pass a delegate to the ILGPU library with an
IIndex but abstract that away in my API. This problem exists with other parameters, too.What I want to be able to do is have something like:
but the problem here is that the
kernel delegate captures action_received_from_user, which ILGPU doesn’t allow.I tried passing in a struct as one of the kernel arguments that contains
action_received_from_user as a member, but because delegates are managed types, they cannot be passed in as a kernel argument.What I am thinking of is one of the following:
- A way to on-the-fly inline (inline in the C/C++ sense)
action_received_from_userinto my kernel body. - A way to use Mono.Cecil or some other reflection API to manually inject CIL into the method body and change the argument types (I’m very familiar with CIL, less so with reflection)
- Use Roslyn -> ??? -> Profit…?
- Some other way to accomplish this.