From e1940e53c0f76e91a2616693b261beb9190015be Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:46:24 -0400 Subject: For C-like targets, emit resource declarations before other globals (#2843) * For C-like targets, emit resource declarations before other globals * Remove unused tests --- tests/autodiff/inout-custom-derivative.slang | 35 ++++++++++++++++++++++ .../inout-custom-derivative.slang.expected.txt | 8 +++++ 2 files changed, 43 insertions(+) create mode 100644 tests/autodiff/inout-custom-derivative.slang create mode 100644 tests/autodiff/inout-custom-derivative.slang.expected.txt (limited to 'tests/autodiff') diff --git a/tests/autodiff/inout-custom-derivative.slang b/tests/autodiff/inout-custom-derivative.slang new file mode 100644 index 000000000..76c9cb74f --- /dev/null +++ b/tests/autodiff/inout-custom-derivative.slang @@ -0,0 +1,35 @@ +//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 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +typedef DifferentialPair dpfloat; +typedef float.Differential dfloat; + +[BackwardDerivative(bwd_f)] +void f(float x, out float y) +{ + y = x * x; +} + +void bwd_f(inout DifferentialPair dpx, in float.Differential dy) +{ + dpx = DifferentialPair(dpx.p, 2.0 * dpx.p * dy); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + { + float o; + f(3.0, o); + + dpfloat dpa = dpfloat(2.0, 1.0); + dpfloat dpo = dpfloat(2.0, 1.0); + __bwd_diff(f)(dpa, o); + + outputBuffer[0] = o; // Expect: 9 + outputBuffer[1] = dpa.d; // Expect: 36 + } +} diff --git a/tests/autodiff/inout-custom-derivative.slang.expected.txt b/tests/autodiff/inout-custom-derivative.slang.expected.txt new file mode 100644 index 000000000..07757c1f5 --- /dev/null +++ b/tests/autodiff/inout-custom-derivative.slang.expected.txt @@ -0,0 +1,8 @@ +type: float +9.000000 +36.000000 +0.000000 +0.000000 +0.000000 +0.000000 +0.000000 -- cgit v1.2.3