diff options
| author | Yong He <yonghe@outlook.com> | 2023-09-28 18:07:40 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-28 18:07:40 -0700 |
| commit | b7d318f48db2cb83a41d665f1727ae93fc555124 (patch) | |
| tree | d81d69cbba264cd059bbe67f29235226032c4793 /tests/autodiff/constref-param.slang | |
| parent | e7238942ea003e134b325fa65296df8e19368e90 (diff) | |
Support `constref` parameters passing. (#3249)
* Support `constref` parameters passing.
* Fix.
* Fix.
* Add test and diagnostic on mix use of __constref and no_diff.
* check for [constref] on differentiable member method.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/autodiff/constref-param.slang')
| -rw-r--r-- | tests/autodiff/constref-param.slang | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/autodiff/constref-param.slang b/tests/autodiff/constref-param.slang new file mode 100644 index 000000000..5bce8e304 --- /dev/null +++ b/tests/autodiff/constref-param.slang @@ -0,0 +1,41 @@ +//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 +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cpu -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +struct NonDiff +{ + float a; +} + +[Differentiable] +float myFunc(__constref NonDiff fIn, float x, __constref no_diff float y) +{ + return x * fIn.a + y; +} + +// test that the ordering of no_diff and __constref doesn't matter. +[Differentiable] +float myFunc2(__constref NonDiff fIn, float x, no_diff __constref float y) +{ + return x * fIn.a + y; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + float a = 10.0; + NonDiff fIn = { a }; + DifferentialPair<float> dpx = DifferentialPair<float>(4.f, 1.f); + float rs = __fwd_diff(myFunc)(fIn, dpx, 1.0).d; + float rs2 = __fwd_diff(myFunc2)(fIn, dpx, 1.0).d; + + // CHECK: 10.0 + // CHECK: 10.0 + + outputBuffer[0] = rs; + outputBuffer[1] = rs2; +} |
