icl-utk-edu / blaspp

BLAS++ is a C++ wrapper around CPU and GPU BLAS (basic linear algebra subroutines), developed as part of the SLATE project.
https://icl.utk.edu/slate/
BSD 3-Clause "New" or "Revised" License
66 stars 23 forks source link

Some 32-bit platforms now need to link to libatomic: Undefined symbols: "___atomic_store_8" #90

Open barracuda156 opened 3 weeks ago

barracuda156 commented 3 weeks ago
[100%] Linking CXX executable tester
cd /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_math_blaspp/blaspp/work/build/test && /opt/local/bin/cmake -E cmake_link_script CMakeFiles/tester.dir/link.txt --verbose=ON
/opt/local/bin/g++-mp-14 -pipe -Os -DNDEBUG -I/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -arch ppc -mmacosx-version-min=10.6 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/opt/local/lib -Wl,-headerpad_max_install_names CMakeFiles/tester.dir/test.cc.o CMakeFiles/tester.dir/test_util.cc.o CMakeFiles/tester.dir/test_asum.cc.o CMakeFiles/tester.dir/test_axpy.cc.o CMakeFiles/tester.dir/test_batch_gemm.cc.o CMakeFiles/tester.dir/test_batch_hemm.cc.o CMakeFiles/tester.dir/test_batch_her2k.cc.o CMakeFiles/tester.dir/test_batch_herk.cc.o CMakeFiles/tester.dir/test_batch_symm.cc.o CMakeFiles/tester.dir/test_batch_syr2k.cc.o CMakeFiles/tester.dir/test_batch_syrk.cc.o CMakeFiles/tester.dir/test_batch_trmm.cc.o CMakeFiles/tester.dir/test_batch_trsm.cc.o CMakeFiles/tester.dir/test_copy.cc.o CMakeFiles/tester.dir/test_dot.cc.o CMakeFiles/tester.dir/test_dotu.cc.o CMakeFiles/tester.dir/test_error.cc.o CMakeFiles/tester.dir/test_gemm.cc.o CMakeFiles/tester.dir/test_gemv.cc.o CMakeFiles/tester.dir/test_ger.cc.o CMakeFiles/tester.dir/test_geru.cc.o CMakeFiles/tester.dir/test_hemm.cc.o CMakeFiles/tester.dir/test_hemv.cc.o CMakeFiles/tester.dir/test_her.cc.o CMakeFiles/tester.dir/test_her2.cc.o CMakeFiles/tester.dir/test_her2k.cc.o CMakeFiles/tester.dir/test_herk.cc.o CMakeFiles/tester.dir/test_iamax.cc.o CMakeFiles/tester.dir/test_max.cc.o CMakeFiles/tester.dir/test_memcpy.cc.o CMakeFiles/tester.dir/test_memcpy_2d.cc.o CMakeFiles/tester.dir/test_nrm2.cc.o CMakeFiles/tester.dir/test_rot.cc.o CMakeFiles/tester.dir/test_rotg.cc.o CMakeFiles/tester.dir/test_rotm.cc.o CMakeFiles/tester.dir/test_rotmg.cc.o CMakeFiles/tester.dir/test_scal.cc.o CMakeFiles/tester.dir/test_swap.cc.o CMakeFiles/tester.dir/test_symm.cc.o CMakeFiles/tester.dir/test_symv.cc.o CMakeFiles/tester.dir/test_syr.cc.o CMakeFiles/tester.dir/test_syr2.cc.o CMakeFiles/tester.dir/test_syr2k.cc.o CMakeFiles/tester.dir/test_syrk.cc.o CMakeFiles/tester.dir/test_trmm.cc.o CMakeFiles/tester.dir/test_trmv.cc.o CMakeFiles/tester.dir/test_trsm.cc.o CMakeFiles/tester.dir/test_trsv.cc.o CMakeFiles/tester.dir/cblas_wrappers.cc.o CMakeFiles/tester.dir/lapack_wrappers.cc.o CMakeFiles/tester.dir/test_batch_gemm_device.cc.o CMakeFiles/tester.dir/test_batch_hemm_device.cc.o CMakeFiles/tester.dir/test_batch_her2k_device.cc.o CMakeFiles/tester.dir/test_batch_herk_device.cc.o CMakeFiles/tester.dir/test_schur_gemm.cc.o CMakeFiles/tester.dir/test_batch_symm_device.cc.o CMakeFiles/tester.dir/test_batch_syr2k_device.cc.o CMakeFiles/tester.dir/test_batch_syrk_device.cc.o CMakeFiles/tester.dir/test_batch_trmm_device.cc.o CMakeFiles/tester.dir/test_batch_trsm_device.cc.o CMakeFiles/tester.dir/test_axpy_device.cc.o CMakeFiles/tester.dir/test_dot_device.cc.o CMakeFiles/tester.dir/test_dotu_device.cc.o CMakeFiles/tester.dir/test_nrm2_device.cc.o CMakeFiles/tester.dir/test_scal_device.cc.o CMakeFiles/tester.dir/test_swap_device.cc.o CMakeFiles/tester.dir/test_copy_device.cc.o CMakeFiles/tester.dir/test_gemm_device.cc.o CMakeFiles/tester.dir/test_hemm_device.cc.o CMakeFiles/tester.dir/test_her2k_device.cc.o CMakeFiles/tester.dir/test_herk_device.cc.o CMakeFiles/tester.dir/test_symm_device.cc.o CMakeFiles/tester.dir/test_syr2k_device.cc.o CMakeFiles/tester.dir/test_syrk_device.cc.o CMakeFiles/tester.dir/test_trmm_device.cc.o CMakeFiles/tester.dir/test_trsm_device.cc.o -o tester  -Wl,-rpath,/opt/local/lib ../_deps/testsweeper-build/libtestsweeper.1.0.0.dylib ../libblaspp.1.0.0.dylib /opt/local/lib/gcc14/libgomp.dylib -framework Accelerate
Undefined symbols:
  "___atomic_store_8", referenced from:
      __Z10setup_PAPIPi in test.cc.o
