From 441e13e13f30b96eb04c05725ad7fe1983c92f53 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:52:49 -0400 Subject: Various AD Fixes (#3263) * Various fixes * Remove unused parameter * Update slang-ir-loop-unroll.cpp --------- Co-authored-by: Yong He --- .../autodiff/generic-differential-synthesis.slang | 35 ++++++++++++++++++++++ ...neric-differential-synthesis.slang.expected.txt | 5 ++++ 2 files changed, 40 insertions(+) create mode 100644 tests/autodiff/generic-differential-synthesis.slang create mode 100644 tests/autodiff/generic-differential-synthesis.slang.expected.txt (limited to 'tests') diff --git a/tests/autodiff/generic-differential-synthesis.slang b/tests/autodiff/generic-differential-synthesis.slang new file mode 100644 index 000000000..8c858b9b3 --- /dev/null +++ b/tests/autodiff/generic-differential-synthesis.slang @@ -0,0 +1,35 @@ +//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 outputBuffer; + +__generic +struct Foo : IDifferentiable +{ + float x[C]; +}; + +[Differentiable] +Foo<3> getFoo(float x) +{ + return { { x, x, x } }; +} + +[Differentiable] +float foobar(float x) +{ + int i = 3 * int(floor(x)); + Foo<3> foo = getFoo(x); + return foo.x[i] * foo.x[i]; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + { + float a = 0.5; + var d = fwd_diff(foobar)(diffPair(a, 1.0)).d; + outputBuffer[0] = d; + } +} diff --git a/tests/autodiff/generic-differential-synthesis.slang.expected.txt b/tests/autodiff/generic-differential-synthesis.slang.expected.txt new file mode 100644 index 000000000..97de29f1f --- /dev/null +++ b/tests/autodiff/generic-differential-synthesis.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +1.000000 +0.000000 +0.000000 +0.000000 -- cgit v1.2.3