-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test cased for fixed array buffes.
- Loading branch information
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<#@ template debug="false" hostspecific="true" language="C#" #> | ||
<#@ include file="Generic/ConfigurationBase.tt" #> | ||
<#@ assembly name="System.Core" #> | ||
<#@ import namespace="System.IO" #> | ||
<#@ output extension=".cs" #> | ||
using System; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
#pragma warning disable CA1815 // Override equals and operator equals on value types | ||
#pragma warning disable CA1051 // Do not declare visible instance fields | ||
#pragma warning disable CA2231 // Overload operator equals on overriding value type Equals | ||
#pragma warning disable CS0659 // Type overrides Object.Equals(object o) but does not | ||
// override Object.GetHashCode() | ||
|
||
namespace ILGPU.Tests | ||
{ | ||
<# foreach (var type in IntTypes) { #> | ||
public unsafe struct FixedBufferStruct<#= type.Name #> : | ||
IXunitSerializable, | ||
IEquatable<FixedBufferStruct<#= type.Name #>> | ||
{ | ||
public fixed <#= type.Type #> Data[FixedBuffers.Length]; | ||
|
||
public FixedBufferStruct<#= type.Name #>(<#= type.Type #> data) | ||
{ | ||
for (int i = 0; i < FixedBuffers.Length; ++i) | ||
Data[i] = data; | ||
} | ||
|
||
public void Deserialize(IXunitSerializationInfo info) | ||
{ | ||
for (int i = 0; i < FixedBuffers.Length; ++i) | ||
Data[i] = info.GetValue<<#= type.Type #>>(nameof(Data) + i); | ||
} | ||
|
||
public void Serialize(IXunitSerializationInfo info) | ||
{ | ||
for (int i = 0; i < FixedBuffers.Length; ++i) | ||
info.AddValue(nameof(Data) + i, Data[i]); | ||
} | ||
|
||
public bool Equals(FixedBufferStruct<#= type.Name #> buffer) | ||
{ | ||
for (int i = 0; i < FixedBuffers.Length; ++i) | ||
{ | ||
if (Data[i] != buffer.Data[i]) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public override bool Equals(object obj) => | ||
obj is FixedBufferStruct<#= type.Name #> fixedStruct && | ||
Equals(fixedStruct); | ||
} | ||
|
||
<# } #> | ||
|
||
public unsafe abstract class FixedBuffers : TestBase | ||
{ | ||
public const int Length = 9; | ||
|
||
protected FixedBuffers(ITestOutputHelper output, TestContext testContext) | ||
: base(output, testContext) | ||
{ } | ||
<# foreach (var type in IntTypes) { #> | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static void AdjustBuffer( | ||
ref FixedBufferStruct<#= type.Name #> value, | ||
<#= type.Type #> scalarValue) | ||
{ | ||
for (int i = 0; i < Length; ++i) | ||
value.Data[i] += scalarValue; | ||
} | ||
|
||
internal static void FixedBuffer<#= type.Name #>Kernel( | ||
Index1 index, | ||
ArrayView<<#= type.Type #>> data, | ||
ArrayView<<#= type.Type #>> data2, | ||
FixedBufferStruct<#= type.Name #> value, | ||
<#= type.Type #> scalarValue) | ||
{ | ||
data[index] = value.Data[index]; | ||
AdjustBuffer(ref value, scalarValue); | ||
data2[index] = value.Data[index]; | ||
} | ||
|
||
[Fact] | ||
[KernelMethod(nameof(FixedBuffer<#= type.Name #>Kernel))] | ||
public void FixedBuffer<#= type.Name #>() | ||
{ | ||
using var buffer1 = Accelerator.Allocate<<#= type.Type #>>(Length); | ||
using var buffer2 = Accelerator.Allocate<<#= type.Type #>>(Length); | ||
|
||
<#= type.Type #> scalarValue = 2; | ||
var fixedBufferData1 = new FixedBufferStruct<#= type.Name #>(scalarValue); | ||
Execute(Length, buffer1.View, buffer2.View, fixedBufferData1, scalarValue); | ||
|
||
var expected1 = Enumerable.Repeat(scalarValue, Length).ToArray(); | ||
var expected2 = Enumerable.Repeat( | ||
(<#= type.Type #>)(scalarValue + scalarValue), | ||
Length).ToArray(); | ||
Verify(buffer1, expected1); | ||
Verify(buffer2, expected2); | ||
} | ||
<# } #> | ||
} | ||
} | ||
|
||
#pragma warning restore CA2231 // Overload operator equals on overriding value type Equals | ||
#pragma warning restore CA1051 // Do not declare visible instance fields | ||
#pragma warning restore CA1815 // Override equals and operator equals on value types | ||
#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not | ||
// override Object.GetHashCode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters