Skip to content

Commit

Permalink
Fixed marshalling ArrayView.Empty as kernel parameter. (m4rs-mt#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ committed Apr 18, 2024
1 parent 27d6489 commit b6e6779
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 b6e6779

Please sign in to comment.