diff options
| author | Yong He <yonghe@outlook.com> | 2023-03-08 21:52:34 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-08 21:52:34 -0800 |
| commit | 86fc50c5092fbccf6072dcf7bbdfafb8915f02c8 (patch) | |
| tree | b4f9eb6cb1eea88145fde0bd1f670a8803120257 /tests/autodiff/primal-substitute.slang | |
| parent | 257733f328f38a763c8b0c8830ff4c0d34ec9491 (diff) | |
Add support for `[PrimalSubstitute]` and `[PrimalSubstituteOf]`. (#2691)
* Add support for `[PrimalSubstitute]` and `[PrimalSubstituteOf]`.
* Fix
* Fix.
* Cleanup.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/autodiff/primal-substitute.slang')
| -rw-r--r-- | tests/autodiff/primal-substitute.slang | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/autodiff/primal-substitute.slang b/tests/autodiff/primal-substitute.slang new file mode 100644 index 000000000..01f221f2a --- /dev/null +++ b/tests/autodiff/primal-substitute.slang @@ -0,0 +1,27 @@ +//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<float> outputBuffer; + +float original(float x) +{ + return x * x; +} + +[PrimalSubstituteOf(original)] +[BackwardDifferentiable] +float primalSubst(float x) +{ + return 2.0f * x * x; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + var a = diffPair(3.0, 1.0); + __bwd_diff(original)(a, 1.0); + outputBuffer[0] = a.d; // Expect: 12.0 + outputBuffer[1] = __fwd_diff(original)(diffPair(3.0, 1.0)).p; // Expect: 18.0 +} |
