Skip to content

Commit

Permalink
fix mkl for amd cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
hczhai committed Nov 4, 2023
1 parent e770aca commit cf08cb2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
30 changes: 27 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ jobs:
if [ "$CPUTYPE" = "AuthenticAMD" ]; then
echo "int mkl_serv_intel_cpu_true() { return 1; }" > fixcpu.c
$CC -shared -fPIC -o libfixcpu.so fixcpu.c
export LD_PRELOAD=$PWD/libfixcpu.so
fi
getconf LONG_BIT
- name: build gtest (macos)
if: matrix.os == 'macos-12'
Expand Down Expand Up @@ -145,8 +145,18 @@ jobs:
cmake .. -DUSE_MKL=ON -DBUILD_TEST=ON -DLARGE_BOND=ON -DUSE_COMPLEX=ON -DUSE_SINGLE_PREC=ON -DUSE_SG=ON
make -j 2
- name: run test (serial)
if: matrix.parallel == 'serial'
- name: run test (serial, linux)
if: matrix.parallel == 'serial' && matrix.os == 'ubuntu-20.04'
run: |
export CPUTYPE=$(lscpu | grep 'Vendor ID' | awk '{print $3}')
if [ "$CPUTYPE" = "AuthenticAMD" ]; then
export LD_PRELOAD=$PWD/libfixcpu.so
fi
cd build_test
./block2_tests
- name: run test (serial, macos)
if: matrix.parallel == 'serial' && matrix.os == 'macos-12'
run: |
cd build_test
./block2_tests
Expand All @@ -156,6 +166,11 @@ jobs:
run: |
python -m pip install pytest 'pyscf==2.1.0' 'scipy==1.10.1'
export PYTHONPATH=$(pwd)/build:$(pwd):${PYTHONPATH}
export CPUTYPE=$(lscpu | grep 'Vendor ID' | awk '{print $3}')
if [ "$CPUTYPE" = "AuthenticAMD" ]; then
export LD_PRELOAD=$PWD/libfixcpu.so
fi
echo $LD_PRELOAD
py.test -s pyblock2/unit_test/*.py
- name: run test (serial-pytest, macos)
Expand All @@ -170,6 +185,11 @@ jobs:
run: |
python -m pip install pytest 'pyscf==2.1.0' 'scipy==1.10.1'
export PYTHONPATH=$(pwd)/build:$(pwd):${PYTHONPATH}
export CPUTYPE=$(lscpu | grep 'Vendor ID' | awk '{print $3}')
if [ "$CPUTYPE" = "AuthenticAMD" ]; then
export LD_PRELOAD=$PWD/libfixcpu.so
fi
echo $LD_PRELOAD
py.test -s pyblock2/unit_test/*.py --symm sany
- name: run test (any-symm-pytest, macos)
Expand All @@ -193,6 +213,10 @@ jobs:
- name: run test (mpi)
if: matrix.parallel == 'mpi'
run: |
export CPUTYPE=$(lscpu | grep 'Vendor ID' | awk '{print $3}')
if [ "$CPUTYPE" = "AuthenticAMD" ]; then
export LD_PRELOAD=$PWD/libfixcpu.so
fi
cd build_test
mpirun -n 2 ./block2_tests
Expand Down
22 changes: 21 additions & 1 deletion docs/source/developer/hints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ library is linked to only pure "so.1" or only pure "so".

**Error:** ::

Insert ``cout`` in openMP parallel code will cause stuck. Because it is not thread-safe. Use ``printf`` instead.
Insert ``cout`` in openMP parallel code will cause dead lock. Because it is not thread-safe. Use ``printf`` instead.

[2023-10-13]

Expand All @@ -358,3 +358,23 @@ library is linked to only pure "so.1" or only pure "so".
ImportError: /.../block2.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZNSt15__exception_ptr13exception_ptr10_M_releaseEv

**Solution:** This happens when code is compiled using gcc/12.2.0 but gcc module is not loaded. If compile using gcc/9.2.0 there is no problem.

[2023-11-03]

**Error:** ::

INTEL MKL ERROR: /opt/hostedtoolcache/Python/3.9.18/x64/lib/libmkl_def.so.1: undefined symbol: mkl_sparse_optimize_bsr_trsm_i8.
Intel MKL FATAL ERROR: Cannot load libmkl_def.so.1.

.. highlight:: bash

**Solution:** Check if this only happens in the AMD CPU but not Intel CPU. If this is the case, we can fix this by the ``fakeintel`` trick ::

export CPUTYPE=$(lscpu | grep 'Vendor ID' | awk '{print $3}')
if [ "$CPUTYPE" = "AuthenticAMD" ]; then
echo "int mkl_serv_intel_cpu_true() { return 1; }" > fixcpu.c
$CC -shared -fPIC -o libfixcpu.so fixcpu.c
export LD_PRELOAD=$PWD/libfixcpu.so
fi

.. highlight:: text

0 comments on commit cf08cb2

Please sign in to comment.