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

Segfault with 0-degree polynomials and autodiff #47

Open
isutoris opened this issue Feb 4, 2018 · 3 comments · May be fixed by #48
Open

Segfault with 0-degree polynomials and autodiff #47

isutoris opened this issue Feb 4, 2018 · 3 comments · May be fixed by #48

Comments

@isutoris
Copy link

isutoris commented Feb 4, 2018

I'm not sure if this is a problem with BasisMatrices or somewhere deeper in Julia, so apologies if this is not the right place. Anyway, on my computer (Julia 0.6.0) and also on JuliaBox (0.6.2), the following consistently segfaults:

using BasisMatrices
using ForwardDiff

fspace = Basis(ChebParams(1, 0.0, 1.0), ChebParams(5, 0.0, 1.0), ChebParams(1, 0.0, 1.0))
b = ones(length(fspace))
f = x -> funeval(b, fspace, x)
Df_x = ForwardDiff.gradient(f, 0.5*ones(3))

Using 0-th degree polynomials is kind of a hack, but the original idea was to use 0-degree / 1-coefficient polynomials as basis functions in some dimensions to impose the approximated function to be constant in those dimensions. This works when evaluated at standard float inputs for x, but apparently not when x is array of ForwardDiff duals (although interestingly it did work in two dimensions, only at three I came across the issue).

I'm attaching segfault output, according to which the crash happened somewhere in base linear algebra routines. However it's not consistent - for some other inputs the crash happened somewhere inside garbage collector instead, so who knows...

signal (11): Segmentation fault
while loading [...omitted...]/tmp_segflt.jl, in expression starting on line 8
macro expansion at ./linalg/generic.jl:9 [inlined]
macro expansion at ./simdloop.jl:73 [inlined]
generic_scale! at ./linalg/generic.jl:8
evalbasex! at [...omitted...]/.julia/v0.6/BasisMatrices/src/cheb.jl:183
evalbasex at [...omitted...]/.julia/v0.6/BasisMatrices/src/cheb.jl:202
evalbase at [...omitted...]/.julia/v0.6/BasisMatrices/src/cheb.jl:119
Type at [...omitted...]/.julia/v0.6/BasisMatrices/src/basis_structure.jl:231
funeval at [...omitted...]/.julia/v0.6/BasisMatrices/src/interp.jl:197
funeval at [...omitted...]/.julia/v0.6/BasisMatrices/src/interp.jl:152 [inlined]
funeval at [...omitted...]/.julia/v0.6/BasisMatrices/src/interp.jl:152
unknown function (ip: 0x7fc3a0d607d7)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
#1 at [...omitted...]/tmp_segflt.jl:7
unknown function (ip: 0x7fc3a0d5a212)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
vector_mode_gradient at [...omitted...]/.julia/v0.6/ForwardDiff/src/gradient.jl:96 [inlined]
gradient at [...omitted...]/.julia/v0.6/ForwardDiff/src/gradient.jl:17
unknown function (ip: 0x7fc3a0d593ed)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
gradient at [...omitted...]/.julia/v0.6/ForwardDiff/src/gradient.jl:15
unknown function (ip: 0x7fc3a0d591ed)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
gradient at [...omitted...]/.julia/v0.6/ForwardDiff/src/gradient.jl:15
unknown function (ip: 0x7fc3a0d572b6)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
do_call at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:75
eval at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:242
eval_body at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:543
jl_interpret_toplevel_thunk at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:692
jl_toplevel_eval_flex at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:592
jl_parse_eval_all at /home/centos/buildbot/slave/package_tarball64/build/src/ast.c:873
jl_load at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:616
include_from_node1 at ./loading.jl:569
unknown function (ip: 0x7fc3b54ddb1b)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
include at ./sysimg.jl:14
unknown function (ip: 0x7fc3b538286b)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
do_call at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:75
eval at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:242
jl_interpret_toplevel_expr at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:34
jl_toplevel_eval_flex at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:577
jl_toplevel_eval_in at /home/centos/buildbot/slave/package_tarball64/build/src/builtins.c:496
eval at ./boot.jl:235
unknown function (ip: 0x7fc3b54a739f)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
eval_user_input at ./REPL.jl:66
unknown function (ip: 0x7fc3b55151cf)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
macro expansion at ./REPL.jl:97 [inlined]
#1 at ./event.jl:73
unknown function (ip: 0x7fc3a0d4f2af)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1424 [inlined]
start_task at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:267
unknown function (ip: 0xffffffffffffffff)
Allocations: 6918720 (Pool: 6916942; Big: 1778); GC: 12
Segmentation fault
@sglyon
Copy link
Member

sglyon commented Feb 5, 2018

Hi @isutoris I've never actually tried this before.

I don't think I'll have time to personally debug/resolve this issue.

If I were going to attempt it I would first move the @inbounds macros on these lines. It is possible that the @inbounds is only appropriate when degree is greater than or equal to 1. Removing that macro will throw errors for improper indexing, which is a common cause for segfault in julia

@isutoris
Copy link
Author

isutoris commented Feb 5, 2018

Thanks for the pointer. After looking at those lines, it does seem like they are always trying to fill first two columns of the out matrix, but if n=1 then out will have just one column. Also this happens for any input type, so the autodiff thing was a red herring.

One possible fix would be to simply handle the case n=1 separately beforehand:

if p.n==1
    out .= 1.0
    return out
end

@inbounds out[:, 1] = 1.0
@inbounds out[:, 2] = z
...

which seems to fix the segfault in my case. If you think this is sufficient, I can try to submit a PR later (once I figure how).

BTW, similar issue appears to be present also in smol_util.jl, although I haven't yet looked at that more closely.

@sglyon
Copy link
Member

sglyon commented Feb 5, 2018

Ahh good catch. Yes, when you have the time will you please open a PR. Fixing smol_util.jl at the same time would be an added bonus ;)

Thanks!

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

Successfully merging a pull request may close this issue.

2 participants