diff options
| author | Yong He <yonghe@outlook.com> | 2022-10-27 11:06:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-27 11:06:14 -0700 |
| commit | 8e11063bfcec528e70f5e80e5db9fca7d4016737 (patch) | |
| tree | 60a4a492e732479bb1f72e76675b2b494c140b6b /tests | |
| parent | f7f0dcadd3b2aca4c0bcd03a96e11c617cf69fc2 (diff) | |
Auto synthesis of IDifferntial interface methods. (#2469)
* Auto synthesis of IDifferntial interface methods.
* Add comments.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/differential-method-synthesis.slang | 45 | ||||
| -rw-r--r-- | tests/autodiff/differential-method-synthesis.slang.expected.txt | 6 |
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/autodiff/differential-method-synthesis.slang b/tests/autodiff/differential-method-synthesis.slang new file mode 100644 index 000000000..73afc4411 --- /dev/null +++ b/tests/autodiff/differential-method-synthesis.slang @@ -0,0 +1,45 @@ +// Tests automatic synthesis of Differential type and method requirements. + +//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], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +struct B : IDifferentiable +{ + float x; +} + +struct A : IDifferentiable +{ + B b; + float y; +}; + +typedef __DifferentialPair<A> dpA; + +A nonDiff(A a) +{ + return a; +} + +__differentiate_jvp A f(A a) +{ + A aout; + aout.y = 2 * a.b.x; + aout.b.x = 5 * a.b.x; + + return nonDiff(aout); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + { + A a = {1.0, 2.0}; + A.Differential b = {0.2}; + dpA dpa = dpA(a, b); + outputBuffer[0] = __jvp(f)(dpa).d().b.x; // Expect: 0 + } +} diff --git a/tests/autodiff/differential-method-synthesis.slang.expected.txt b/tests/autodiff/differential-method-synthesis.slang.expected.txt new file mode 100644 index 000000000..e070cf84d --- /dev/null +++ b/tests/autodiff/differential-method-synthesis.slang.expected.txt @@ -0,0 +1,6 @@ +type: float +0.000000 +0.000000 +0.000000 +0.000000 +0.000000 |
