kokkos / kokkos-kernels

Kokkos C++ Performance Portability Programming Ecosystem: Math Kernels - Provides BLAS, Sparse BLAS and Graph Kernels
Other
311 stars 98 forks source link

bsr_spmmv unit-test: address sanitizer report a leak #2268

Closed lucbv closed 4 months ago

lucbv commented 4 months ago

Compiling Kokkos Core and Kernels with debug symbols and address sanitizer reveals a memory leak in the bsr_spmmv unit-test.

9: [==========] Running 7 tests from 1 test case.
9: [----------] Global test environment set-up.
9: [----------] 7 tests from openmp
9: [ RUN      ] openmp.sparse_bsr_gauss_seidel_rank1_double_int_int_TestDevice
9: [       OK ] openmp.sparse_bsr_gauss_seidel_rank1_double_int_int_TestDevice (34558 ms)
9: [ RUN      ] openmp.sparse_bsr_gauss_seidel_rank2_double_int_int_TestDevice
9: [       OK ] openmp.sparse_bsr_gauss_seidel_rank2_double_int_int_TestDevice (63999 ms)
9: [ RUN      ] openmp.sparse_bsr_gauss_seidel_empty_double_int_int_TestDevice
9: [       OK ] openmp.sparse_bsr_gauss_seidel_empty_double_int_int_TestDevice (9 ms)
9: [ RUN      ] openmp.sparse_bsrmatrix_double_int_int_TestDevice
9: [       OK ] openmp.sparse_bsrmatrix_double_int_int_TestDevice (0 ms)
9: [ RUN      ] openmp.sparse_block_spgemm_double_int_int_TestDevice
9: [       OK ] openmp.sparse_block_spgemm_double_int_int_TestDevice (14162 ms)
9: [ RUN      ] openmp.sparse_bsr_spmv_double_int_int_TestDevice
9: [       OK ] openmp.sparse_bsr_spmv_double_int_int_TestDevice (2329 ms)
9: [ RUN      ] openmp.sparse_bsr_spmmv_double_int_int_LayoutLeft_TestDevice
9: [       OK ] openmp.sparse_bsr_spmmv_double_int_int_LayoutLeft_TestDevice (10341 ms)
9: [----------] 7 tests from openmp (125398 ms total)
9: 
9: [----------] Global test environment tear-down
9: [==========] 7 tests from 1 test case ran. (125399 ms total)
9: [  PASSED  ] 7 tests.
9: 
9: =================================================================
9: ==1415823==ERROR: LeakSanitizer: detected memory leaks
9: 
9: Direct leak of 6912 byte(s) in 144 object(s) allocated from:
9:     #0 0x7f3ee39c2e28 in operator new(unsigned long) /tmp/root/spack-stage/spack-stage-gcc-13.2.0-4vbuetotqxgsh36yktpdyae5thosh553/spack-src/libsanitizer/asan/asan_new_delete.cpp:95
9:     #1 0x47be8d in void Test_Spmv_Bsr::test_spm_mv_combos<Kokkos::LayoutLeft, KokkosSparse::Experimental::BsrMatrix<double, int, Kokkos::OpenMP, void, int>, KokkosSparse::CrsMatrix<double, int, Kokkos::OpenMP, void, int> >(char const*, KokkosSparse::Experimental::BsrMatrix<double, int, Kokkos::OpenMP, void, int> const&, KokkosSparse::CrsMatrix<double, int, Kokkos::OpenMP, void, int> const&, unsigned long) (/home/lberge/Research/kokkos_eco/builds/kk_lucbv/sparse/unit_test/KokkosKernels_blocksparse_openmp+0x47be8d)
9:     #2 0x43974c in void Test_Spmv_Bsr::test_spm_mv_random<double, int, int, Kokkos::LayoutLeft, Kokkos::OpenMP>() (/home/lberge/Research/kokkos_eco/builds/kk_lucbv/sparse/unit_test/KokkosKernels_blocksparse_openmp+0x43974c)
9:     #3 0x41d8d0 in void Test_Spmv_Bsr::test_spm_mv<double, int, int, Kokkos::LayoutLeft, Kokkos::OpenMP>() (/home/lberge/Research/kokkos_eco/builds/kk_lucbv/sparse/unit_test/KokkosKernels_blocksparse_openmp+0x41d8d0)
9:     #4 0x40c3c2 in openmp_sparse_bsr_spmmv_double_int_int_LayoutLeft_TestDevice_Test::TestBody() /ascldap/users/lberge/Research/kokkos_eco/sources/kk_lucbv/test_common/Test_Common_Test_All_Type_Combos.hpp:63
9:     #5 0xd5130a in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (/home/lberge/Research/kokkos_eco/builds/kk_lucbv/sparse/unit_test/KokkosKernels_blocksparse_openmp+0xd5130a)
9:     #6 0xd465c1 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /ascldap/users/lberge/Research/kokkos_eco/sources/kk_lucbv/tpls/gtest/gtest/gtest-all.cc:3598
9:     #7 0xd09eb7 in testing::Test::Run() /ascldap/users/lberge/Research/kokkos_eco/sources/kk_lucbv/tpls/gtest/gtest/gtest-all.cc:3634
9:     #8 0xd0af7b in testing::TestInfo::Run() /ascldap/users/lberge/Research/kokkos_eco/sources/kk_lucbv/tpls/gtest/gtest/gtest-all.cc:3812
9:     #9 0xd0ba83 in testing::TestCase::Run() /ascldap/users/lberge/Research/kokkos_eco/sources/kk_lucbv/tpls/gtest/gtest/gtest-all.cc:3930
9:     #10 0xd1b6b1 in testing::internal::UnitTestImpl::RunAllTests() /ascldap/users/lberge/Research/kokkos_eco/sources/kk_lucbv/tpls/gtest/gtest/gtest-all.cc:5801
9:     #11 0xd53b19 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (/home/lberge/Research/kokkos_eco/builds/kk_lucbv/sparse/unit_test/KokkosKernels_blocksparse_openmp+0xd53b19)
9:     #12 0xd48941 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (/home/lberge/Research/kokkos_eco/builds/kk_lucbv/sparse/unit_test/KokkosKernels_blocksparse_openmp+0xd48941)
9:     #13 0xd18d52 in testing::UnitTest::Run() /ascldap/users/lberge/Research/kokkos_eco/sources/kk_lucbv/tpls/gtest/gtest/gtest-all.cc:5412
9:     #14 0x40accf in RUN_ALL_TESTS() (/home/lberge/Research/kokkos_eco/builds/kk_lucbv/sparse/unit_test/KokkosKernels_blocksparse_openmp+0x40accf)
9:     #15 0x40a98c in main /ascldap/users/lberge/Research/kokkos_eco/sources/kk_lucbv/test_common/Test_Main.cpp:23
9:     #16 0x7f3ee303feaf in __libc_start_call_main (/lib64/libc.so.6+0x3feaf) (BuildId: e535a3491625906f928c4c3026789142fb74f0ff)

