diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2023-03-15 22:26:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-15 19:26:58 -0700 |
| commit | 71efd949fa5276e2464416fcf237f8fd2c486281 (patch) | |
| tree | a5b24cd077f2ecc3f74d4dd4671c8260eb6e9b67 /tests/autodiff/reverse-control-flow-1.slang | |
| parent | 38e62199cc75ce34608491c8dd299eb330bde518 (diff) | |
AD: Primal-Hoisting Rework + Checkpoint Policy Framework (#2702)
Diffstat (limited to 'tests/autodiff/reverse-control-flow-1.slang')
| -rw-r--r-- | tests/autodiff/reverse-control-flow-1.slang | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-control-flow-1.slang b/tests/autodiff/reverse-control-flow-1.slang new file mode 100644 index 000000000..7d2f518be --- /dev/null +++ b/tests/autodiff/reverse-control-flow-1.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 + } +} |
