summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/differential-method-synthesis.slang45
-rw-r--r--tests/autodiff/differential-method-synthesis.slang.expected.txt6
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