Kokkos Core was configured as follows (of course set variables to appropriate paths):

cmake -S ${KOKKOS_SOURCE} \
      -B ${KOKKOS_BUILD} \
      -D CMAKE_INSTALL_PREFIX:PATH=${KOKKOS_INSTALL} \
      -D CMAKE_CXX_COMPILER:STRING="g++" \
      -D CMAKE_CXX_FLAGS:STRING="-fsanitize=address" \
      -D CMAKE_BUILD_TYPE:STRING="Debug" \
      -D Kokkos_ARCH_BDW:BOOL=ON \
      -D Kokkos_ENABLE_OPENMP:BOOL=ON

Kokkos Kernels was configure as follows (again set variable appropriately):

cmake -S ${KK_SOURCE} \
      -B ${KK_BUILD} \
      -D CMAKE_INSTALL_PREFIX:PATH="${KK_INSTALL}" \
      -D CMAKE_CXX_COMPILER:STRING="g++" \
      -D CMAKE_CXX_FLAGS:STRING="-fsanitize=address" \
      -D CMAKE_EXE_LINKER_FLAGS:STRING="-fsanitize=address -lgfortran" \
      -D CMAKE_BUILD_TYPE:STRING="Debug" \
      -D Kokkos_ROOT:PATH="${KOKKOS_INSTALL}" \
      -D KokkosKernels_ENABLE_TPL_BLAS:BOOL=ON \
      -D   BLAS_LIBRARIES:STRING="openblas" \
      -D   BLAS_LIBRARY_DIRS:PATH="${OPENBLAS_INSTALL}/lib" \
      -D KokkosKernels_ENABLE_TPL_LAPACK:BOOL=OFF \
      -D   LAPACK_LIBRARIES:STRING="openblas" \
      -D   LAPACK_LIBRARY_DIRS:PATH="${OPENBLAS_INSTALL}/lib" \
      -D KokkosKernels_ENABLE_TESTS:BOOL=ON \
      -D KokkosKernels_ENABLE_EXAMPLES:BOOL=ON

Note that the compiler used was sems-gcc/13.2.0 available as a SEMS module.

cwpearson commented 4 months ago

I think this is the problem:

https://github.com/kokkos/kokkos-kernels/blob/8130cf9ab45db5b2bebad4586c9827a18b2f6bcb/sparse/unit_test/Test_Sparse_spmv_bsr.hpp#L647-L649

These are not freed. I'm also not sure why we're using new at all here

lucbv commented 4 months ago

@cgcgcg fyi, this is being worked on. @cwpearson actually that pattern appears twice in the test, my sense is simply passing a pointer to the spmv interface instead of storing pointers directly would be just fine?