diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/getter-setter.slang | 2 | ||||
| -rw-r--r-- | tests/autodiff/reverse-inout-param-2.slang | 6 | ||||
| -rw-r--r-- | tests/autodiff/reverse-inout-param-2.slang.expected.txt | 2 | ||||
| -rw-r--r-- | tests/diagnostics/autodiff-data-flow-3.slang | 26 | ||||
| -rw-r--r-- | tests/diagnostics/autodiff-data-flow-3.slang.expected | 8 |
5 files changed, 39 insertions, 5 deletions
diff --git a/tests/autodiff/getter-setter.slang b/tests/autodiff/getter-setter.slang index 705604bbb..06caadce8 100644 --- a/tests/autodiff/getter-setter.slang +++ b/tests/autodiff/getter-setter.slang @@ -45,7 +45,7 @@ typedef DifferentialPair<A> dpA; A f(A a) { A aout; - aout.y = 2 * a.x; + aout.y = detach(2 * a.x); aout.x = 5 * a.x; return aout; diff --git a/tests/autodiff/reverse-inout-param-2.slang b/tests/autodiff/reverse-inout-param-2.slang index 18eb825e6..813238863 100644 --- a/tests/autodiff/reverse-inout-param-2.slang +++ b/tests/autodiff/reverse-inout-param-2.slang @@ -28,7 +28,7 @@ void g( v1 = v2; v2.nd = v2.nd + 1.0; p.n = v1.nd + 1.0; - p.m = v2.nd + 1.0 + x; // == v2.nd + 2 + x == 1 + 2 + x == 3+x + p.m = detach(v2.nd + 1.0 + x); // == v2.nd + 2 + x == 1 + 2 + x == 3+x po = p; po.m += 1.0; // == 4+x y = p.m * x; // == (3+x)*x @@ -39,7 +39,7 @@ void f(inout no_diff D p, out no_diff D p0, out ND v1, inout ND v2, float x, out { // v2.nd is 3. g(p, p0, v1, v2, x, y); - // v2.nd is now 4, now g is equivalent to (4+x)*x. + // v2.nd is now 4, now g is equivalent to detach(4+x)*x, so g' = 9. g(p, p0, v1, v2, x, y); } @@ -64,7 +64,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) __bwd_diff(f)(p, v2, x, yDiffOut); outputBuffer[0] = x.p; // should be 5, since bwd_diff does not write back new primal val. - outputBuffer[1] = x.d; // 14 + outputBuffer[1] = x.d; // 9 outputBuffer[2] = p.m; // 1.0 outputBuffer[3] = p.n; // 2.0 outputBuffer[4] = v2.nd; // 1.0 diff --git a/tests/autodiff/reverse-inout-param-2.slang.expected.txt b/tests/autodiff/reverse-inout-param-2.slang.expected.txt index 65933cc7d..492ad8d10 100644 --- a/tests/autodiff/reverse-inout-param-2.slang.expected.txt +++ b/tests/autodiff/reverse-inout-param-2.slang.expected.txt @@ -1,6 +1,6 @@ type: float 5.000000 -14.000000 +9.000000 1.000000 2.000000 1.000000 diff --git a/tests/diagnostics/autodiff-data-flow-3.slang b/tests/diagnostics/autodiff-data-flow-3.slang new file mode 100644 index 000000000..0a8e3e58a --- /dev/null +++ b/tests/diagnostics/autodiff-data-flow-3.slang @@ -0,0 +1,26 @@ +//DIAGNOSTIC_TEST:SIMPLE: + +struct DiffT : IDifferentiable +{ + float f; +} +struct NoDiffField +{ + DiffT fp; +} + +[BackwardDifferentiable] +float g(float x) +{ + NoDiffField obj; + obj.fp.f = x * x; // Error, this location cannot hold derivative. + return obj.fp.f; +} + +[BackwardDifferentiable] +float h(float x) +{ + NoDiffField obj; + obj.fp.f = detach(x * x); // OK. + return obj.fp.f; +} diff --git a/tests/diagnostics/autodiff-data-flow-3.slang.expected b/tests/diagnostics/autodiff-data-flow-3.slang.expected new file mode 100644 index 000000000..73381cf58 --- /dev/null +++ b/tests/diagnostics/autodiff-data-flow-3.slang.expected @@ -0,0 +1,8 @@ +result code = -1 +standard error = { +tests/diagnostics/autodiff-data-flow-3.slang(16): error 41024: derivative is lost during assignment to non-differentiable location. Use 'detach()' to clarify intention. + obj.fp.f = x * x; // Error, this location cannot hold derivative. + ^ +} +standard output = { +} |
