From 8e11063bfcec528e70f5e80e5db9fca7d4016737 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Oct 2022 11:06:14 -0700 Subject: Auto synthesis of IDifferntial interface methods. (#2469) * Auto synthesis of IDifferntial interface methods. * Add comments. Co-authored-by: Yong He --- tests/autodiff/differential-method-synthesis.slang | 45 ++++++++++++++++++++++ ...ifferential-method-synthesis.slang.expected.txt | 6 +++ 2 files changed, 51 insertions(+) create mode 100644 tests/autodiff/differential-method-synthesis.slang create mode 100644 tests/autodiff/differential-method-synthesis.slang.expected.txt (limited to 'tests') 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 outputBuffer; + +struct B : IDifferentiable +{ + float x; +} + +struct A : IDifferentiable +{ + B b; + float y; +}; + +typedef __DifferentialPair 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 -- cgit v1.2.3