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

Fix BigFloat for Julia v1.12 #307

Merged
merged 11 commits into from
Oct 13, 2024
Merged

Fix BigFloat for Julia v1.12 #307

merged 11 commits into from
Oct 13, 2024

Conversation

odow
Copy link
Member

@odow odow commented Oct 10, 2024

No description provided.

src/implementations/BigFloat.jl Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.41%. Comparing base (93c7e3b) to head (ce60f92).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #307      +/-   ##
==========================================
- Coverage   91.85%   90.41%   -1.44%     
==========================================
  Files          23       22       -1     
  Lines        2246     2222      -24     
==========================================
- Hits         2063     2009      -54     
- Misses        183      213      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@odow
Copy link
Member Author

odow commented Oct 10, 2024

I don't understand this well enough to figure out what's going on here.

@odow
Copy link
Member Author

odow commented Oct 11, 2024

I guess a bunch of our C calls might be invalid now?

julia> x, y = setprecision(BigFloat, 32) do
           return rand(BigFloat, 1), rand(BigFloat, 1)
       end
(BigFloat[0.51086560986], BigFloat[0.18767778529])

julia> accurate = LinearAlgebra.dot(x, y)
0.095878126238614356830099183515159211310674436390399932861328125

julia> output = setprecision(BigFloat, 32) do
           buf = MA.buffer_for(LinearAlgebra.dot, Vector{BigFloat}, Vector{BigFloat})
           output = BigFloat(0)
           MA.buffered_operate_to!!(buf, output, LinearAlgebra.dot, x, y)
           return output
       end
get_str.c:157: MPFR assertion failed: size_s1 >= m

[48611] signal 6: Abort trap: 6
in expression starting at REPL[85]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
pthread_kill at /usr/lib/system/libsystem_pthread.dylib (unknown line)
abort at /usr/lib/system/libsystem_c.dylib (unknown line)
mpfr_assert_fail at /Users/oscar/.julia/juliaup/julia-nightly/lib/julia/libmpfr.6.dylib (unknown line)
mpfr_get_str_aux at /Users/oscar/.julia/juliaup/julia-nightly/lib/julia/libmpfr.6.dylib (unknown line)
mpfr_get_str at /Users/oscar/.julia/juliaup/julia-nightly/lib/julia/libmpfr.6.dylib (unknown line)
regular_eg at /Users/oscar/.julia/juliaup/julia-nightly/lib/julia/libmpfr.6.dylib (unknown line)
sprnt_fp at /Users/oscar/.julia/juliaup/julia-nightly/lib/julia/libmpfr.6.dylib (unknown line)
mpfr_vasnprintf_aux at /Users/oscar/.julia/juliaup/julia-nightly/lib/julia/libmpfr.6.dylib (unknown line)
mpfr_asprintf at /Users/oscar/.julia/juliaup/julia-nightly/lib/julia/libmpfr.6.dylib (unknown line)
string_mpfr at ./mpfr.jl:1187
_string at ./mpfr.jl:1233
_string at ./mpfr.jl:1235 [inlined]
show at ./mpfr.jl:1245
show at ./multimedia.jl:47
unknown function (ip: 0x104e1d5e2)

This PR seems suspicous JuliaLang/julia#55906

@blegat
Copy link
Member

blegat commented Oct 11, 2024

The printing is actually happened when we try to show the output. Surprisingly, replacing output = BigFloat(0) by output = BigFloat(1) removes the segfault.

@blegat
Copy link
Member

blegat commented Oct 11, 2024

Here is the MWE

a = one(BigFloat)
b = zero(BigFloat)
ccall((:mpfr_swap, :libmpfr), Cvoid, (Ref{BigFloat}, Ref{BigFloat}), b, a)
show(b)

It gives

get_str.c:157: MPFR assertion failed: size_s1 >= m

