-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with ifelse #220
Comments
Use IfElse.ifelse. julia> using LoopVectorization, IfElse
julia> function _real_sqrt(x,y)
t = sqrt(2*(abs(x) + hypot(x, y)))
return IfElse.ifelse(x ≥ zero(x), t/2, abs(y)/t)
end
_real_sqrt (generic function with 1 method)
julia> x = (rand(1000).-0.5).*10;
julia> y = (rand(1000).-0.5).*10;
julia> _real_sqrt.(x,y) ≈ @avx _real_sqrt.(x,y)
true
julia> @btime @. $z = _real_sqrt($x, $y);
9.486 μs (0 allocations: 0 bytes)
julia> @btime @avx @. $z = _real_sqrt($x, $y);
2.335 μs (0 allocations: 0 bytes) |
Here is the related issue: |
Although I guess this should be solvable via the abstract interpreter. So reopening the issue'd be fine to track that. |
Thanks! |
For more of an explanation, vectorization/SIMD means doing multiple operations per instruction. LoopVectorization/VectorizationBase represent that with types like: julia> using VectorizationBase
julia> vx = Vec(ntuple(_ -> 2rand(), VectorizationBase.pick_vector_width(Float64))...)
Vec{8, Float64}<1.5219234039045744, 1.8300372474242277, 1.5738687191737752, 0.18406707750515228, 0.6740398193024504, 0.253508594387144, 1.715660422824369, 1.6706874133577432>
julia> vx > abs2(vx)
Mask{8,Bit}<0, 0, 0, 1, 1, 1, 0, 0> This relies on overloading a bunch of functions to make them work as expected. |
On LoopVectorization 0.12.9:
The error is:
The text was updated successfully, but these errors were encountered: