numo-linalg
numo-linalg copied to clipboard
"stack smashing detected" occur with liblapacke64
I used this test script.
$ cat test.rb
require "numo/linalg/autoloader"
require "datasets-numo-narray"
require "rumale"
p Numo::Linalg::Autoloader.libs
numeric_columns = [
:bill_length_mm, :bill_depth_mm, :flipper_length_mm, :body_mass_g
]
penguins = Datasets::Penguins.new
array = penguins.filter_map do |record|
values = numeric_columns.map do |column|
record[column]
end
unless values.include?(nil)
values
end
end
x = Numo::NArray[*array]
x_std = Rumale::Preprocessing::StandardScaler.new.fit_transform(x)
pca = Rumale::Decomposition::PCA.new#(n_components: 4)
p pca.fit_transform(x_std)
First, I confirmed that the problem occurs with liblapacke64.
$ ruby test.rb
["/usr/lib/x86_64-linux-gnu/libopenblas.so.0", "/usr/lib/x86_64-linux-gnu/liblapacke64.so.3.9.0"]
*** stack smashing detected ***: terminated
Aborted (core dumped)
Then, I tried the same test script with liblapacke.
$ sudo apt remove liblapacke64
...(snip)...
$ ruby test.rb
["/usr/lib/x86_64-linux-gnu/libopenblas.so.0", "/usr/lib/x86_64-linux-gnu/liblapacke.so.3.9.0"]
Numo::DFloat#shape=[342,2]
[[1.84075, 0.0476324],
[1.30485, -0.427722],
[1.36718, -0.15425],
[1.87608, -0.00204541],
[1.90895, 0.827996],
[1.76045, -0.350965],
[0.808889, 0.521724],
[1.83252, -0.768507],
[1.19246, 1.02478],
[1.72767, -0.787415],
[1.74049, -0.665515],
[1.78609, -0.235726],
[1.94543, 1.00977],
[1.56169, 0.596213],
[1.7371, -0.593942],
[1.56656, 0.0957962],
[0.794444, 1.30888],
[2.33955, -0.631749],
[0.992793, 1.98276],
[2.39412, -0.294074],
...
The problem does not occur with liblapacke.
This is valgrind output.
$ valgrind $(rbenv which ruby) test.rb
==2294062== Memcheck, a memory error detector
==2294062== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2294062== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==2294062== Command: /home/mrkn/.rbenv/versions/3.0.1/bin/ruby test.rb
==2294062==
==2294062== Warning: client switching stacks? SP change: 0x1ffe8020d0 --> 0x1fff000150
==2294062== to suppress, use: --max-stackframe=8380544 or greater
["/usr/lib/x86_64-linux-gnu/libopenblas.so.0", "/usr/lib/x86_64-linux-gnu/liblapacke64.so.3.9.0"]
==2294062== Invalid write of size 8
==2294062== at 0x41BB6B70: dstein_ (in /usr/lib/x86_64-linux-gnu/lapack64/liblapack64.so.3.9.0)
==2294062== by 0x41BC418E: dsyevx_ (in /usr/lib/x86_64-linux-gnu/lapack64/liblapack64.so.3.9.0)
==2294062== by 0x41BC8BDA: dsygvx_ (in /usr/lib/x86_64-linux-gnu/lapack64/liblapack64.so.3.9.0)
==2294062== by 0x19764283: LAPACKE_dsygvx_work (in /usr/lib/x86_64-linux-gnu/liblapacke64.so.3.9.0)
==2294062== by 0x19763DF5: LAPACKE_dsygvx (in /usr/lib/x86_64-linux-gnu/liblapacke64.so.3.9.0)
==2294062== by 0xAD5A5BE: iter_lapack_s_dsygvx (sygvx.c:42)
==2294062== by 0xA7C1257: loop_narray (ndloop.c:1336)
==2294062== by 0xA7C2440: ndloop_run (ndloop.c:1297)
==2294062== by 0x492799D: rb_ensure (eval.c:1162)
==2294062== by 0xA7C5818: na_ndloop_main (ndloop.c:1409)
==2294062== by 0xA7C5C08: na_ndloop3 (ndloop.c:1476)
==2294062== by 0xAD63E74: lapack_s_dsygvx (sygvx.c:187)
==2294062== Address 0x9c662e8 is 0 bytes after a block of size 8 alloc'd
==2294062== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==2294062== by 0x494D43F: objspace_xmalloc0 (gc.c:10618)
==2294062== by 0x494D43F: ruby_xmalloc0 (gc.c:10839)
==2294062== by 0x494D43F: ruby_xmalloc_body (gc.c:10848)
==2294062== by 0x494D43F: ruby_xmalloc (gc.c:12787)
==2294062== by 0xA807B28: int32_allocate (allocate.c:13)
==2294062== by 0x4B0F7D6: vm_call0_cfunc_with_frame (vm_eval.c:135)
==2294062== by 0x4B0F7D6: vm_call0_cfunc (vm_eval.c:149)
==2294062== by 0x4B0F7D6: vm_call0_body (vm_eval.c:180)
==2294062== by 0x4B12C6F: vm_call0_cc (vm_eval.c:72)
==2294062== by 0x4B12C6F: rb_funcallv_scope (vm_eval.c:1006)
==2294062== by 0x4B12C6F: rb_funcallv (vm_eval.c:1026)
==2294062== by 0xA7B6A92: na_get_pointer_for_rw (narray.c:714)
==2294062== by 0xA7B6A92: nary_get_pointer_for_write (narray.c:756)
==2294062== by 0xA7C03D4: ndloop_set_stepidx.isra.0 (ndloop.c:523)
==2294062== by 0xA7C15C9: ndloop_set_output_narray (ndloop.c:794)
==2294062== by 0xA7C2093: ndloop_set_output (ndloop.c:821)
==2294062== by 0xA7C2093: ndloop_run (ndloop.c:1267)
==2294062== by 0x492799D: rb_ensure (eval.c:1162)
==2294062== by 0xA7C5818: na_ndloop_main (ndloop.c:1409)
==2294062== by 0xA7C5C08: na_ndloop3 (ndloop.c:1476)
==2294062==
*** stack smashing detected ***: terminated
==2294062==
==2294062== Process terminating with default action of signal 6 (SIGABRT): dumping core
==2294062== at 0x4CAE18B: raise (raise.c:51)
==2294062== by 0x4C8D858: abort (abort.c:79)
==2294062== by 0x4CF83ED: __libc_message (libc_fatal.c:155)
==2294062== by 0x4D9AB49: __fortify_fail (fortify_fail.c:26)
==2294062== by 0x4D9AB15: __stack_chk_fail (stack_chk_fail.c:24)
==2294062== by 0xAD5A5FD: iter_lapack_s_dsygvx (sygvx.c:46)
==2294062== by 0xA7C1257: loop_narray (ndloop.c:1336)
==2294062== by 0xA7C2440: ndloop_run (ndloop.c:1297)
==2294062== by 0x492799D: rb_ensure (eval.c:1162)
==2294062== by 0xA7C5818: na_ndloop_main (ndloop.c:1409)
==2294062== by 0xA7C5C08: na_ndloop3 (ndloop.c:1476)
==2294062== by 0xAD63E74: lapack_s_dsygvx (sygvx.c:187)
==2294062==
==2294062== HEAP SUMMARY:
==2294062== in use at exit: 51,316,903 bytes in 101,992 blocks
==2294062== total heap usage: 586,260 allocs, 484,268 frees, 141,784,088 bytes allocated
==2294062==
==2294062== LEAK SUMMARY:
==2294062== definitely lost: 1,728 bytes in 36 blocks
==2294062== indirectly lost: 2,607 bytes in 47 blocks
==2294062== possibly lost: 14,892,379 bytes in 92,848 blocks
==2294062== still reachable: 36,420,189 bytes in 9,061 blocks
==2294062== suppressed: 0 bytes in 0 blocks
==2294062== Rerun with --leak-check=full to see details of leaked memory
==2294062==
==2294062== For lists of detected and suppressed errors, rerun with: -s
==2294062== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Aborted (core dumped)