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

Segmentation fault when converting BFloat16 to Float32 #89

Open
findmyway opened this issue Dec 31, 2024 · 2 comments
Open

Segmentation fault when converting BFloat16 to Float32 #89

findmyway opened this issue Dec 31, 2024 · 2 comments

Comments

@findmyway
Copy link

julia> versioninfo()
Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 192 × Intel(R) Xeon(R) Platinum 8468
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, sapphirerapids)
Threads: 1 default, 0 interactive, 1 GC (on 192 virtual cores)
Environment:
  LD_LIBRARY_PATH = /usr/local/nccl-rdma-sharp-plugins/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64                  |

julia> using BFloat16s

julia> x = BFloat16[0]
1-element Vector{BFloat16}:
 0.0

julia> Float32.(x)
[1]    26383 segmentation fault (core dumped)  julia
@inkydragon
Copy link
Member

Cannot be reproduced on Win11 and WSL.
Maybe the issue is related to the system or the CPU.

Details

Win11

julia> using BFloat16s

julia> x = BFloat16[0]
1-element Vector{BFloat16}:
 0.0

julia> Float32.(x)
1-element Vector{Float32}:
 0.0

julia> versioninfo()
Julia Version 1.11.2
Commit 5e9a32e7af (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 32 × 13th Gen Intel(R) Core(TM) i9-13900HX
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 32 virtual cores)

WSL (Ubuntu 22.04.5 LTS)

julia> using BFloat16s

julia> x = BFloat16[0]
1-element Vector{BFloat16}:
 0.0

julia> Float32.(x)
1-element Vector{Float32}:
 0.0

julia> versioninfo()
Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 32 × 13th Gen Intel(R) Core(TM) i9-13900HX
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 32 virtual cores)

if llvm_arithmetic
Base.Float32(x::BFloat16) = Base.fpext(Float32, x)
Base.Float64(x::BFloat16) = Base.fpext(Float64, x)
else
# Expansion to Float32
function Base.Float32(x::BFloat16)
reinterpret(Float32, UInt32(reinterpret(Unsigned, x)) << 16)
end
# Expansion to Float64
function Base.Float64(x::BFloat16)
Float64(Float32(x))
end
end

Does the following code trigger the problem and what is your output?

Float32(x[1])
BFloat16s.llvm_arithmetic
Base.fpext.(Float32, x)
@. reinterpret(Float32, UInt32(reinterpret(UInt16, x)) << 16)

Base.fpext isa Core.IntrinsicFunction.
I'm guessing this is a julia bug.

@findmyway
Copy link
Author

This only occurs on my Linux server. On my local mac environment, it works fine. Should we create an issue under the Julia repo?

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

2 participants