From 7398e1e09312ed4e19195e060de9a2c9a073fcc1 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 26 Sep 2024 00:10:45 -0400 Subject: Always run AD cleanup pass. (#5157) --- tests/autodiff/no-diff-strip.slang | 45 +++++++++++++++++++++++++ tests/autodiff/no-diff-strip.slang.expected.txt | 6 ++++ 2 files changed, 51 insertions(+) create mode 100644 tests/autodiff/no-diff-strip.slang create mode 100644 tests/autodiff/no-diff-strip.slang.expected.txt (limited to 'tests') diff --git a/tests/autodiff/no-diff-strip.slang b/tests/autodiff/no-diff-strip.slang new file mode 100644 index 000000000..ebcdd7972 --- /dev/null +++ b/tests/autodiff/no-diff-strip.slang @@ -0,0 +1,45 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +// This test just checks that we compile and run successfully. +// "NDBuffer" & "no_diff NDBuffer" should resolve to the same code-gen type. +// + +struct NDBuffer +{ + RWStructuredBuffer buffer; + int[N] strides; + int[N] transform; + + T get(int[N] index) { return buffer[index[0]]; } +} + +float _read_slice(int2 index, NDBuffer texture) +{ + return texture.get({index.x, index.y}); +} + +[Differentiable] +void _trampoline(no_diff in vector index, in no_diff NDBuffer texture, no_diff out float _result) +{ + _result = _read_slice(index, texture); +} + + +[shader("compute")] +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + NDBuffer texture; + texture.buffer = outputBuffer; + texture.strides = {1, 1}; + + float result; + _trampoline({dispatchThreadID.x, dispatchThreadID.y}, texture, result); + outputBuffer[dispatchThreadID.x] = result; +} + diff --git a/tests/autodiff/no-diff-strip.slang.expected.txt b/tests/autodiff/no-diff-strip.slang.expected.txt new file mode 100644 index 000000000..e070cf84d --- /dev/null +++ b/tests/autodiff/no-diff-strip.slang.expected.txt @@ -0,0 +1,6 @@ +type: float +0.000000 +0.000000 +0.000000 +0.000000 +0.000000 -- cgit v1.2.3