summaryrefslogtreecommitdiff
path: root/tests/autodiff/long-loop.slang
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2023-05-06 03:03:25 -0400
committerGitHub <noreply@github.com>2023-05-06 00:03:25 -0700
commit271dc1b98d3887b6297c5407dc67692716687f4d (patch)
treea714a41f6a490000545e82cadd20561a020b0a1e /tests/autodiff/long-loop.slang
parent0602eaaba32bdbaf3f99ab8987e97419cba395aa (diff)
Don't store loop induction values + fix minor issue (#2872)
Diffstat (limited to 'tests/autodiff/long-loop.slang')
-rw-r--r--tests/autodiff/long-loop.slang36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/autodiff/long-loop.slang b/tests/autodiff/long-loop.slang
new file mode 100644
index 000000000..69652dbf0
--- /dev/null
+++ b/tests/autodiff/long-loop.slang
@@ -0,0 +1,36 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+//TEST:SIMPLE(filecheck=CHECK): -target hlsl -profile cs_5_0 -entry computeMain -line-directive-mode none
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+[BackwardDifferentiable]
+float sin_series(float x, int iterations)
+{
+ float result = x;
+ float term = x;
+ [MaxIters(30)]
+ for (int i = 1; i < iterations; i++)
+ {
+ term *= -1.0f * x * x / ((2 * i) * (2 * i + 1));
+ result += term;
+ }
+ return result;
+}
+
+// Check that the intermediate context of sin_series does not have an array for `i`.
+
+// CHECK: struct s_bwd_sin_series_Intermediates
+// CHECK-NOT: int {{[A-Za-z0-9_]+}}[{{.*}}]
+// CHECK: }
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ var x = diffPair(float.getPi(), 1.0);
+
+ __bwd_diff(sin_series)(x, 30, 1.0f);
+
+ outputBuffer[0] = x.d; // -1.0
+}