summaryrefslogtreecommitdiff
path: root/tests/autodiff
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2023-10-05 12:52:49 -0400
committerGitHub <noreply@github.com>2023-10-05 09:52:49 -0700
commit441e13e13f30b96eb04c05725ad7fe1983c92f53 (patch)
treeaee5c31b62876ef8ad60a37b2a4767b6f1a299c6 /tests/autodiff
parent65751ce222adb302e62b5b7b6312de65638abed5 (diff)
Various AD Fixes (#3263)
* Various fixes * Remove unused parameter * Update slang-ir-loop-unroll.cpp --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests/autodiff')
-rw-r--r--tests/autodiff/generic-differential-synthesis.slang35
-rw-r--r--tests/autodiff/generic-differential-synthesis.slang.expected.txt5
2 files changed, 40 insertions, 0 deletions
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<float> outputBuffer;
+
+__generic<let C : int>
+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