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

llvmcall errors for some Vec sizes #61

Closed
perrutquist opened this issue Jan 23, 2020 · 10 comments
Closed

llvmcall errors for some Vec sizes #61

perrutquist opened this issue Jan 23, 2020 · 10 comments

Comments

@perrutquist
Copy link

perrutquist commented Jan 23, 2020

Example:

julia> v = Vec(ntuple(i->1.0, 7))
<7 x Float64>[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

julia> 1.0*v
ERROR: error compiling *: Failed to parse LLVM Assembly: 
julia: llvmcall:3:26: error: '%0' defined with type '[7 x double]'
%res = fmul <7 x double> %0, %1
                         ^

(For other lengths, such as 6 or 8, there's no error. )

I suspect this has to to with NTuple{N, VecElement{T}} not mapping to a LLVM vector for all values of N.

@vchuravy
Copy link
Collaborator

Right I think it turns out that LLVM creates invalid code for vector lengths that are not multiplies of 2 and Julia chooses a different representation for them. Couldn't quickly find where that happens, but I remember investigating this years ago.

@KristofferC
Copy link
Collaborator

See discussion in #1.

@eschnett
Copy link
Owner

So this is Julia applying a work-around for a long-standing bug in LLVM?

Which vector lengths are working in Julia? SIMD should emit an error message for these.

@perrutquist
Copy link
Author

From: https://docs.julialang.org/en/v1/base/simd-types/
"A homogeneous tuple of VecElement{T} maps to an LLVM vector type when T is a primitive bits type and the tuple length is in the set {2-6,8-10,16}"

Although the vector length 12 also seems to work, even though it's not in the above-mentioned set.

@perrutquist
Copy link
Author

Rather than an error message, how about letting Vec(::NTuple{7,T)) work with an NTuple{8,VecElement{T}} internally?

@fredrikekre
Copy link

Which vector lengths are working in Julia?

I investigated that some time ago: https://github.com/KristofferC/Tensors.jl/blob/218188cbfb3d755d5fbdd5c33efc115942b9781a/src/simd.jl#L33-L34. I don't remember which Juila/LLVM version that was for though.

@eschnett
Copy link
Owner

It seems the respective bug in LLVM was corrected in 2017 (see https://bugs.llvm.org/show_bug.cgi?id=27708). We might just be able to remove that special rule again (see jl_special_vector_alignment in src/datatype.c in Julia). I'm investigating.

@eschnett
Copy link
Owner

Yes, removing the special case that only allows certain vector sizes seems to work fine now when this special casing is removed. (It was necessary for LLVM 3.8 and earlier.)

@perrutquist
Copy link
Author

Wow! After merging JuliaLang/julia#34490 and JuliaLang/julia#34473 SIMD.jl works beautifully! (I had almost given up on using this package due to segfaults and other problems.) Maybe mention these PRs in the readme until they are in a Julia release?

@KristofferC
Copy link
Collaborator

This is now fixed upstream. Will be in Julia 1.4.

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

5 participants