Skip to content

Commit

Permalink
Fix broadcasting products for general access patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Feb 6, 2020
1 parent 75daf98 commit 4b481a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ function add_broadcast!(
bloopsyms = Symbol[k]
cloopsyms = Symbol[m]
reductdeps = Symbol[m, k]
kvec = bloopsyms
elseif ndims(B) == 2
n = loopsyms[2];
bloopsyms = Symbol[k,n]
cloopsyms = Symbol[m,n]
reductdeps = Symbol[m, k, n]
kvec = Symbol[k]
else
throw("B must be a vector or matrix.")
end
Expand All @@ -72,13 +74,22 @@ function add_broadcast!(
loadB = add_broadcast!(ls, gensym(:B), mB, bloopsyms, B, elementbytes)
# set Cₘₙ = 0
# setC = add_constant!(ls, zero(promote_type(recursive_eltype(A), recursive_eltype(B))), cloopsyms, mC, elementbytes)
# targetC will be used for reduce_to_add
mCt = gensym(mC)
targetC = add_constant!(ls, gensym(:zero), cloopsyms, mCt, elementbytes, :numericconstant)
push!(ls.preamble_zeros, (identifier(targetC), IntOrFloat))
setC = add_constant!(ls, gensym(:zero), cloopsyms, mC, elementbytes, :numericconstant)
push!(ls.preamble_zeros, (identifier(setC), IntOrFloat))
setC.reduced_children = kvec
# compute Cₘₙ += Aₘₖ * Bₖₙ
reductop = Operation(
ls, mC, elementbytes, :vmuladd, compute, reductdeps, Symbol[k], Operation[loadA, loadB, setC]
ls, mC, elementbytes, :vmuladd, compute, reductdeps, kvec, Operation[loadA, loadB, setC]
)
pushop!(ls, reductop, mC)
reductop = pushop!(ls, reductop, mC)
reductfinal = Operation(
ls, mCt, elementbytes, :reduce_to_add, compute, cloopsyms, kvec, Operation[reductop, targetC]
)
pushop!(ls, reductfinal, mCt)
end

struct LowDimArray{D,T,N,A<:DenseArray{T,N}} <: DenseArray{T,N}
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,12 @@ end

M, K, N = 77, 83, 57;
A = rand(R,M,K); B = rand(R,K,N); C = rand(R,M,N);

At = copy(A')
D1 = C .+ A * B;
D2 = @avx C .+ A *ˡ B;
@test D1 D2
fill!(D2, -999999); D2 = @avx C .+ At' *ˡ B;
@test D1 D2
if T <: Union{Float32,Float64}
D3 = cos.(B');
D4 = @avx cos.(B');
Expand Down

2 comments on commit 4b481a3

@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 register()

@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/8936

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 Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.8 -m "<description of version>" 4b481a3020f7a4e2fb775aa882cc7d052134f933
git push origin v0.6.8

Please sign in to comment.