From d58e08f8237a1888ceaad53402d534679ea83b1a Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 18 Nov 2022 12:37:27 -0800 Subject: Data flow validation pass for diagnosing derivative loss. (#2523) --- tests/diagnostics/autodiff-data-flow.slang | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/diagnostics/autodiff-data-flow.slang (limited to 'tests/diagnostics/autodiff-data-flow.slang') 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; +} -- cgit v1.2.3