diff options
| author | Yong He <yonghe@outlook.com> | 2022-11-30 13:24:39 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-30 13:24:39 -0800 |
| commit | 09684224d5ab63f530d66c0be65fa50e6fc5290b (patch) | |
| tree | 292d0f257b3d5a5e027892a5a1e046d60166aadd /tests | |
| parent | f52b4de3b29ee27213b7d60fb620a0d5d50b49f9 (diff) | |
Support `no_diff` on existential typed params. (#2540)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/no-diff-param-2.slang | 38 | ||||
| -rw-r--r-- | tests/autodiff/no-diff-param-2.slang.expected.txt | 5 |
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/autodiff/no-diff-param-2.slang b/tests/autodiff/no-diff-param-2.slang new file mode 100644 index 000000000..d29928d69 --- /dev/null +++ b/tests/autodiff/no-diff-param-2.slang @@ -0,0 +1,38 @@ +//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], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +typedef DifferentialPair<float> dpfloat; + +interface IFoo : IDifferentiable +{ + [ForwardDifferentiable] + float getVal(); +} + +struct A : IFoo +{ + float x; + [ForwardDifferentiable] + float getVal(){return x;} +} + +[ForwardDifferentiable] +float f(float x, no_diff IFoo y) +{ + return x * x + y.getVal(); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + { + A a; + a.x = 2.0; + let rs = __fwd_diff(f)(dpfloat(1.5, 1.0), a); + outputBuffer[0] = rs.p; // Expect: 6.25 + outputBuffer[1] = rs.d; // Expect: 3.0 + } +} diff --git a/tests/autodiff/no-diff-param-2.slang.expected.txt b/tests/autodiff/no-diff-param-2.slang.expected.txt new file mode 100644 index 000000000..18066089d --- /dev/null +++ b/tests/autodiff/no-diff-param-2.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +4.250000 +3.000000 +0.000000 +0.000000
\ No newline at end of file |
