JuliaArrays / JuliaArrays/StaticArrays.jl
Suboptimal matrix vector product
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
There appears to be a scaling problem with matrix vector products, I think to do with vectorization (from inspecting generated code).
Example:
julia> let N=32, M=8
@btime mul!($(zeros(Float32, M)), $(rand(Float32, M, N)), $(rand(Float32, N)))
@btime $(rand(SMatrix{M, N, Float32})) * $(rand(SVector{N, Float32}))
@btime $(rand(SMatrix{M, N, Float32})) * $(rand(SMatrix{N, 1, Float32}))
end;
33.646 ns (0 allocations: 0 bytes)
8.601 ns (0 allocations: 0 bytes)
9.834 ns (0 allocations: 0 bytes)
julia> let N=64, M=8
@btime mul!($(zeros(Float32, M)), $(rand(Float32, M, N)), $(rand(Float32, N)))
@btime $(rand(SMatrix{M, N, Float32})) * $(rand(SVector{N, Float32}))
@btime $(rand(SMatrix{M, N, Float32})) * $(rand(SMatrix{N, 1, Float32}))
end;
44.674 ns (0 allocations: 0 bytes)
40.647 ns (0 allocations: 0 bytes)
16.021 ns (0 allocations: 0 bytes)
julia> let N=128, M=8
@btime mul!($(zeros(Float32, M)), $(rand(Float32, M, N)), $(rand(Float32, N)))
@btime $(rand(SMatrix{M, N, Float32})) * $(rand(SVector{N, Float32}))
@btime $(rand(SMatrix{M, N, Float32})) * $(rand(SMatrix{N, 1, Float32}))
end;
65.031 ns (0 allocations: 0 bytes)
351.633 ns (0 allocations: 0 bytes)
46.571 ns (0 allocations: 0 bytes)
The equivalent matrix matrix product scales fine, so my guess is the necessary functionality is there, but it needs to be wired up?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported @btime comparisons for mul!, SMatrix * SVector, and SMatrix * SMatrix at N=32, 64, and 128. Start by tracing the matrix-vector multiplication and generated-code path, then compare its dispatch with the matrix-matrix product. Done means the matrix-vector product no longer shows the reported scaling problem while preserving zero allocations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100