summaryrefslogtreecommitdiff
path: root/tests/diagnostics/autodiff-data-flow.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-11-18 12:37:27 -0800
committerGitHub <noreply@github.com>2022-11-18 12:37:27 -0800
commitd58e08f8237a1888ceaad53402d534679ea83b1a (patch)
treee66838e0dc31fc12ebd7c1acecbb5060e8808366 /tests/diagnostics/autodiff-data-flow.slang
parent0a050a439fa91b66f2020421d4fec3e60aed4112 (diff)
Data flow validation pass for diagnosing derivative loss. (#2523)
Diffstat (limited to 'tests/diagnostics/autodiff-data-flow.slang')
-rw-r--r--tests/diagnostics/autodiff-data-flow.slang38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/diagnostics/autodiff-data-flow.slang b/tests/diagnostics/autodiff-data-flow.slang
new file mode 100644
index 000000000..93c76c07e
--- /dev/null
+++ b/tests/diagnostics/autodiff-data-flow.slang
@@ -0,0 +1,38 @@
+//DIAGNOSTIC_TEST:SIMPLE:
+
+float nonDiff(float x)
+{
+ return x;
+}
+
+[ForwardDifferentiable]
+float f(float x)
+{
+ float val = 0;
+ if (x > 5)
+ val = x + 1;
+ else
+ val = nonDiff(x * 2.0f);
+ // Not all path propagates derivatives through.
+ return val;
+}
+
+// error: function does not return a differentiable value.
+[ForwardDifferentiable]
+void g(float x)
+{
+ float val = 0;
+ if (x > 5)
+ val = x + 1;
+ return;
+}
+
+
+[ForwardDifferentiable]
+float h(float x)
+{
+ float val = 0;
+ // no diagnostic by clarifying intention.
+ val = no_diff(nonDiff(x * 2.0f));
+ return val;
+}