From 721d2e8a2d457081cd3d9b081979d436b7002c2c Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 9 Mar 2020 20:03:42 -0400 Subject: CUDA Wave intrinsic vector/matrix support (#1267) * Distinguish between __activeMask and _getConvergedMask(). Remove need to pass in mask to CUDA wave impls. * Add support for vector/matrix Wave intrinsics for CUDA. Fix issue with CUDA parsing of errors. * Fix typo. Make WaveReadLineAt and WaveReadFirst work for vector/matrix types. * Fix typo. * Added equality wave intrinsic test. * Fix some typos * Added wave-lane-at.slang --- tests/hlsl-intrinsic/wave-equality.slang | 31 ++++++++++++++++ .../wave-equality.slang.expected.txt | 4 +++ tests/hlsl-intrinsic/wave-lane-at.slang | 41 ++++++++++++++++++++++ .../hlsl-intrinsic/wave-lane-at.slang.expected.txt | 4 +++ 4 files changed, 80 insertions(+) create mode 100644 tests/hlsl-intrinsic/wave-equality.slang create mode 100644 tests/hlsl-intrinsic/wave-equality.slang.expected.txt create mode 100644 tests/hlsl-intrinsic/wave-lane-at.slang create mode 100644 tests/hlsl-intrinsic/wave-lane-at.slang.expected.txt (limited to 'tests') diff --git a/tests/hlsl-intrinsic/wave-equality.slang b/tests/hlsl-intrinsic/wave-equality.slang new file mode 100644 index 000000000..d12d8cfbc --- /dev/null +++ b/tests/hlsl-intrinsic/wave-equality.slang @@ -0,0 +1,31 @@ +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -profile cs_6_0 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int idx = int(dispatchThreadID.x); + + int value = 0; + + // Scalar + + value |= WaveActiveAllEqual(idx * 0 + 1) ? 1 : 0; // true + value |= WaveActiveAllEqual(idx & 2) ? 2 : 0; // false + + // Vector + + int2 v0 = int2(idx & 0xf0, (idx & 0xf00) + 1); // (0, 1) + int2 v1 = int2(idx & 2, (idx & 2) + 1); + + value |= WaveActiveAllEqual(v0) ? 0x10 : 0; // true + value |= WaveActiveAllEqual(v1) ? 0x20 : 0; // false + + outputBuffer[idx] = value; +} \ No newline at end of file diff --git a/tests/hlsl-intrinsic/wave-equality.slang.expected.txt b/tests/hlsl-intrinsic/wave-equality.slang.expected.txt new file mode 100644 index 000000000..2bf571888 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-equality.slang.expected.txt @@ -0,0 +1,4 @@ +11 +11 +11 +11 diff --git a/tests/hlsl-intrinsic/wave-lane-at.slang b/tests/hlsl-intrinsic/wave-lane-at.slang new file mode 100644 index 000000000..ca05d985d --- /dev/null +++ b/tests/hlsl-intrinsic/wave-lane-at.slang @@ -0,0 +1,41 @@ +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -profile cs_6_0 +// Disabled because on GLSL targets the lane index *must* be a const expr - and in this test it is not. +//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + int idx = int(dispatchThreadID.x); + + int value = 0; + + // Scalar + + value += WaveReadLaneAt(idx, (idx + 1) & 3); + + // vector + + { + float2 v = float2(idx + 1, idx + 2); + float2 readValue = WaveReadLaneAt(v, (idx - 1) & 3); + + value += int(readValue[0] + readValue[1]); + } + + // matrix + { + matrix v = matrix(idx, idx - 1, idx * 3, idx - 2); + + matrix readValue = WaveReadLaneAt(v, (idx - 1) & 3); + + value += int(readValue[0][0] + readValue[0][1] + readValue[1][0] + readValue[1][1]); + } + + outputBuffer[idx] = value; +} \ No newline at end of file diff --git a/tests/hlsl-intrinsic/wave-lane-at.slang.expected.txt b/tests/hlsl-intrinsic/wave-lane-at.slang.expected.txt new file mode 100644 index 000000000..a327b0804 --- /dev/null +++ b/tests/hlsl-intrinsic/wave-lane-at.slang.expected.txt @@ -0,0 +1,4 @@ +19 +2 +B +10 -- cgit v1.2.3