Skip to content

Commit

Permalink
Fixed marshalling ArrayView.Empty as kernel parameter. (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ authored May 2, 2024
1 parent aa11ee9 commit 5593fe7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion Src/ILGPU.Tests/MemoryBufferOperations.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021-2023 ILGPU Project
// Copyright (c) 2021-2024 ILGPU Project
// www.ilgpu.net
//
// File: MemoryBufferOperations.tt/MemoryBufferOperations.cs
Expand Down Expand Up @@ -109,6 +109,28 @@ 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))]
[MethodImpl(MethodImplOptions.NoInlining)]
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
4 changes: 2 additions & 2 deletions Src/ILGPU/Backends/PointerViews/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2018-2023 ILGPU Project
// Copyright (c) 2018-2024 ILGPU Project
// www.ilgpu.net
//
// File: Utilities.cs
Expand Down 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 5593fe7

Please sign in to comment.