summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2023-07-12 18:02:36 -0400
committerGitHub <noreply@github.com>2023-07-12 18:02:36 -0400
commitbbd9c2e6d7b57f5acc3238083ab2f7c7b140df5e (patch)
treeb6abec59b4ff3fe92436db35c1e61a6df236f550 /tests
parent4ed3aafa20b667329f2f9dea94d7c65dc2e80db4 (diff)
Extend `no_diff` to support subscript operations on resources and array variables… (#2981)
* Extend `no_diff` to support subscript operations on resources and array variables * Update autodiff.slang.expected
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/no-diff-array-access.slang23
-rw-r--r--tests/autodiff/no-diff-array-access.slang.expected.txt6
-rw-r--r--tests/diagnostics/autodiff.slang.expected6
3 files changed, 32 insertions, 3 deletions
diff --git a/tests/autodiff/no-diff-array-access.slang b/tests/autodiff/no-diff-array-access.slang
new file mode 100644
index 000000000..df8c8faa0
--- /dev/null
+++ b/tests/autodiff/no-diff-array-access.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 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+typedef DifferentialPair<float> dpfloat;
+typedef DifferentialPair<float3> dpfloat3;
+
+[ForwardDifferentiable]
+float f(float x, float[3] y)
+{
+ return x * no_diff(outputBuffer[4]) + y[2] * x * no_diff(y[1]);
+}
+
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ var dpx = fwd_diff(f)(DifferentialPair<float>(1.0f, 1.0f), DifferentialPair<float[3]>( { 1.0f, 2.0f, 3.0f }, { 1.0f, 2.0f, 3.0f }));
+ outputBuffer[0] = dpx.p; // Expect: 6.0
+ outputBuffer[1] = dpx.d; // Expect: 12.0
+}
diff --git a/tests/autodiff/no-diff-array-access.slang.expected.txt b/tests/autodiff/no-diff-array-access.slang.expected.txt
new file mode 100644
index 000000000..504eaec3e
--- /dev/null
+++ b/tests/autodiff/no-diff-array-access.slang.expected.txt
@@ -0,0 +1,6 @@
+type: float
+6.000000
+12.000000
+0.000000
+0.000000
+0.000000
diff --git a/tests/diagnostics/autodiff.slang.expected b/tests/diagnostics/autodiff.slang.expected
index d075b9406..95da2a6d3 100644
--- a/tests/diagnostics/autodiff.slang.expected
+++ b/tests/diagnostics/autodiff.slang.expected
@@ -1,12 +1,12 @@
result code = -1
standard error = {
-tests/diagnostics/autodiff.slang(35): error 38031: 'no_diff' can only be used to decorate a call.
+tests/diagnostics/autodiff.slang(30): error 38031: 'no_diff' can only be used to decorate a call or a subscript operation
float x1 = no_diff x; // invalid use of no_diff here.
^~~~~~~
-tests/diagnostics/autodiff.slang(36): error 38032: use 'no_diff' on a call to a differentiable function has no meaning.
+tests/diagnostics/autodiff.slang(31): error 38032: use 'no_diff' on a call to a differentiable function has no meaning.
return no_diff f(x); // no_diff on a differentiable call has no meaning.
^~~~~~~
-tests/diagnostics/autodiff.slang(41): error 38033: cannot use 'no_diff' in a non-differentiable function.
+tests/diagnostics/autodiff.slang(36): error 38033: cannot use 'no_diff' in a non-differentiable function.
return no_diff nonDiff(x); // no_diff in a non-differentiable function
^~~~~~~
}