diff options
| author | Yong He <yonghe@outlook.com> | 2023-11-03 12:49:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-03 12:49:23 -0700 |
| commit | cc222702a8d7a1fccf8ad14b256570bcec1554ae (patch) | |
| tree | ddc6aeba05fe3cbc8618d7b1cb5e63a9d711667d /tests | |
| parent | 911a4401b08f6199e18b32349c236c186a2dd128 (diff) | |
Add more diagnostics on invalid custom derivative use. (#3309)
* Add more diagnostics on invalid custom derivative use.
* cleanup.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/custom-derivative-generic.slang | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/autodiff/custom-derivative-generic.slang b/tests/autodiff/custom-derivative-generic.slang new file mode 100644 index 000000000..4ecde65cf --- /dev/null +++ b/tests/autodiff/custom-derivative-generic.slang @@ -0,0 +1,32 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type + +struct Buggy<let N : int> +{ + float m(float x) { return N * x; } + + [BackwardDerivativeOf(m)] + void mDiff(inout DifferentialPair<float> x, float dResult) + { + updateDiff(x, N * dResult); + } +} + +[Differentiable] +float test(float x) +{ + Buggy<2> b; + return b.m(x); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + var a = diffPair(3.0); + __bwd_diff(test)(a, 1.0); + outputBuffer[dispatchThreadID.x] = a.d; + // CHECK: 2.0 +} |
