summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2023-02-28 21:24:24 -0500
committerGitHub <noreply@github.com>2023-02-28 21:24:24 -0500
commit3c32dd951c5d69b5568929e0038e693553efca79 (patch)
tree377b4b921e82cfc201a768d88a70f12a16586614 /tests
parent7eeda30df967671c410de4fd725f91f9078d74c4 (diff)
AD: Fixed do-while loops (#2683)
* WIP: Fix for do-while loops * Added a somewhat hacky fix for do-while loops * Redid the indexed region map builder step to fix issue with the nested loops test * rename * Used managed pointers
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/reverse-do-while.slang47
-rw-r--r--tests/autodiff/reverse-do-while.slang.expected.txt6
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-do-while.slang b/tests/autodiff/reverse-do-while.slang
new file mode 100644
index 000000000..983863f5e
--- /dev/null
+++ b/tests/autodiff/reverse-do-while.slang
@@ -0,0 +1,47 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj
+
+//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_simple_while(float y)
+{
+ float t = y;
+
+ bool keepGoing = true;
+ int i = 2;
+
+ [MaxIters(3)]
+ do
+ {
+ i++;
+ t = t * t;
+
+ keepGoing = (i < 5);
+ } while (keepGoing);
+
+ return t;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ {
+ dpfloat dpa = dpfloat(1.0, 0.0);
+
+ __bwd_diff(test_simple_while)(dpa, 1.0f);
+ outputBuffer[0] = dpa.d; // Expect: 8.0
+ }
+
+ {
+ dpfloat dpa = dpfloat(0.4, 0.0);
+
+ __bwd_diff(test_simple_while)(dpa, 1.0f);
+ outputBuffer[1] = dpa.d; // Expect: 0.0131072
+ }
+}
diff --git a/tests/autodiff/reverse-do-while.slang.expected.txt b/tests/autodiff/reverse-do-while.slang.expected.txt
new file mode 100644
index 000000000..76b7cf779
--- /dev/null
+++ b/tests/autodiff/reverse-do-while.slang.expected.txt
@@ -0,0 +1,6 @@
+type: float
+8.000000
+0.013107
+0.000000
+0.000000
+0.000000