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

Adding more than 3 complex numbers (inlining threshold) #6681

Closed
ivarne opened this issue Apr 28, 2014 · 2 comments
Closed

Adding more than 3 complex numbers (inlining threshold) #6681

ivarne opened this issue Apr 28, 2014 · 2 comments

Comments

@ivarne
Copy link
Sponsor Member

ivarne commented Apr 28, 2014

First reported by @jtravs on the mailinglist. This is similar to #3206, but with complex numbers, and it seems like +(a,b,c,d,e) is performed in a suboptmal way because of varargs.

function sum5(scale, sa1, a1, sa2, a2, sa3, a3, sa4, a4, sa5, a5, out)
    for i=1:length(out)
        out[i] = scale*(sa1*a1[i] + sa2*a2[i] + sa3*a3[i]
                                            + sa4*a4[i] + sa5*a5[i])
    end
end

function sum5b(scale, sa1, a1, sa2, a2, sa3, a3, sa4, a4, sa5, a5, out)
    for i=1:length(out)
        out[i] = scale*(sa1*a1[i] + sa2*a2[i] + sa3*a3[i])
        out[i] += scale*(sa4*a4[i] + sa5*a5[i])
    end
end

function dosums(T)
    scale = rand()
    sa1 = rand()
    a1 = rand(T,200000)
    sa2 = rand()
    a2 = rand(T,200000)
    sa3 = rand()
    a3 = rand(T,200000)
    sa4 = rand()
    a4 = rand(T,200000)
    sa5 = rand()
    a5 = rand(T,200000)
    out = similar(a1)
    sum5(scale,sa1,a1,sa2,a2,sa3,a3,sa4,a4,sa5,a5,out)
    @time sum5(scale,sa1,a1,sa2,a2,sa3,a3,sa4,a4,sa5,a5,out)
    sum5b(scale,sa1,a1,sa2,a2,sa3,a3,sa4,a4,sa5,a5,out)
    @time sum5b(scale,sa1,a1,sa2,a2,sa3,a3,sa4,a4,sa5,a5,out)
end
dosums(Complex{Float64}) 

The result show that there is a huge penalty when we add too many numbers in one invocation of +.

elapsed time: 0.022001424 seconds (28800096 bytes allocated) 
elapsed time: 0.00194736 seconds (96 bytes allocated)
@JeffBezanson JeffBezanson changed the title Adding more than 3 complex numbers Adding more than 3 complex numbers (inlining threshold) Apr 28, 2014
@vtjnash
Copy link
Sponsor Member

vtjnash commented Apr 29, 2014

this has a rather complex interaction with the inlining threshold, because it is just under the threshold for splitting out the parts of the sum into multiple variables, which puts it just over the threshold after inlining N variables

however, the bigger question is why this is falling back to the julia calling convention for more than three arguments to +:

julia> code_llvm(+,(Complex{Float64},Complex{Float64},Complex{Float64},Complex{Float64},Complex{Float64}))

define %jl_value_t* @"julia_+15722"(%jl_value_t*, %jl_value_t**, i32) {

@JeffBezanson
Copy link
Sponsor Member

fixed by #7075

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

No branches or pull requests

3 participants