summaryrefslogtreecommitdiff
path: root/tests/autodiff/bool-return-control-flow.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-02-20 14:42:50 -0800
committerGitHub <noreply@github.com>2023-02-20 14:42:50 -0800
commit47715e625337d489f3c0131bbc2b849378b48a5a (patch)
treebc737c8f03ef537b2ac39860bbb922c7600edc43 /tests/autodiff/bool-return-control-flow.slang
parent8b05df4187117d61491f2fdbeb7d744146ad73f7 (diff)
Miscellaneous backward autodiff fixes. (#2665)
* Fix differentiable type registration * Fix use of non-differentiable return value in a differentiable func. * Fix use of primal inst that does not dominate the diff block. * Fix primal inst hoisting, and add missing type legalization logic. * Make `detach` defined on all differentiable T. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/autodiff/bool-return-control-flow.slang')
-rw-r--r--tests/autodiff/bool-return-control-flow.slang31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/autodiff/bool-return-control-flow.slang b/tests/autodiff/bool-return-control-flow.slang
new file mode 100644
index 000000000..9dd398a89
--- /dev/null
+++ b/tests/autodiff/bool-return-control-flow.slang
@@ -0,0 +1,31 @@
+//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], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+[BackwardDifferentiable]
+bool conditionFunc(no_diff float a, inout float x)
+{
+ x = x * a;
+ return x > 100.f;
+}
+
+[BackwardDifferentiable]
+float outerFunc(no_diff float a, float x)
+{
+ if (conditionFunc(a, x))
+ return x;
+ else
+ return -x;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ float a = 10.0;
+ DifferentialPair<float> dpx = DifferentialPair<float>(4.f, 1.f);
+ __bwd_diff(outerFunc)(a, dpx, 1.0);
+
+ outputBuffer[0] = dpx.d;
+} \ No newline at end of file