ld: symbol(s) not found
collect2: error: ld returned 1 exit status
make[2]: *** [test/tester] Error 1

This is not OS-specific issue, it will fail likewise on *BSD and Linux on certain 32-bit archs (arm, ppc, likely mips).

mgates3 commented 3 weeks ago

Thanks for the report. Would something like this work as a check? I don't have a 32-bit system handy to check on.

require_libatomic.cc:

#include <atomic>

int main( int argc, char** argv )
{
    std::atomic<int> x = 0;
    for (int i = 1; i < argc; ++i) {
        ++x;
    }
    return x;
}

Try to compile and link:

g++ -std=c++17 -o require_libatomic require_libatomic.cc 

If not, try to compile and link:

g++ -std=c++17 -o require_libatomic require_libatomic.cc -latomic

If so, that's fairly easy to integrate into the Makefile / CMake build scripts.

barracuda156 commented 3 weeks ago

@mgates3 Thank you for responding!

Checking for int does not serve the purpose, since 4-byte atomics is usually supported everywhere (and for sure on ppc at least). What may not be supported is 8-byte atomics, so we need to check for a corresponding type. (I have also seen in some tickets that RISC-V may not support 1-byte atomics, but cannot confirm that personally.)

mgates3 commented 3 weeks ago

That explains the issue better. So:

#include <atomic>
#include <cstdint>

int main( int argc, char** argv )
{
    std::atomic<std::int64_t> x = 0;
    for (int i = 1; i < argc; ++i) {
        ++x;
    }
    return x;
}
barracuda156 commented 3 weeks ago

This works as expected (fails without libatomic, succeeds with the flag added):

36-150% /opt/local/bin/gcc-mp-14 -std=c++17 -o require_libatomic require_libatomic.cc
Undefined symbols:
  "___atomic_fetch_add_8", referenced from:
      __ZNSt13__atomic_baseIxEppEv in ccpntpHJ.o
  "___atomic_load_8", referenced from:
      __ZNKSt13__atomic_baseIxEcvxEv in ccpntpHJ.o
ld: symbol(s) not found
collect2: error: ld returned 1 exit status
36-150% /opt/local/bin/gcc-mp-14 -std=c++17 -o require_libatomic require_libatomic.cc -latomic
36-150%