Skip to content

Commit

Permalink
safe=true and add a docstring, closes #434 (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Sep 29, 2022
1 parent 9d8fb66 commit be2af94
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/condense_loopset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ function can_turbo(f::F, ::Val{NARGS})::Bool where {F,NARGS}
promoted_op = Base.promote_op(f, ntuple(RetVec2Int(), Val(NARGS))...)
return promoted_op !== Union{}
end
can_turbo(::typeof(vfmaddsub), ::Val{3}) = true
can_turbo(::typeof(vfmsubadd), ::Val{3}) = true

"""
check_turbo_safe(ls::LoopSet)
Expand Down
16 changes: 9 additions & 7 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function process_args(
v::Int8 = zero(Int8),
threads::Int = 1,
warncheckarg::Int = 1,
safe::Bool = false,
safe::Bool = true,
)
for arg args
inline, check_empty, u₁, u₂, v, threads, warncheckarg, safe =
Expand Down Expand Up @@ -295,6 +295,14 @@ The integer's value indicates the number of threads to use.
It is clamped to be between `1` and `min(Threads.nthreads(),LoopVectorization.num_cores())`.
`false` is equivalent to `1`, and `true` is equivalent to `min(Threads.nthreads(),LoopVectorization.num_cores())`.
`safe` (defaults to `true`) will cause `@turbo` to fall back to `@inbounds @fastmath` if `can_turbo` returns false for any of the functions called in the loop. You can disable the associated warning with `warn_check_args=false`.
Setting the keyword argument `warn_check_args=true` (e.g. `@turbo warn_check_args=true for ...`) in a loop or
broadcast statement will cause it to warn once if `LoopVectorization.check_args` fails and the fallback
loop is executed instead of the LoopVectorization-optimized loop.
Setting it to an integer > 0 will warn that many times, while setting it to a negative integer will warn
an unlimited amount of times. The default is `warn_check_args = 1`. Failure means that there may have been an array with unsupported type, unsupported element types, or (if `safe=true`) a function for which `can_turbo` returned `false`.
`inline` is a Boolean. When `true`, `body` will be directly inlined
into the function (via a forced-inlining call to `_turbo_!`).
When `false`, it wont force inlining of the call to `_turbo_!` instead, letting Julia's own inlining engine
Expand Down Expand Up @@ -324,12 +332,6 @@ and `@fastmath` is generated. Note that `VectorizationBase` provides functions s
ignore `@fastmath`, preserving IEEE semantics both within `@turbo` and `@fastmath`.
`check_args` currently returns false for some wrapper types like `LinearAlgebra.UpperTriangular`, requiring you to
use their `parent`. Triangular loops aren't yet supported.
Setting the keyword argument `warn_check_args=true` (e.g. `@turbo warn_check_args=true for ...`) in a loop or
broadcast statement will cause it to warn once if `LoopVectorization.check_args` fails and the fallback
loop is executed instead of the LoopVectorization-optimized loop.
Setting it to an integer > 0 will warn that many times, while setting it to a negative integer will warn
an unlimited amount of times. The default is `warn_check_args = 0`.
"""
macro turbo(args...)
turbo_macro(__module__, __source__, last(args), Base.front(args)...)
Expand Down
1 change: 1 addition & 0 deletions test/offsetarrays.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LoopVectorization, ArrayInterface, OffsetArrays, Test
using LoopVectorization: StaticInt
# T = Float64; r = -1:1;
# T = Float32; r = -1:1;

Expand Down
1 change: 1 addition & 0 deletions test/shuffleloadstores.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using LoopVectorization: vpermilps177, vmovshdup, vfmsubadd, vfmaddsub, vmovsldup
function dot_simd(a::AbstractVector, b::AbstractVector)
s = zero(eltype(a))
@fastmath @inbounds @simd for i eachindex(a)
Expand Down

2 comments on commit be2af94

@chriselrod
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/69251

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.130 -m "<description of version>" be2af94ddacbb958d8995c58b4da4603def6fffc
git push origin v0.12.130

Please sign in to comment.