Skip to content

[QUESTION]: Is it available to compile a Dynamic Method with ILGPU? #1542

@jyswjjgdwtdtj

Description

@jyswjjgdwtdtj

Question

I need to run a method created dynamically.

DynamicMethod dm=new DynamicMethod("Test", typeof(void),new Type[]{typeof(Index1D),typeof(ArrayView<Single>)},typeof(Program));
var il= dm.GetILGenerator();
il.Emit(OpCodes.Ret);
var del=dm.CreateDelegate<Action<Index1D,ArrayView<float>>>();
/*
equals to:

static void Test(
        Index1D index,ArrayView<float> buffer)  // A view of floats to store float results from GPUMath
    {
        return;
    }

*/
using var context = Context.CreateDefault();
using var accelerator = context.GetPreferredDevice(preferCPU: true).CreateAccelerator(context);
var kernel = accelerator.LoadAutoGroupedStreamKernel(del);
using var buffer = accelerator.Allocate1D<float>(128);
kernel((int)buffer.Length, buffer.View);

However, exception System.NotSupportedException: Derived classes must provide an implementation. takes place.
Is there any way to compile a dynamically created method with ILGpu?
And there's no "Derived classes" I think

Environment

  • ILGPU version: 1.5.3
  • .NET version: 10
  • Operating system: Windows10
  • Hardware (if GPU-related): this problem may not be related to hardware

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions