diff options
| author | Edward Liu <shiqiu1105@gmail.com> | 2022-11-14 12:08:01 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-14 12:08:01 -0800 |
| commit | 368ec3116ea0f10f44acbf76b5dc9e34d6ff3d32 (patch) | |
| tree | 3d9def111db278affb8413bddb5aab9ce3cf73a6 /tests | |
| parent | 623f5c36e0dc8190753aa5fa2e89f1010c367c67 (diff) | |
Minimum binary arithmetic reverse autodiff working. (#2514)
* Initial plumbing of backward autodiff in the frontend.
* More plumbing.
* Initial reverse autodiff working.
* Bug fixes.
* Misc.
* Remove redundant code.
* More clean up.
* Misc.
* Rebase and add backward diff test.
* Disable test.
* Clean up.
* Minor fix.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/backward-diff-smoke.slang | 25 | ||||
| -rw-r--r-- | tests/autodiff/backward-diff-smoke.slang.expected.txt | 6 |
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/autodiff/backward-diff-smoke.slang b/tests/autodiff/backward-diff-smoke.slang new file mode 100644 index 000000000..3d0d8970d --- /dev/null +++ b/tests/autodiff/backward-diff-smoke.slang @@ -0,0 +1,25 @@ +//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(float x, float y) +{ + return 2.0f * x + y * 4.0f - x; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + dpfloat dpa = dpfloat(2.0, 0.0); + dpfloat dpb = dpfloat(1.5, 0.0); + + __bwd_diff(test)(dpa, dpb, 1.0f); + outputBuffer[0] = dpa.d; // Expect: 1 + outputBuffer[1] = dpb.d; // Expect: 4 +} diff --git a/tests/autodiff/backward-diff-smoke.slang.expected.txt b/tests/autodiff/backward-diff-smoke.slang.expected.txt new file mode 100644 index 000000000..8b514833c --- /dev/null +++ b/tests/autodiff/backward-diff-smoke.slang.expected.txt @@ -0,0 +1,6 @@ +type: float +1.0 +4.0 +0.0 +0.0 +0.0
\ No newline at end of file |
