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

conv is slower than necessary #167

Open
KristofferC opened this issue Jun 25, 2017 · 2 comments · May be fixed by #545
Open

conv is slower than necessary #167

KristofferC opened this issue Jun 25, 2017 · 2 comments · May be fixed by #545

Comments

@KristofferC
Copy link

KristofferC commented Jun 25, 2017

Moved from JuliaLang/julia#13996 (more discussion there)

It seems that conv is slower than necessary. By implementing a naive convolution, I am able to outperform conv for moderate vector sizes. On my particular machine, naive convolution is better than conv if the product of vector sizes is less than 100 000.

Just so everyone sees what the naive solution is, I'm pasting it below.

slowconvcost(m,n) = 2e-9*m*n+1e-6
fastconvcost(m,n) = 7e-8*(m+n)*log(m+n)+1e-4
function sebconv(a::Array{T}, b::Array{T}) where T
    m = length(a)
    n = length(b)
    if(fastconvcost(m,n)<slowconvcost(m,n)) return conv(a,b); end
    c = zeros(T,m+n-1)
    @inbounds for j=1:m
        for k=1:n
            c[j+k-1] += a[j]*b[k]
        end
    end
    return c
end

Here is a performance plot:

convperf

Edit: tweaked code for better heuristic as to when slowconv is faster than fastconv.

@ViralBShah
Copy link
Contributor

There's still a large gap for small sizes:

julia> x = rand(100); y = rand(100);

julia> @btime sebconv($x, $y);
  1.429 μs (1 allocation: 1.77 KiB)

julia> @btime conv($x, $y);
  17.875 μs (18 allocations: 9.84 KiB)

@martinholters
Copy link
Member

Ref. #545.

@wheeheee wheeheee linked a pull request Oct 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants