Trouble During Shared Library Linking for ML-IAP

I cloned the most recent develop branch of the LAMMPS github repo and I attempted to build and install it using a fresh miniconda env with the following cmake setup

cmake ../cmake \
  -C ../cmake/presets/most.cmake \
  -D CMAKE_BUILD_TYPE=Release \
  -D CMAKE_INSTALL_PREFIX=$(pwd) \
  -D BUILD_MPI=ON \
  -D PKG_VORONOI=NO \
  -D PKG_ML-IAP=ON \
  -D PKG_ML-SNAP=ON \
  -D MLIAP_ENABLE_PYTHON=ON \
  -D PKG_GPU=cuda \
  -D PKG_PYTHON=ON \
  -D BUILD_SHARED_LIBS=ON \
  -D PKG_KOKKOS=yes \
  -D GPU_ARCH=sm_86 \
  -D Kokkos_ARCH_AMPERE86=yes \
  -D CMAKE_C_COMPILER="$CC" \
  -D CMAKE_CXX_COMPILER="$CXX"

Building goes fine; however, during linking I am getting what seems to be a conflict in source code definitions

/home/dma/miniconda3/envs/lammps-dev/bin/../lib/gcc/x86_64-conda-linux-gnu/12.4.0/../../../../x86_64-conda-linux-gnu/bin/ld: CMakeFiles/lammps.dir/cython/mliap_unified_couple.cpp.o: in function `__pyx_CommonTypesMetaclass_get_module(_object*, void*)':
mliap_unified_couple.cpp:(.text._Z37__pyx_CommonTypesMetaclass_get_moduleP7_objectPv+0x0): multiple definition of `__pyx_CommonTypesMetaclass_get_module(_object*, void*)'; CMakeFiles/lammps.dir/cython/mliap_model_python_couple.cpp.o:mliap_model_python_couple.cpp:(.text._Z37__pyx_CommonTypesMetaclass_get_moduleP7_objectPv+0x0): first defined here
/home/dma/miniconda3/envs/lammps-dev/bin/../lib/gcc/x86_64-conda-linux-gnu/12.4.0/../../../../x86_64-conda-linux-gnu/bin/ld: CMakeFiles/lammps.dir/cython/mliap_model_python_couple_kokkos.cpp.o: in function `__pyx_CommonTypesMetaclass_get_module(_object*, void*)':
mliap_model_python_couple_kokkos.cpp:(.text._Z37__pyx_CommonTypesMetaclass_get_moduleP7_objectPv+0x0): multiple definition of `__pyx_CommonTypesMetaclass_get_module(_object*, void*)'; CMakeFiles/lammps.dir/cython/mliap_model_python_couple.cpp.o:mliap_model_python_couple.cpp:(.text._Z37__pyx_CommonTypesMetaclass_get_moduleP7_objectPv+0x0): first defined here
/home/dma/miniconda3/envs/lammps-dev/bin/../lib/gcc/x86_64-conda-linux-gnu/12.4.0/../../../../x86_64-conda-linux-gnu/bin/ld: CMakeFiles/lammps.dir/cython/mliap_unified_couple_kokkos.cpp.o: in function `__pyx_CommonTypesMetaclass_get_module(_object*, void*)':
mliap_unified_couple_kokkos.cpp:(.text._Z37__pyx_CommonTypesMetaclass_get_moduleP7_objectPv+0x0): multiple definition of `__pyx_CommonTypesMetaclass_get_module(_object*, void*)'; CMakeFiles/lammps.dir/cython/mliap_model_python_couple.cpp.o:mliap_model_python_couple.cpp:(.text._Z37__pyx_CommonTypesMetaclass_get_moduleP7_objectPv+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/lammps.dir/build.make:27126: liblammps.so.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:550: CMakeFiles/lammps.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

I am typically pretty good with lammps but the quirks of the ML-IAP unified interface has me needing assistance. Axel (or Nick) if you are out there, I would very much appreciate the help. It might be relevant to also mention I am using Cython version 3.1.2, python 3.11, and the GPUs are A6000s.

Since I hate conda (for the many bad choices contributors of conda packages make and how it can easily lead to inconsistent software installations) and dislike cython, I have no comments that are compatible with the community guidelines here.

I’m seeing this error without miniconda and Python 3.12.

My build script is below:

# Compiles LAMMPS ML-IAP

# Activate environment which contains the cuEQ ops
which python
if [ ! -e venv ]; then
  python -m venv ./venv
fi
source venv/bin/activate
pip install -r requirements.txt  # Can send, it's just the MACE requirements
which python

# Add CUDA to path
export PATH=/usr/local/cuda-12/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

mkdir -p build-mliap
cd build-mliap
cmake \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_PREFIX=$(pwd) \
    -D CMAKE_CXX_STANDARD=17 \
    -D CMAKE_CXX_STANDARD_REQUIRED=ON \
    -D BUILD_SHARED_LIBS=ON \
    -D BUILD_MPI=OFF \
    -D PKG_KOKKOS=ON \
    -D Kokkos_ENABLE_CUDA=ON \
    -D CMAKE_CXX_COMPILER=$(pwd)/../lib/kokkos/bin/nvcc_wrapper \
    -D Kokkos_ARCH_ZEN3=ON \
    -D Kokkos_ARCH_ADA89=ON \
    -D CMAKE_PREFIX_PATH=$(pwd)/../../libtorch \
    -D MKL_INCLUDE_DIR=`pwd` \
    -D PKG_ML-IAP=ON \
    -D PKG_ML-SNAP=ON \
    -D MLIAP_ENABLE_PYTHON=ON \
    -D PKG_PYTHON=ON \
    ../cmake

# Fix some compiler flags
sed -i 's/ -Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128//' CMakeFiles/*.dir/flags.make

# Build
make -j 32
make install
make install-python

I was able to fix mine with LDFLAGS

export LDFLAGS="-Wl,--allow-multiple-definition"

but this isn’t exactly a satisfactory solution.

1 Like

It is not that much worse than what cython does itself.

I saw the same error today. Downgrading cython to 3.0.11 seemed to work for me.

pip install --upgrade cython==3.0.11