diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/generic-impl-jvp.slang | 10 | ||||
| -rw-r--r-- | tests/autodiff/reverse-loop.slang | 1 | ||||
| -rw-r--r-- | tests/diagnostics/autodiff-data-flow.slang | 5 | ||||
| -rw-r--r-- | tests/diagnostics/autodiff-data-flow.slang.expected | 3 | ||||
| -rw-r--r-- | tests/diagnostics/autodiff.slang | 15 | ||||
| -rw-r--r-- | tests/diagnostics/autodiff.slang.expected | 9 | ||||
| -rw-r--r-- | tests/diagnostics/for-loop-warning.slang | 60 | ||||
| -rw-r--r-- | tests/diagnostics/for-loop-warning.slang.expected | 35 |
8 files changed, 133 insertions, 5 deletions
diff --git a/tests/autodiff/generic-impl-jvp.slang b/tests/autodiff/generic-impl-jvp.slang index 332833fff..98adc4a7c 100644 --- a/tests/autodiff/generic-impl-jvp.slang +++ b/tests/autodiff/generic-impl-jvp.slang @@ -24,6 +24,7 @@ struct myvector : IDifferentiable __init(T c) { + [ForceUnroll] for (int i = 0; i < N; i++) { values[i] = c; @@ -46,7 +47,7 @@ struct myvector : IDifferentiable static Differential dmul(This a, Differential b) { Differential output; - + for (int i = 0; i < N; i++) { output.values[i] = T.dmul(a.values[i], b.values[i]); @@ -73,6 +74,7 @@ __generic<T : IDFloat, let N : int> myvector<T, N> operator +(myvector<T, N> a, myvector<T, N> b) { myvector<T, N> output; + [ForceUnroll] for (int i = 0; i < N; i++) { output.values[i] = a.values[i] + b.values[i]; @@ -85,6 +87,7 @@ __generic<T : IDFloat, let N : int> myvector<T, N> operator *(myvector<T, N> a, myvector<T, N> b) { myvector<T, N> output; + [ForceUnroll] for (int i = 0; i < N; i++) { output.values[i] = a.values[i] * b.values[i]; @@ -97,6 +100,7 @@ __generic<T : IDFloat, let N : int> myvector<T, N> operator *(T a, myvector<T, N> b) { myvector<T, N> output; + [ForceUnroll] for (int i = 0; i < N; i++) { output.values[i] = a * b.values[i]; @@ -109,6 +113,7 @@ __generic<T : IDFloat, let N : int> T dot(myvector<T, N> a, myvector<T, N> b) { T curr = (T)0.0; + [ForceUnroll] for (int i = 0; i < N; i++) { curr = curr + (a.values[i] * b.values[i]); @@ -125,6 +130,7 @@ DifferentialPair<T> dot_jvp(dpvector<T, N> a, dpvector<T, N> b) { T.Differential curr_d = (T.dzero()); T curr_p = (T)0.0; + [ForceUnroll] for (int i = 0; i < N; i++) { curr_p = curr_p + (a.p.values[i] * b.p.values[i]); @@ -145,6 +151,7 @@ struct lineardvector : IDifferentiable __init(vector<Real.Differential, N> a) { + [ForceUnroll] for (int i = 0; i < N; i++) { val.values[i] = a[i]; @@ -204,6 +211,7 @@ struct linearvector : MyLinearArithmeticType, IDifferentiable [ForwardDifferentiable] __init(vector<Real, N> a) { + [ForceUnroll] for (int i = 0; i < N; i++) { val.values[i] = a[i]; diff --git a/tests/autodiff/reverse-loop.slang b/tests/autodiff/reverse-loop.slang index 828a06185..5598f6b71 100644 --- a/tests/autodiff/reverse-loop.slang +++ b/tests/autodiff/reverse-loop.slang @@ -13,7 +13,6 @@ float test_simple_loop(float y) { float t = y; - [MaxIters(3)] for (int i = 0; i < 3; i++) { t = t * t; diff --git a/tests/diagnostics/autodiff-data-flow.slang b/tests/diagnostics/autodiff-data-flow.slang index 93c76c07e..e8d9502e4 100644 --- a/tests/diagnostics/autodiff-data-flow.slang +++ b/tests/diagnostics/autodiff-data-flow.slang @@ -24,6 +24,11 @@ void g(float x) float val = 0; if (x > 5) val = x + 1; + + for (int i = 0; i < 5; i++) // Not ok, we can't infer the loop iterations because the body modifies induction var. + { + i = (int)x; + } return; } diff --git a/tests/diagnostics/autodiff-data-flow.slang.expected b/tests/diagnostics/autodiff-data-flow.slang.expected index 290ef974b..301f84985 100644 --- a/tests/diagnostics/autodiff-data-flow.slang.expected +++ b/tests/diagnostics/autodiff-data-flow.slang.expected @@ -6,6 +6,9 @@ tests/diagnostics/autodiff-data-flow.slang(15): error 41020: derivative cannot b tests/diagnostics/autodiff-data-flow.slang(22): error 41021: a differentiable function must have at least one differentiable output. void g(float x) ^ +tests/diagnostics/autodiff-data-flow.slang(28): error 30510: loops inside a differentiable function need to provide either '[MaxIters(n)]' or '[ForceUnroll]' attribute. + for (int i = 0; i < 5; i++) // Not ok, we can't infer the loop iterations because the body modifies induction var. + ^~~ } standard output = { } diff --git a/tests/diagnostics/autodiff.slang b/tests/diagnostics/autodiff.slang index f9fed6753..935ef07cb 100644 --- a/tests/diagnostics/autodiff.slang +++ b/tests/diagnostics/autodiff.slang @@ -11,6 +11,21 @@ float f(float x) float val = 0; if (x > 5) val = x + 1; + + // warning: dynamic loop without [MaxIters] or [ForceUnroll] + for (int i = 0; i < (int)x; i++) + { + } + + [MaxIters(2)] + for (int i = 0; i < (int)x; i++) // OK + { + } + + for (int i = 0; i < 5; i++) // OK + { + } + return val; } diff --git a/tests/diagnostics/autodiff.slang.expected b/tests/diagnostics/autodiff.slang.expected index cd97bce76..952503d1c 100644 --- a/tests/diagnostics/autodiff.slang.expected +++ b/tests/diagnostics/autodiff.slang.expected @@ -1,12 +1,15 @@ result code = -1 standard error = { -tests/diagnostics/autodiff.slang(20): error 38031: 'no_diff' can only be used to decorate a call. +tests/diagnostics/autodiff.slang(16): error 30510: loops inside a differentiable function need to provide either '[MaxIters(n)]' or '[ForceUnroll]' attribute. + for (int i = 0; i < (int)x; i++) + ^~~ +tests/diagnostics/autodiff.slang(35): error 38031: 'no_diff' can only be used to decorate a call. float x1 = no_diff x; // invalid use of no_diff here. ^~~~~~~ -tests/diagnostics/autodiff.slang(21): error 38032: use 'no_diff' on a call to a differentiable function has no meaning. +tests/diagnostics/autodiff.slang(36): error 38032: use 'no_diff' on a call to a differentiable function has no meaning. return no_diff f(x); // no_diff on a differentiable call has no meaning. ^~~~~~~ -tests/diagnostics/autodiff.slang(26): error 38033: cannot use 'no_diff' in a non-differentiable function. +tests/diagnostics/autodiff.slang(41): error 38033: cannot use 'no_diff' in a non-differentiable function. return no_diff nonDiff(x); // no_diff in a non-differentiable function ^~~~~~~ } diff --git a/tests/diagnostics/for-loop-warning.slang b/tests/diagnostics/for-loop-warning.slang new file mode 100644 index 000000000..226af46f5 --- /dev/null +++ b/tests/diagnostics/for-loop-warning.slang @@ -0,0 +1,60 @@ +//DIAGNOSTIC_TEST:SIMPLE: + + +float doSomething(int x) +{ + for (int i = 0; i < x; i--) // warn. + {} + for (int i = 0; i < 5; i-=-2) // ok. + {} + for (int j = 0; j < 3; j += 0) // warn. + {} + for (int i = 0; i < 5; i++) // ok + { + for (int j = 0; j < 3; i++) // warn. + {} + } + for (int i = 0; i < 5; i++) // ok + { + for (int j = 0; i < 4; j++) // warn. + {} + } + + [MaxIters(6)] // warn + for (int i = 0; i <= 6; i+=3) + { + } + + [MaxIters(6)] // warn + for (int i = 5; i >= 0; i -= 3) + { + } + [MaxIters(6)] // warn + for (int i = 5; i > 0; i--) + { + } + + [MaxIters(5)] // ok + for (int i = 0; i < 5; i++) // ok + { + } + + for (int i = 1; i < 0; i++) // warn + { + } + for (int i = 1; i >= 2; i--) // warn + { + } + for (int i = 1; i >= 1; i--) // ok + { + } + for (int i = 1; i > 1; i--) // warn + { + } + [MaxIters(5)] // ok, because the loop body modifies i so we can't infer the iterations. + for (int i = 0; i < 5; i+=2) + { + i--; + } + return 0.0; +} diff --git a/tests/diagnostics/for-loop-warning.slang.expected b/tests/diagnostics/for-loop-warning.slang.expected new file mode 100644 index 000000000..e37abb035 --- /dev/null +++ b/tests/diagnostics/for-loop-warning.slang.expected @@ -0,0 +1,35 @@ +result code = 0 +standard error = { +tests/diagnostics/for-loop-warning.slang(6): warning 30502: the for loop is modifiying variable 'i' in the opposite direction from loop exit condition. + for (int i = 0; i < x; i--) // warn. + ^~ +tests/diagnostics/for-loop-warning.slang(10): warning 30503: the for loop is not modifiying variable 'j' because the step size evaluates to 0. + for (int j = 0; j < 3; j += 0) // warn. + ^~ +tests/diagnostics/for-loop-warning.slang(14): warning 30500: the for loop initializes and checks variable 'j' but the side effect expression is modifying 'i'. + for (int j = 0; j < 3; i++) // warn. + ^ +tests/diagnostics/for-loop-warning.slang(19): warning 30501: the for loop initializes and modifies variable 'j' but the predicate expression is checking 'i'. + for (int j = 0; i < 4; j++) // warn. + ^ +tests/diagnostics/for-loop-warning.slang(42): warning 30505: the loop runs for 0 iterations and will be removed. + for (int i = 1; i < 0; i++) // warn + ^~~ +tests/diagnostics/for-loop-warning.slang(45): warning 30505: the loop runs for 0 iterations and will be removed. + for (int i = 1; i >= 2; i--) // warn + ^~~ +tests/diagnostics/for-loop-warning.slang(51): warning 30505: the loop runs for 0 iterations and will be removed. + for (int i = 1; i > 1; i--) // warn + ^~~ +tests/diagnostics/for-loop-warning.slang(23): warning 30504: the for loop is statically determined to terminate within 3 iterations, which is less than what [MaxIters] specifies. + [MaxIters(6)] // warn + ^~~~~~~~ +tests/diagnostics/for-loop-warning.slang(28): warning 30504: the for loop is statically determined to terminate within 2 iterations, which is less than what [MaxIters] specifies. + [MaxIters(6)] // warn + ^~~~~~~~ +tests/diagnostics/for-loop-warning.slang(32): warning 30504: the for loop is statically determined to terminate within 5 iterations, which is less than what [MaxIters] specifies. + [MaxIters(6)] // warn + ^~~~~~~~ +} +standard output = { +} |
