From 368ec3116ea0f10f44acbf76b5dc9e34d6ff3d32 Mon Sep 17 00:00:00 2001 From: Edward Liu Date: Mon, 14 Nov 2022 12:08:01 -0800 Subject: 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 --- tests/autodiff/backward-diff-smoke.slang | 25 ++++++++++++++++++++++ .../backward-diff-smoke.slang.expected.txt | 6 ++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/autodiff/backward-diff-smoke.slang create mode 100644 tests/autodiff/backward-diff-smoke.slang.expected.txt (limited to 'tests') 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 outputBuffer; + +typedef DifferentialPair 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 -- cgit v1.2.3