summaryrefslogtreecommitdiff
path: root/tests/autodiff/reverse-loop.slang
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2023-01-30 11:46:36 -0500
committerGitHub <noreply@github.com>2023-01-30 08:46:36 -0800
commit134dd7eb26fc7988ae13559d276cbf337b4b9d27 (patch)
tree35bd06e6bebb4518bca805e14e85f8f9ef4341c6 /tests/autodiff/reverse-loop.slang
parent4a66e9729175a89833e5db784bb64e6a7f60cdf2 (diff)
Overhauled reverse-mode control flow handling (#2608)
* Added switch-case support; fixed non-diff parameter transposition * Made region propagation much more robust. Partial loop unzip implementation * WIP: Added most loop handling code, and a test. Still untested * Added CFG Normalization pass + CFG Reversal Pass + Loop Unzipping + most loop transcription * Add single-iter-loop test. * proj files * removed comments * Update reverse-loop.slang * Removed out-of-date code * Disabled IR validation during constructSSA phase of normalizeCFG. constructSSA now reuses sharedBuilder * Moved normalizeCFG() call to prepareFuncForBackwardDiff()
Diffstat (limited to 'tests/autodiff/reverse-loop.slang')
-rw-r--r--tests/autodiff/reverse-loop.slang40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-loop.slang b/tests/autodiff/reverse-loop.slang
new file mode 100644
index 000000000..6ae207080
--- /dev/null
+++ b/tests/autodiff/reverse-loop.slang
@@ -0,0 +1,40 @@
+//TEST_IGNORE_FILE:
+//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_simple_loop(float y)
+{
+ float t = y;
+
+ for (int i = 0; i < 3; i++)
+ {
+ t = t * t;
+ }
+
+ return t;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ {
+ dpfloat dpa = dpfloat(1.0, 0.0);
+
+ __bwd_diff(test_simple_loop)(dpa, 1.0f);
+ outputBuffer[0] = dpa.d; // Expect: 2.0
+ }
+
+ {
+ dpfloat dpa = dpfloat(0.4, 0.0);
+
+ __bwd_diff(test_simple_loop)(dpa, 1.0f);
+ outputBuffer[1] = dpa.d; // Expect: 1.0
+ }
+}