Skip to content
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

Remove redundant bounds check in mul! with sparse matrices #26554

Merged
merged 1 commit into from
Mar 22, 2018

Conversation

haampie
Copy link
Contributor

@haampie haampie commented Mar 21, 2018

There's performance to be gained in sparse mat-vec products for very sparse matrices by moving the @inbounds one block up. We can probably do this cause the dimensions of B and C have already been checked.

Some results:

function bench(n = 1_000, k = 5)
    # Tridiagonal matrix
    A = spdiagm(-1 => fill(-1.0, n-1), 0 => fill(2.0, n), 1 => fill(-1.1, n-1))
    B = ones(n, k)
    C1 = similar(B)
    C2 = similar(B)

    mul!(C1, A, B, 1.0, 0.0)
    my_mul!(C2, A, B, 1.0, 0.0)

    @assert C1 == C2

    mul!(C1, A', B, 1.0, 0.0)
    my_mul!(C2, A', B, 1.0, 0.0)

    @assert C1 == C2

    A1 = @benchmark mul!($C1, $A, $B, 1.0, 0.0)
    A2 = @benchmark my_mul!($C1, $A, $B, 1.0, 0.0)

    Aᵀ1 = @benchmark mul!($C1, $(A'), $B, 1.0, 0.0)
    Aᵀ2 = @benchmark my_mul!($C1, $(A'), $B, 1.0, 0.0)

    A1, A2, Aᵀ1, Aᵀ2
end
n k old A * x new A * x old A' * x new A' * x
1_000 5 22μs 17μs 21μs 18μs
10_000 5 222μs 175μs 207μs 182μs
100_000 5 2395μs 1933μs 2385μs 2078μs

@andreasnoack andreasnoack merged commit ae439a5 into JuliaLang:master Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants