diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2023-04-26 15:46:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-26 15:46:24 -0400 |
| commit | e1940e53c0f76e91a2616693b261beb9190015be (patch) | |
| tree | 2ef14f1e81eb1cf0b003cf93102afdbd542f4750 /tests/autodiff | |
| parent | a1739e87b5fb90b0a39c583f8d2468f851869c9f (diff) | |
For C-like targets, emit resource declarations before other globals (#2843)
* For C-like targets, emit resource declarations before other globals
* Remove unused tests
Diffstat (limited to 'tests/autodiff')
| -rw-r--r-- | tests/autodiff/inout-custom-derivative.slang | 35 | ||||
| -rw-r--r-- | tests/autodiff/inout-custom-derivative.slang.expected.txt | 8 |
2 files changed, 43 insertions, 0 deletions
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<float> outputBuffer; + +typedef DifferentialPair<float> dpfloat; +typedef float.Differential dfloat; + +[BackwardDerivative(bwd_f)] +void f(float x, out float y) +{ + y = x * x; +} + +void bwd_f(inout DifferentialPair<float> dpx, in float.Differential dy) +{ + dpx = DifferentialPair<float>(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 |
