diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2023-01-04 23:40:13 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-04 10:10:13 -0800 |
| commit | 7f64b2a9e3eb7aea13de550bd24c1aea7787c94b (patch) | |
| tree | 40afc50c9fb227b8728487403d3f9b712a1509b2 /tests/autodiff | |
| parent | e8f977a00f5d131ec2d51d2a026d6452e8f762f0 (diff) | |
Multi-block reverse-mode autodiff (#2576)
* Initial multi-block implementation
* Implemented multi-block reverse-mode (without loops)
* Added logic to remove block-level decorations to avoid confusing IR simplification passes
* Fixed issues with block-level decorations during IR simplification by removing them prior to simplification.
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests/autodiff')
| -rw-r--r-- | tests/autodiff/reverse-control-flow.slang | 42 | ||||
| -rw-r--r-- | tests/autodiff/reverse-control-flow.slang.expected.txt | 6 |
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-control-flow.slang b/tests/autodiff/reverse-control-flow.slang new file mode 100644 index 000000000..7d2f518be --- /dev/null +++ b/tests/autodiff/reverse-control-flow.slang @@ -0,0 +1,42 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +typedef DifferentialPair<float> dpfloat; +typedef float.Differential dfloat; + +[BackwardDifferentiable] +float test_single_branch(float y) +{ + float o; + if (y > 0.5) + { + o = y * 2.0f; + } + else + { + o = y + 1.0f; + } + + return o; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + { + dpfloat dpa = dpfloat(1.0, 0.0); + + __bwd_diff(test_single_branch)(dpa, 1.0f); + outputBuffer[0] = dpa.d; // Expect: 2.0 + } + + { + dpfloat dpa = dpfloat(0.4, 0.0); + + __bwd_diff(test_single_branch)(dpa, 1.0f); + outputBuffer[1] = dpa.d; // Expect: 1.0 + } +} diff --git a/tests/autodiff/reverse-control-flow.slang.expected.txt b/tests/autodiff/reverse-control-flow.slang.expected.txt new file mode 100644 index 000000000..86aa47f11 --- /dev/null +++ b/tests/autodiff/reverse-control-flow.slang.expected.txt @@ -0,0 +1,6 @@ +type: float +2.000000 +1.000000 +0.000000 +0.000000 +0.000000 |
