summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/reverse-control-flow.slang42
-rw-r--r--tests/autodiff/reverse-control-flow.slang.expected.txt6
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-control-flow.slang b/tests/autodiff/reverse-control-flow.slang
new file mode 100644
index 000000000..7d2f518be
--- /dev/null
+++ b/tests/autodiff/reverse-control-flow.slang
@@ -0,0 +1,42 @@
+//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 float.Differential dfloat;
+
+[BackwardDifferentiable]
+float test_single_branch(float y)
+{
+ float o;
+ if (y > 0.5)
+ {
+ o = y * 2.0f;
+ }
+ else
+ {
+ o = y + 1.0f;
+ }
+
+ return o;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ {
+ dpfloat dpa = dpfloat(1.0, 0.0);
+
+ __bwd_diff(test_single_branch)(dpa, 1.0f);
+ outputBuffer[0] = dpa.d; // Expect: 2.0
+ }
+
+ {
+ dpfloat dpa = dpfloat(0.4, 0.0);
+
+ __bwd_diff(test_single_branch)(dpa, 1.0f);
+ outputBuffer[1] = dpa.d; // Expect: 1.0
+ }
+}
diff --git a/tests/autodiff/reverse-control-flow.slang.expected.txt b/tests/autodiff/reverse-control-flow.slang.expected.txt
new file mode 100644
index 000000000..86aa47f11
--- /dev/null
+++ b/tests/autodiff/reverse-control-flow.slang.expected.txt
@@ -0,0 +1,6 @@
+type: float
+2.000000
+1.000000
+0.000000
+0.000000
+0.000000