Skip to content

Commit

Permalink
Fixed marshalling ArrayView.Empty as kernel parameter. (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ authored Dec 1, 2023
1 parent c324431 commit d49fd60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Src/ILGPU.Tests/MemoryBufferOperations.tt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ namespace ILGPU.Tests
{
output[index] = input[index];
}

internal static void EmptyView_Kernel<T>(
Index1D index,
ArrayView1D<T, Stride1D.Dense> output)
where T : unmanaged
{
if (index < output.Length)
output[index] = default(T);
}

<# foreach (var type in copyTypes) { #>
[Fact]
[KernelMethod(nameof(EmptyView_Kernel))]
public void EmptyView_<#= type.Name #>()
{
Execute<Index1D, <#= type.Type #>>(
42,
ArrayView1D<<#= type.Type #>, Stride1D.Dense>.Empty);
}

<# } #>

internal static void ZeroLength_Kernel<T>(
Index1D index,
Expand Down
2 changes: 1 addition & 1 deletion Src/ILGPU/Backends/PointerViews/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static FieldInfo GetLengthField(Type implType) =>
/// <returns>The underlying native pointer.</returns>
private static IntPtr GetNativePtr<T>(in ArrayView<T> view)
where T : unmanaged =>
view.Buffer.NativePtr;
view.Buffer?.NativePtr ?? IntPtr.Zero;

/// <summary>
/// Gets the native-pointer method for the given element type.
Expand Down

0 comments on commit d49fd60

Please sign in to comment.