From 228e71dab7dfa18ece979f4099ec0c7d1e37e5ff Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 3 Feb 2023 16:44:33 -0800 Subject: Overhaul `transposeParameterBlock` to support `inout` params. (#2621) * Overhaul `transposeParameterBlock` to support `inout` params. * Small bug fixes. * Bug fix on differentiable intrinsic specialization. * Fixes. * Run autodiff tests on CPU. * Clean up. * More bug fixes., * Add test coverage on inout param. * Fix language server hinting for transcribed mutable params. --------- Co-authored-by: Yong He --- tests/autodiff/reverse-inout-param-0.slang | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/autodiff/reverse-inout-param-0.slang (limited to 'tests/autodiff/reverse-inout-param-0.slang') diff --git a/tests/autodiff/reverse-inout-param-0.slang b/tests/autodiff/reverse-inout-param-0.slang new file mode 100644 index 000000000..13bfb6277 --- /dev/null +++ b/tests/autodiff/reverse-inout-param-0.slang @@ -0,0 +1,31 @@ +//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; + +[BackwardDifferentiable] +void g(float x, out float y) +{ + y = (x + 1) * (x + 1); +} + +[BackwardDifferentiable] +void f(float x, out float y) +{ + g(x, y); + g(x, y); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + var x = diffPair(5.0); + float yDiffOut = 1.0; + + __bwd_diff(f)(x, yDiffOut); + + outputBuffer[0] = x.p; // should be 5, since bwd_diff does not write back new primal val. + outputBuffer[1] = x.d; // 12.0 +} \ No newline at end of file -- cgit v1.2.3