-
Notifications
You must be signed in to change notification settings - Fork 35
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
Code generation problems #12
Comments
Methinks this might be a type instability. The array and tuple handling code in Julia is currently changing. I will have a look. |
Here is a shorter code to reproduce the problem: using SIMD
f(a) = @inbounds a[1] = Vec{4,Float32}(1)
@code_llvm f(Array{Vec{4,Float32}}(1)) I see that the code that creates the SIMD vector is translated fine; it is inline, and as simple as it should be. I thus think that the array indexing is causing problems. The problem disappears when I use @timholy Any ideas? Here is the generated LLVM code:
Given this, I assume that the call to |
This doesn't seem like it could possibly be affected by any of my recent array changes: julia> using SIMD
julia> v = Vec{4,Float32}(1)
4-element SIMD.Vec{4,Float32}:
Float32⟨1.0,1.0,1.0,1.0⟩
julia> a = Array{Vec{4,Float32}}(1)
1-element Array{SIMD.Vec{4,Float32},1}:
Float32⟨-0.00026230933,4.5644e-41,-0.02648136,4.5644e-41⟩
julia> @which a[1] = v
setindex!{T}(A::Array{T,N<:Any}, x, i1::Real) at array.jl:372 That line is here. This problem seems to be fixed (or at least, better) if you comment out this line. So I'd look into your |
Ref #6 |
This looks relevant: julia> using SIMD
julia> code_llvm(Tuple, (Vec{4, Float32},))
define void @julia_Type_67726([4 x float]* noalias sret, %jl_value_t*, %Vec*) #0 {
[...]
%19 = call %jl_value_t* @jl_apply_generic(%jl_value_t** %4, i32 3)
[...]
} In my older Julia ( julia> using SIMD
julia> code_llvm(Tuple, (Vec{4, Float32},))
define void @julia_Type_50122([4 x float]* sret, %jl_value_t*, %Vec*) #0 {
[...]
%18 = call %jl_value_t* @jl_apply_generic(%jl_value_t** %5, i32 3)
[...]
}
julia> Tuple(Vec{4, Float32}(0))
(0.0f0,0.0f0,0.0f0,0.0f0)
julia> code_llvm(Tuple, (Vec{4, Float32},))
define void @julia_Type_50122([4 x float]* sret, %jl_value_t*, %Vec*) #0 {
top:
%3 = alloca [4 x float], align 4
call void @julia_convert_50126([4 x float]* nonnull sret %3, %jl_value_t* inttoptr (i64 140529556360832 to %jl_value_t*), %Vec* %2) #0
%4 = bitcast [4 x float]* %0 to i8*
%5 = bitcast [4 x float]* %3 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %4, i8* %5, i64 16, i32 4, i1 false)
ret void
} In current Julia the simpler code can't be provoked by running the constructor once. |
@GunnarFarneback Thanks for pointing to #6; yes, this was the problem. Apologies for not understanding the main point of your pull request when you requested it three months ago. |
(I think you meant @KristofferC.) |
@timholy @KristofferC Yes, sorry again. Not my day today. |
:) |
This code
run with a Julia 0.5 of today allocates way too much memory:
code_llvm produces a mess including a scary call to jl_apply_generic.
In a 48 days old Julia I had available this is much better,
6 allocations: 1.526 MB
, unless@inbounds
is removed, in which case it's back to 200k allocations. There code_llvm also produces a mess but at least without any jl_apply_generic.I'm not sure if I'm doing something I shouldn't but at least it looks like something has regressed with recent Julia.
The text was updated successfully, but these errors were encountered: