ILGPU
ILGPU copied to clipboard
Throw exception of illegal memory access with OptimzationLevel.O2
WpfApp1.zip Hi,
The specialized kernel throw "illegal memory access" if turning on "OptimzationLevel.O2". it is ok with O1 and O0. It should have something to do with the definision of Run<T,T2>(...) and Run<T1,T2,T3,T4)(...)
Thanks!
hi @GeoBIM2020, thanks for reporting this issue. I have been able to reproduce the issue, and managed to reduce your sample code. This will require further investigation.
using ILGPU;
using ILGPU.Runtime;
using ILGPU.Runtime.Cuda;
namespace Issue846
{
public static class Program
{
private static void TestKernel(Index1D index, ArrayView1D<int, Stride1D.Dense> input, ArrayView1D<int, Stride1D.Dense> output)
{
switch (input[index])
{
case 0:
output[0] = 11;
break;
case 1:
output[0] = 22;
break;
case 2:
output[0] = 33;
break;
}
}
public static void Main()
{
using var context = Context.Create(builder => builder.Cuda().Optimize(OptimizationLevel.O2));
foreach (var device in context)
{
if (device.AcceleratorType == AcceleratorType.Cuda)
{
var accelerator = device.CreateAccelerator(context);
var kernel = accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView1D<int, Stride1D.Dense>, ArrayView1D<int, Stride1D.Dense>>(TestKernel);
using var inputBuffer = accelerator.Allocate1D<int>(new int[2] { 0, 1 });
using var outputBuffer = accelerator.Allocate1D<int>(2);
kernel(2, inputBuffer.View, outputBuffer.View);
accelerator.Synchronize();
var result = outputBuffer.View.GetAsArray1D();
}
}
}
}
}
This appears to be issue with the InferKernelAddressSpaces
optimization step of ILGPU, used only in O2
.
@m4rs-mt are you able to provide any additional information about this issue?
Looks like a bug in the InferKernelAdressSpaces
analysis/transformation, which should be fixed in version v1.3.