|
1 | 1 |
|
2 | 2 | @testset "Fall back behavior" begin
|
3 | 3 |
|
4 |
| - @show Float64, @__LINE__ |
5 |
| - function msd(x) |
6 |
| - s = zero(eltype(x)) |
7 |
| - for i in eachindex(x) |
8 |
| - s += x[i] * x[i] |
9 |
| - end |
10 |
| - s |
| 4 | + @show Float64, @__LINE__ |
| 5 | + function msd(x) |
| 6 | + s = zero(eltype(x)) |
| 7 | + for i in eachindex(x) |
| 8 | + s += x[i] * x[i] |
11 | 9 | end
|
12 |
| - function msdavx(x) |
13 |
| - s = zero(eltype(x)) |
14 |
| - @turbo warn_check_args=true for i in eachindex(x) |
15 |
| - s = muladd(x[i], x[i], s) # Avoids fastmath in fallback loop. |
16 |
| - end |
17 |
| - s |
| 10 | + s |
| 11 | + end |
| 12 | + function msdavx(x) |
| 13 | + s = zero(eltype(x)) |
| 14 | + @turbo warn_check_args=true for i in eachindex(x) |
| 15 | + s = muladd(x[i], x[i], s) # Avoids fastmath in fallback loop. |
18 | 16 | end
|
| 17 | + s |
| 18 | + end |
19 | 19 |
|
20 |
| - x = fill(8.0, 128); |
21 |
| - x[1] = 1e9 |
22 |
| - |
23 |
| - @test @inferred LoopVectorization.check_args(x) |
24 |
| - @test @inferred LoopVectorization.check_args(x, x) |
25 |
| - @test @inferred LoopVectorization.check_args(x, x, x) |
26 |
| - @test @inferred !LoopVectorization.check_args(view(x, [1,3,4,18])) |
27 |
| - @test @inferred !LoopVectorization.check_args(FallbackArrayWrapper(x)) |
28 |
| - @test @inferred !LoopVectorization.check_args(FallbackArrayWrapper(x), x, x) |
29 |
| - @test @inferred !LoopVectorization.check_args(x, FallbackArrayWrapper(x)) |
30 |
| - @test @inferred !LoopVectorization.check_args(x, FallbackArrayWrapper(x), x) |
31 |
| - @test @inferred !LoopVectorization.check_args(x, x, FallbackArrayWrapper(x)) |
32 |
| - @test @inferred !LoopVectorization.check_args(x, x, FallbackArrayWrapper(x), FallbackArrayWrapper(x)) |
33 |
| - @test @inferred !LoopVectorization.check_args(['a']) |
34 |
| - @test @inferred !LoopVectorization.check_args(Diagonal(x)) |
35 |
| - |
36 |
| - @test_nowarn msdavx(x) |
37 |
| - @test_logs (:warn,"`LoopVectorization.check_args` on your inputs failed; running fallback `@inbounds @fastmath` loop instead.\nUse `warn_check_args=false`, e.g. `@turbo warn_check_args=false ...`, to disable this warning.") msdavx(FallbackArrayWrapper(x)) |
38 |
| - @test msdavx(FallbackArrayWrapper(x)) == 1e18 |
39 |
| - @test msd(x) == msdavx(FallbackArrayWrapper(x)) |
40 |
| - @test msdavx(x) != msdavx(FallbackArrayWrapper(x)) |
41 |
| - |
42 |
| - x = rand(1000); # should be long enough to make zero differences incredibly unlikely |
43 |
| - @test exp.(x) != (@turbo exp.(x)) |
44 |
| - @test exp.(x) == (@turbo exp.(FallbackArrayWrapper(x))) |
| 20 | + x = fill(8.0, 128); |
| 21 | + x[1] = 1e9 |
| 22 | + |
| 23 | + @test @inferred LoopVectorization.check_args(x) |
| 24 | + @test @inferred LoopVectorization.check_args(x, x) |
| 25 | + @test @inferred LoopVectorization.check_args(x, x, x) |
| 26 | + @test @inferred !LoopVectorization.check_args(view(x, [1,3,4,18])) |
| 27 | + @test @inferred !LoopVectorization.check_args(FallbackArrayWrapper(x)) |
| 28 | + @test @inferred !LoopVectorization.check_args(FallbackArrayWrapper(x), x, x) |
| 29 | + @test @inferred !LoopVectorization.check_args(x, FallbackArrayWrapper(x)) |
| 30 | + @test @inferred !LoopVectorization.check_args(x, FallbackArrayWrapper(x), x) |
| 31 | + @test @inferred !LoopVectorization.check_args(x, x, FallbackArrayWrapper(x)) |
| 32 | + @test @inferred !LoopVectorization.check_args(x, x, FallbackArrayWrapper(x), FallbackArrayWrapper(x)) |
| 33 | + @test @inferred !LoopVectorization.check_args(['a']) |
| 34 | + @test @inferred !LoopVectorization.check_args(Diagonal(x)) |
| 35 | + |
| 36 | + @test_nowarn msdavx(x) |
| 37 | + lnn = LineNumberNode(14, joinpath(pkgdir(LoopVectorization),"test","fallback.jl")) |
| 38 | + warnstring = "$(lnn):\n`LoopVectorization.check_args` on your inputs failed; running fallback `@inbounds @fastmath` loop instead.\nUse `warn_check_args=false`, e.g. `@turbo warn_check_args=false ...`, to disable this warning." |
| 39 | + |
| 40 | + @test_logs (:warn,warnstring) msdavx(FallbackArrayWrapper(x)) |
| 41 | + @test msdavx(FallbackArrayWrapper(x)) == 1e18 |
| 42 | + @test msd(x) == msdavx(FallbackArrayWrapper(x)) |
| 43 | + @test msdavx(x) != msdavx(FallbackArrayWrapper(x)) |
| 44 | + |
| 45 | + x = rand(1000); # should be long enough to make zero differences incredibly unlikely |
| 46 | + @test exp.(x) != (@turbo exp.(x)) |
| 47 | + @test exp.(x) == (@turbo exp.(FallbackArrayWrapper(x))) |
45 | 48 | end
|
46 | 49 |
|
0 commit comments