Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException when passing empty ArrayViews to OpenCL kernel #1121

Closed
computablee opened this issue Nov 12, 2023 · 1 comment · Fixed by #1131
Closed

NullReferenceException when passing empty ArrayViews to OpenCL kernel #1121

computablee opened this issue Nov 12, 2023 · 1 comment · Fixed by #1131

Comments

@computablee
Copy link

In ILGPU 1.5.1 on .NET 7, I get a NullReferenceException when I try to pass an empty ArrayView to an OpenCL kernel. Below is a minimal reproducer:

using ILGPU;
using ILGPU.Runtime;

var context = Context.CreateDefault();
var accelerator = context.Devices[1].CreateAccelerator(context);
Console.WriteLine("Using {0} accelerator.", accelerator.AcceleratorType);

var kernel = accelerator.LoadAutoGroupedStreamKernel((Index1D i, ArrayView1D<byte, Stride1D.Dense> empty) => { });
kernel(1, ArrayView1D<byte, Stride1D.Dense>.Empty);

This has the following output on my machine:

Using OpenCL accelerator.
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at ILGPULauncher(Kernel, AcceleratorStream, Index1D, ArrayView1D`2)
   at ILGPU.Runtime.KernelLoaders.<>c__DisplayClass14_0`2.<LoadAutoGroupedStreamKernel>b__0(TIndex index, T1 param1)
   at Program.<Main>$(String[] args) in /home/lane/Repos/ILGPU-tester/Program.cs:line 9

My use case for this is that I'm passing a struct to some GPU kernels which contains a number of ArrayViews, though not all of them may be set at a given time (e.g., one ArrayView may point to a valid array one call, but be empty on a subsequent call depending on memory characteristics of the application). I'd like to just be able to set these array views using .Empty, but I am encountering that exception.

Is this something that ILGPU can address, or is this an inherent limitation of OpenCL/CUDA kernels? Thank you to all the maintainers!

Additional notes:

  • This does not happen on CPU accelerators
  • I have not tested CUDA accelerators as I do not have a CUDA-enabled GPU
  • My workaround for now has been to allocate a 1-element buffer with uninitialized data and use that as a placeholder, though this is not elegant
@m4rs-mt
Copy link
Owner

m4rs-mt commented Nov 13, 2023

Hi @computablee and welcome to the ILGPU community. First of all, thank you very much for your feedback and your detailed issue description. In fact, 'empty' array views are meant to be supported on all platforms. Let me look into that based on the sample provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants