Skip to content

Commit

Permalink
Added basic loop tests with constant trip counts.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rs-mt committed Sep 20, 2020
1 parent 7c3e225 commit 59044b8
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions Src/ILGPU.Tests/BasicLoops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,33 @@ public void ForCounterData(int counter)
Verify(buffer, expected);
}

internal static void ForCounterDataConstantKernel(
Index1 index,
ArrayView<int> data)
{
int value = 42;
int value2 = 23;
int value3 = 0;
for (int i = 0; i < 32; ++i)
{
++value;
--value2;
value3 += 2;
}
data[index] = value + value2 + value3;
}

[Fact]
[KernelMethod(nameof(ForCounterDataConstantKernel))]
public void ForCounterDataConstant()
{
using var buffer = Accelerator.Allocate<int>(Length);
Execute(buffer.Length, buffer.View);

var expected = Enumerable.Repeat(129, Length).ToArray();
Verify(buffer, expected);
}

internal static void NestedForCounterKernel(
Index1 index,
ArrayView<int> data,
Expand Down Expand Up @@ -121,6 +148,30 @@ public void NestedForCounter(int counter1, int counter2)
Verify(buffer, expected);
}

internal static void NestedForCounterConstantKernel(
Index1 index,
ArrayView<int> data)
{
int value = 0;
for (int i = 0; i < 10; ++i)
{
for (int j = 0; j < 20; ++j)
value += 2;
}
data[index] = value;
}

[Fact]
[KernelMethod(nameof(NestedForCounterConstantKernel))]
public void NestedForCounterConstant()
{
using var buffer = Accelerator.Allocate<int>(Length);
Execute(buffer.Length, buffer.View);

var expected = Enumerable.Repeat(2 * 10 * 20, Length).ToArray();
Verify(buffer, expected);
}

internal static void DoWhileKernel(
Index1 index,
ArrayView<int> data,
Expand All @@ -146,6 +197,31 @@ public void DoWhile()
Verify(buffer, expected);
}

internal static void DoWhileConstantKernel(
Index1 index,
ArrayView<int> data)
{
int counter = 38;
int value = 3;
do
{
++value;
}
while (counter-- > 0);
data[index] = value;
}

[Fact]
[KernelMethod(nameof(DoWhileConstantKernel))]
public void DoWhileConstant()
{
using var buffer = Accelerator.Allocate<int>(Length);
Execute(buffer.Length, buffer.View);

var expected = Enumerable.Repeat(42, Length).ToArray();
Verify(buffer, expected);
}

internal static void ContinueKernel(
Index1 index,
ArrayView<int> data,
Expand Down Expand Up @@ -263,6 +339,41 @@ public void BreakLoop(int counter, int counter2, int counter3, int result)
var expected = Enumerable.Repeat(result, Length).ToArray();
Verify(buffer, expected);
}

internal static void NestedBreakContinueConstantKernel(
Index1 index,
ArrayView<int> data)
{
int accumulate = 0;
int k = 0;
for (int i = 0; i < 32; ++i)
{
for (int j = 0; j < 13; ++j)
{
if (j == i)
continue;

if (++k == 9)
break;
}

if (i == 13)
continue;
++accumulate;
}
data[index] = accumulate;
}

[Fact]
[KernelMethod(nameof(NestedBreakContinueConstantKernel))]
public void NestedBreakContinueLoopConstant()
{
using var buffer = Accelerator.Allocate<int>(Length);
Execute(buffer.Length, buffer.View);

var expected = Enumerable.Repeat(31, Length).ToArray();
Verify(buffer, expected);
}
}
}

Expand Down

0 comments on commit 59044b8

Please sign in to comment.