Skip to content

Commit

Permalink
Fail when simd=:ivdep is used with foldl etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jul 15, 2019
1 parent b455f9e commit 518a650
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ end
function Base.mapfoldl(xform::Transducer, step, itr;
simd::SIMDFlag = Val(false),
init = MissingInit())
check_no_ivdep(simd)
unreduced(transduce(xform, step, init, itr; simd=simd))
end

Expand Down Expand Up @@ -724,17 +725,20 @@ julia> foldl(Filter(isodd), 1:4, init=0.0) do state, input
"""
function Base.foldl(step, xform::Transducer, itr;
kw...)
check_no_ivdep(; kw...)
mapfoldl(xform, Completing(step), itr; kw...)
end

@inline Base.foldl(step, ed::Eduction; init=MissingInit(), kwargs...) =
@inline function Base.foldl(step, ed::Eduction; init=MissingInit(), kwargs...)
check_no_ivdep(; kwargs...)
if FinalType(ed.rf) === NOTYPE
xf = Transducer(ed.rf)
unreduced(transduce(xf, Completing(step), init, ed.coll; kwargs...))
else
rf = reform(ed.rf, Completing(step))
unreduced(transduce(rf, init, ed.coll; kwargs...))
end
end

"""
foreach(eff, xf::Transducer, reducible; simd)
Expand Down
14 changes: 14 additions & 0 deletions src/simd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ end

const SIMDFlag = Union{Bool, Symbol, Val{true}, Val{false}, Val{:ivdep}}

"""
check_no_ivdep(::SIMDFlag)
check_no_ivdep(; simd=Val(false), kwargs...)
"""
@inline check_no_ivdep(simd) = simd
@inline check_no_ivdep(simd::Symbol) =
simd == :ivdep ? check_no_ivdep(Val(:ivdep)) : simd
@noinline check_no_ivdep(::Val{:ivdep}) =
throw(ArgumentError(string(
"`simd=:ivdep` must not be used for generic `foldl` or `reduce`.",
" Please use `foreach`."
)))
check_no_ivdep(; simd=Val(false), _...) = check_no_ivdep(simd)

"""
maybe_usesimd(xform, simd)
Expand Down
11 changes: 11 additions & 0 deletions test/test_simd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ end
end
end

@testset "UX" begin
for err in [
(@test_error mapfoldl(Map(identity), +, 1:2; simd=:ivdep)),
(@test_error foldl(+, Map(identity), 1:2; simd=:ivdep)),
(@test_error foldl(+, eduction(Map(identity), 1:2); simd=:ivdep)),
]
@test occursin("`simd=:ivdep` must not be used",
sprint(showerror, err))
end
end

@testset "@simd_if" begin
err = @test_error @macroexpand @simd_if rf for i in 1:1
end
Expand Down

0 comments on commit 518a650

Please sign in to comment.