[42807] signal 6 (-6): Aborted
in expression starting at /home/blegat/.julia/dev/MutableArithmetics/b.jl:6
unknown function (ip: 0x725fea6533f4)
gsignal at /usr/lib/libc.so.6 (unknown line)
abort at /usr/lib/libc.so.6 (unknown line)
mpfr_assert_fail at /workspace/srcdir/mpfr-4.2.1/src/mpfr-gmp.c:300
mpfr_get_str_aux at /workspace/srcdir/mpfr-4.2.1/src/get_str.c:157
mpfr_get_str at /workspace/srcdir/mpfr-4.2.1/src/get_str.c:2877
regular_eg at /workspace/srcdir/mpfr-4.2.1/src/vasprintf.c:1308
partition_number at /workspace/srcdir/mpfr-4.2.1/src/vasprintf.c:1925 [inlined]
sprnt_fp at /workspace/srcdir/mpfr-4.2.1/src/vasprintf.c:1994 [inlined]
mpfr_vasnprintf_aux at /workspace/srcdir/mpfr-4.2.1/src/vasprintf.c:2413
mpfr_asprintf at /workspace/srcdir/mpfr-4.2.1/src/printf.c:176
string_mpfr at ./mpfr.jl:1187
_string at ./mpfr.jl:1233
_string at ./mpfr.jl:1235 [inlined]
show at ./mpfr.jl:1245
unknown function (ip: 0x725fe8d03866)
show at ./show.jl:476
unknown function (ip: 0x725fe8d00d62)
jl_apply at /cache/build/builder-amdci5-1/julialang/julia-master/src/julia.h:2228 [inlined]
do_call at /cache/build/builder-amdci5-1/julialang/julia-master/src/interpreter.c:125
eval_value at /cache/build/builder-amdci5-1/julialang/julia-master/src/interpreter.c:222
eval_stmt_value at /cache/build/builder-amdci5-1/julialang/julia-master/src/interpreter.c:173 [inlined]
eval_body at /cache/build/builder-amdci5-1/julialang/julia-master/src/interpreter.c:685
jl_interpret_toplevel_thunk at /cache/build/builder-amdci5-1/julialang/julia-master/src/interpreter.c:892
jl_toplevel_eval_flex at /cache/build/builder-amdci5-1/julialang/julia-master/src/toplevel.c:1047
jl_toplevel_eval_flex at /cache/build/builder-amdci5-1/julialang/julia-master/src/toplevel.c:987
ijl_toplevel_eval at /cache/build/builder-amdci5-1/julialang/julia-master/src/toplevel.c:1058
ijl_toplevel_eval_in at /cache/build/builder-amdci5-1/julialang/julia-master/src/toplevel.c:1100
eval at ./boot.jl:439 [inlined]
include_string at ./loading.jl:2741
_include at ./loading.jl:2801
include at ./Base.jl:581 [inlined]
exec_options at ./client.jl:329
_start at ./client.jl:558
jfptr__start_66271.1 at /home/blegat/.julia/juliaup/julia-nightly/lib/julia/sys.so (unknown line)
jl_apply at /cache/build/builder-amdci5-1/julialang/julia-master/src/julia.h:2228 [inlined]
true_main at /cache/build/builder-amdci5-1/julialang/julia-master/src/jlapi.c:900
jl_repl_entrypoint at /cache/build/builder-amdci5-1/julialang/julia-master/src/jlapi.c:1059
main at /cache/build/builder-amdci5-1/julialang/julia-master/cli/loader_exe.c:58
unknown function (ip: 0x725fea5e2e07)
__libc_start_main at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8)
Allocations: 1 (Pool: 1; Big: 0); GC: 0

@odow
Copy link
Member Author

odow commented Oct 13, 2024

Okay. I tidied things up. Our previous implementation was just needlessly complicated with layers of indirection.

@odow odow changed the title Fix mutable_copy(::BigFloat) in Julia v1.12 Fix BigFloat for Julia v1.12 Oct 13, 2024
@odow odow merged commit 208d0f2 into master Oct 13, 2024
10 of 11 checks passed
@odow odow deleted the od/bigfloat branch October 13, 2024 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants