summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-11-29 18:17:33 -0800
committerGitHub <noreply@github.com>2022-11-29 18:17:33 -0800
commitf52b4de3b29ee27213b7d60fb620a0d5d50b49f9 (patch)
treed4570c53045bca8e9411e884b0905d9384430a58 /tests
parentf5581786a1891cedb165adb1afe71fe34f26e030 (diff)
Allow `no_diff` modifier on parameters (#2538)
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/no-diff-param.slang23
-rw-r--r--tests/autodiff/no-diff-param.slang.expected.txt5
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/autodiff/no-diff-param.slang b/tests/autodiff/no-diff-param.slang
new file mode 100644
index 000000000..b7c754889
--- /dev/null
+++ b/tests/autodiff/no-diff-param.slang
@@ -0,0 +1,23 @@
+//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;
+
+typedef DifferentialPair<float> dpfloat;
+
+[ForwardDifferentiable]
+float f(float x, no_diff float y)
+{
+ return x * x + y * y;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ {
+ let rs = __fwd_diff(f)(dpfloat(1.5, 1.0), 2.0);
+ outputBuffer[0] = rs.p; // Expect: 6.25
+ outputBuffer[1] = rs.d; // Expect: 3.0
+ }
+}
diff --git a/tests/autodiff/no-diff-param.slang.expected.txt b/tests/autodiff/no-diff-param.slang.expected.txt
new file mode 100644
index 000000000..b4bbbf1d4
--- /dev/null
+++ b/tests/autodiff/no-diff-param.slang.expected.txt
@@ -0,0 +1,5 @@
+type: float
+6.250000
+3.000000
+0.000000
+0.000000 \ No newline at end of file