Skip to content

Commit 2ac981d

Browse files
committed
AMD-AOCC-AOCL update and minor fixed
1 parent 630453d commit 2ac981d

15 files changed

+330
-48
lines changed

toolchain/README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ and give setup files that you can use to compile ABACUS.
2727
- [x] Support for [LibRI](https://github.com/abacusmodeling/LibRI) by submodule or automatic installation from github.com (but installed LibRI via `wget` seems to have some problem, please be cautious)
2828
- [x] A mirror station by Bohrium database, which can download CEREAL, LibNPY, LibRI and LibComm by `wget` in China Internet.
2929
- [x] Support for GPU compilation, users can add `-DUSE_CUDA=1` in builder scripts.
30-
- [ ] Support for AMD compiler and math lib like `AOCL` and `AOCC` (doing)
30+
- [x] Support for AMD compiler and math lib `AOCL` and `AOCC` (not fully complete due to flang and AOCC-ABACUS compliation error)
3131
- [ ] Change the downloading url from cp2k mirror to other mirror or directly downloading from official website. (doing)
3232
- [ ] Support a JSON or YAML configuration file for toolchain, which can be easily modified by users.
3333
- [ ] A better README and Detail markdown file.
@@ -50,6 +50,8 @@ There are also well-modified script to run *install_abacus_toolchain.sh* for `gn
5050
> ./toolchain_gnu.sh
5151
# for intel-mkl
5252
> ./toolchain_intel.sh
53+
# for amd aocc-aocl
54+
> ./toolchain_amd.sh
5355
# for intel-mkl-mpich
5456
> ./toolchain_intel-mpich.sh
5557
```
@@ -121,8 +123,12 @@ The needed dependencies version default:
121123
- `ELPA` 2025.01.001
122124
- `CEREAL` 1.3.2
123125
- `RapidJSON` 1.1.0
124-
And Intel-oneAPI need user or server manager to manually install from Intel.
125-
[Intel-oneAPI](https://www.intel.cn/content/www/cn/zh/developer/tools/oneapi/toolkits.html)
126+
And:
127+
- Intel-oneAPI need user or server manager to manually install from Intel.
128+
- - [Intel-oneAPI](https://www.intel.cn/content/www/cn/zh/developer/tools/oneapi/toolkits.html)
129+
- AMD AOCC-AOCL need user or server manager to manually install from AMD.
130+
- - [AOCC](https://www.amd.com/zh-cn/developer/aocc.html)
131+
- - [AOCL](https://www.amd.com/zh-cn/developer/aocl.html)
126132

127133
Dependencies below are optional, which is NOT installed by default:
128134

@@ -152,6 +158,8 @@ If compliation is successful, a message will be shown like this:
152158
> ./build_abacus_gnu.sh
153159
> To build ABACUS by intel-toolchain, just use:
154160
> ./build_abacus_intel.sh
161+
> To build ABACUS by amd-toolchain in gcc-aocl, just use:
162+
> ./build_abacus_amd.sh
155163
> or you can modify the builder scripts to suit your needs.
156164
```
157165

@@ -183,6 +191,14 @@ or you can also do it in a more completely way:
183191

184192
### Intel-oneAPI problem
185193

194+
#### OneAPI 2025.0 problem
195+
196+
Generally, OneAPI 2025.0 can be useful to compile basic function of ABACUS, but one will encounter compatible problem related to something. Here is the treatment
197+
- related to rapidjson:
198+
- - Not to use rapidjson in your toolchain
199+
- - or use the master branch of [RapidJSON](https://github.com/Tencent/rapidjson)
200+
- related to LibRI: not to use LibRI or downgrade your OneAPI.
201+
186202
#### ELPA problem via Intel-oneAPI toolchain in AMD server
187203

188204
The default compiler for Intel-oneAPI is `icpx` and `icx`, which will cause problem when compling ELPA in AMD server. (Which is a problem and needed to have more check-out)
@@ -210,12 +226,27 @@ And will not occur in Intel-MPI before 2021.10.0 (Intel-oneAPI before 2023.2.0)
210226

211227
More problem and possible solution can be accessed via [#2928](https://github.com/deepmodeling/abacus-develop/issues/2928)
212228

229+
### AMD AOCC-AOCL problem
230+
231+
You cannot use AOCC to complie abacus now, see [#5982](https://github.com/deepmodeling/abacus-develop/issues/5982) .
232+
233+
However, use AOCC-AOCL to compile dependencies is permitted and usually get boosting in ABACUS effciency. But you need to get rid of `flang` while compling ELPA. Toolchain itself help you make this `flang` shade in default, and you can manully use `flang` by setting `--with-flang=yes` in `toolchain_amd.sh` to have a try.
234+
235+
Notice: ABACUS via GCC-AOCL in AOCC-AOCL toolchain have no application with DeePKS, DeePMD and LibRI.
213236

214237
### OpenMPI problem
215238

216239
#### in EXX and LibRI
217240

218-
- GCC toolchain with OpenMPI cannot compile LibComm v0.1.1 due to the different MPI variable type from MPICH and IntelMPI, see discussion here [#5033](https://github.com/deepmodeling/abacus-develop/issues/5033), you can switch to GCC-MPICH or Intel toolchain
241+
- GCC toolchain with OpenMPI cannot compile LibComm v0.1.1 due to the different MPI variable type from MPICH and IntelMPI, see discussion here [#5033](https://github.com/deepmodeling/abacus-develop/issues/5033), you can try use a newest branch of LibComm by
242+
```
243+
git clone https://gitee.com/abacus_dft/LibComm -b MPI_Type_Contiguous_Pool
244+
```
245+
or pull the newest master branch of LibComm
246+
```
247+
git clone https://github.com/abacusmodeling/LibComm
248+
```
249+
. yet another is switching to GCC-MPICH or Intel toolchain
219250
- It is recommended to use Intel toolchain if one wants to include EXX feature in ABACUS, which can have much better performance and can use more than 16 threads in OpenMP parallelization to accelerate the EXX process.
220251

221252
#### OpenMPI-v5

toolchain/build_abacus_gnu-aocl.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
#SBATCH -J build
3+
#SBATCH -N 1
4+
#SBATCH -n 16
5+
#SBATCH -o install.log
6+
#SBATCH -e install.err
7+
# JamesMisaka in 2025.03.09
8+
9+
# Build ABACUS by amd-openmpi toolchain
10+
11+
# module load openmpi aocc aocl
12+
13+
ABACUS_DIR=..
14+
TOOL=$(pwd)
15+
INSTALL_DIR=$TOOL/install
16+
source $INSTALL_DIR/setup
17+
cd $ABACUS_DIR
18+
ABACUS_DIR=$(pwd)
19+
#AOCLhome=/opt/aocl # user can specify this parameter
20+
21+
BUILD_DIR=build_abacus_gnu
22+
rm -rf $BUILD_DIR
23+
24+
PREFIX=$ABACUS_DIR
25+
ELPA=$INSTALL_DIR/elpa-2025.01.001/cpu
26+
CEREAL=$INSTALL_DIR/cereal-1.3.2/include/cereal
27+
LIBXC=$INSTALL_DIR/libxc-7.0.0
28+
RAPIDJSON=$INSTALL_DIR/rapidjson-1.1.0/
29+
# LAPACK=$AOCLhome/lib
30+
# SCALAPACK=$AOCLhome/lib
31+
# FFTW3=$AOCLhome
32+
# LIBRI=$INSTALL_DIR/LibRI-0.2.1.0
33+
# LIBCOMM=$INSTALL_DIR/LibComm-0.1.1
34+
# LIBTORCH=$INSTALL_DIR/libtorch-2.1.2/share/cmake/Torch
35+
# LIBNPY=$INSTALL_DIR/libnpy-1.0.1/include
36+
# DEEPMD=$HOME/apps/anaconda3/envs/deepmd # v3.0 might have problem
37+
38+
# if clang++ have problem, switch back to g++
39+
40+
cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \
41+
-DCMAKE_CXX_COMPILER=clang++ \
42+
-DMPI_CXX_COMPILER=mpicxx \
43+
-DELPA_DIR=$ELPA \
44+
-DCEREAL_INCLUDE_DIR=$CEREAL \
45+
-DLibxc_DIR=$LIBXC \
46+
-DENABLE_LCAO=ON \
47+
-DENABLE_LIBXC=ON \
48+
-DUSE_OPENMP=ON \
49+
-DUSE_ELPA=ON \
50+
-DENABLE_RAPIDJSON=ON \
51+
-DRapidJSON_DIR=$RAPIDJSON \
52+
# -DLAPACK_DIR=$LAPACK \
53+
# -DSCALAPACK_DIR=$SCALAPACK \
54+
# -DFFTW3_DIR=$FFTW3 \
55+
# -DENABLE_DEEPKS=1 \
56+
# -DTorch_DIR=$LIBTORCH \
57+
# -Dlibnpy_INCLUDE_DIR=$LIBNPY \
58+
# -DENABLE_LIBRI=ON \
59+
# -DLIBRI_DIR=$LIBRI \
60+
# -DLIBCOMM_DIR=$LIBCOMM \
61+
# -DDeePMD_DIR=$DEEPMD \
62+
63+
# if one want's to include deepmd, your system gcc version should be >= 11.3.0 for glibc requirements
64+
65+
cmake --build $BUILD_DIR -j `nproc`
66+
cmake --install $BUILD_DIR 2>/dev/null
67+
68+
# generate abacus_env.sh
69+
cat << EOF > "${TOOL}/abacus_env.sh"
70+
#!/bin/bash
71+
source $INSTALL_DIR/setup
72+
export PATH="${PREFIX}/bin":\${PATH}
73+
EOF
74+
75+
# generate information
76+
cat << EOF
77+
========================== usage =========================
78+
Done!
79+
To use the installed ABACUS version
80+
You need to source ${TOOL}/abacus_env.sh first !
81+
"""
82+
EOF

toolchain/build_abacus_gnu.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#SBATCH -n 16
55
#SBATCH -o install.log
66
#SBATCH -e install.err
7-
# install ABACUS with libxc and deepks
87
# JamesMisaka in 2025.03.09
98

109
# Build ABACUS by gnu-toolchain

toolchain/build_abacus_intel-mpich.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
#SBATCH -n 16
55
#SBATCH -o install.log
66
#SBATCH -e install.err
7-
# build and install ABACUS with libxc, also can with deepks and deepmd
87
# JamesMisaka in 2025.03.09
98

109
# Build ABACUS by intel-toolchain with mpich
1110

1211
# module load mkl compiler
13-
# source path/to/vars.sh
12+
# source path/to/setvars.sh
1413

1514
ABACUS_DIR=..
1615
TOOL=$(pwd)

toolchain/build_abacus_intel.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
#SBATCH -n 16
55
#SBATCH -o install.log
66
#SBATCH -e install.err
7-
# install ABACUS with libxc and deepks
87
# JamesMisaka in 2025.03.09
98

109
# Build ABACUS by intel-toolchain
1110

1211
# module load mkl compiler mpi
13-
# source path/to/vars.sh
12+
# source path/to/setvars.sh
1413

1514
ABACUS_DIR=..
1615
TOOL=$(pwd)

toolchain/install_abacus_toolchain.sh

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ The --with-PKG options follow the rules:
159159
Default = yes
160160
--with-amd Use the AMD compiler to build CP2K.
161161
Default = system
162+
--with-flang Use flang in AMD compiler, which may lead to problem and efficiency loss in ELPA
163+
Default = no
162164
--with-cmake Cmake utilities
163165
Default = install
164166
--with-openmpi OpenMPI, important if you want a parallel version of ABACUS.
@@ -183,6 +185,10 @@ The --with-PKG options follow the rules:
183185
it replaces the FFTW library. If the ScaLAPACK component is
184186
found, it replaces the one specified by --with-scalapack.
185187
Default = system
188+
--with-aocl AMD Optimizing CPU Libraries, which provides LAPACK, BLAS, FFTW, ScaLAPACK
189+
the ScaLAPACK and FFTW can directly use which in AOCL by setting --with-scalapack=system and --with-fftw=system if AOCL in system environment.
190+
related scripts are in development to incorporate scalapack and fftw once for all.
191+
Default = system
186192
--with-openblas OpenBLAS is a free high performance LAPACK and BLAS library,
187193
the successor to GotoBLAS.
188194
Default = install
@@ -238,7 +244,7 @@ EOF
238244
# ------------------------------------------------------------------------
239245
tool_list="gcc intel amd cmake"
240246
mpi_list="mpich openmpi intelmpi"
241-
math_list="mkl openblas"
247+
math_list="mkl aocl openblas"
242248
lib_list="fftw libxc scalapack elpa cereal rapidjson libtorch libnpy libri libcomm"
243249
package_list="${tool_list} ${mpi_list} ${math_list} ${lib_list}"
244250
# ------------------------------------------------------------------------
@@ -266,6 +272,9 @@ with_scalapack="__INSTALL__"
266272
if [ "${MKLROOT}" ]; then
267273
export MATH_MODE="mkl"
268274
with_mkl="__SYSTEM__"
275+
elif [ "${AOCLhome}" ]; then
276+
export MATH_MODE="aocl"
277+
with_aocl="__SYSTEM__"
269278
else
270279
export MATH_MODE="openblas"
271280
fi
@@ -292,6 +301,7 @@ if (command -v mpiexec > /dev/null 2>&1); then
292301
echo "MPI is detected and it appears to be Intel MPI"
293302
with_gcc="__DONTUSE__"
294303
with_amd="__DONTUSE__"
304+
with_aocl="__DONTUSE__"
295305
with_intel="__SYSTEM__"
296306
with_intelmpi="__SYSTEM__"
297307
export MPI_MODE="intelmpi"
@@ -318,10 +328,11 @@ export intel_classic="no"
318328
# and will lead to problem in force calculation
319329
# but icx is recommended by intel compiler
320330
# option: --with-intel-classic can change it to yes/no
321-
# zhaoqing by 2023.08
331+
# JamesMisaka by 2023.08
322332
export intelmpi_classic="no"
323-
export with_ifx="yes"
324-
export openmpi_4th="no"
333+
export with_ifx="yes" # whether ifx is used in oneapi
334+
export with_flang="no" # whether flang is used in aocc
335+
export openmpi_4th="no" # whether openmpi downgrade
325336
export GPUVER="no"
326337
export MPICH_DEVICE="ch4"
327338
export TARGET_CPU="native"
@@ -342,6 +353,7 @@ if [ "${CRAY_LD_LIBRARY_PATH}" ]; then
342353
# set default value for some installers appropriate for CLE
343354
with_gcc="__DONTUSE__"
344355
with_amd="__DONTUSE__"
356+
with_aocl="__DONTUSE__"
345357
with_intel="__DONTUSE__"
346358
with_fftw="__SYSTEM__"
347359
with_scalapack="__DONTUSE__"
@@ -416,6 +428,12 @@ while [ $# -ge 1 ]; do
416428
cray)
417429
export MATH_MODE="cray"
418430
;;
431+
aocl)
432+
export MATH_MODE="aocl"
433+
with_aocl="__SYSTEM__"
434+
with_fftw="__SYSTEM__"
435+
with_scalapack="__SYSTEM__"
436+
;;
419437
mkl)
420438
export MATH_MODE="mkl"
421439
;;
@@ -424,7 +442,7 @@ while [ $# -ge 1 ]; do
424442
;;
425443
*)
426444
report_error ${LINENO} \
427-
"--math-mode currently only supports mkl, and openblas as options"
445+
"--math-mode currently only supports mkl, aocl, openblas and cray as options"
428446
;;
429447
esac
430448
;;
@@ -519,9 +537,6 @@ while [ $# -ge 1 ]; do
519537
export MPI_MODE=intelmpi
520538
fi
521539
;;
522-
--with-amd*)
523-
with_amd=$(read_with "${1}" "__SYSTEM__")
524-
;;
525540
--with-intel-classic*)
526541
intel_classic=$(read_with "${1}" "no") # default new intel compiler
527542
;;
@@ -534,6 +549,15 @@ while [ $# -ge 1 ]; do
534549
--with-ifx*)
535550
with_ifx=$(read_with "${1}" "yes") # default yes
536551
;;
552+
--with-amd*)
553+
with_amd=$(read_with "${1}" "__SYSTEM__")
554+
;;
555+
--with-flang*)
556+
with_flang=$(read_with "${1}" "no")
557+
;;
558+
--with-aocl*)
559+
with_aocl=$(read_with "${1}" "__SYSTEM__")
560+
;;
537561
--with-libxc*)
538562
with_libxc=$(read_with "${1}")
539563
;;
@@ -864,6 +888,8 @@ To build ABACUS by gnu-toolchain, just use:
864888
./build_abacus_gnu.sh
865889
To build ABACUS by intel-toolchain, just use:
866890
./build_abacus_intel.sh
891+
To build ABACUS by amd-toolchain in gcc-aocl, just use:
892+
./build_abacus_gnu-aocl.sh
867893
or you can modify the builder scripts to suit your needs.
868894
"""
869895
EOF

toolchain/scripts/stage0/install_amd.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ case "${with_amd}" in
3333
echo "==================== Finding AMD compiler from system paths ===================="
3434
check_command clang "amd" && CC="$(realpath $(command -v clang))" || exit 1
3535
check_command clang++ "amd" && CXX="$(realpath $(command -v clang++))" || exit 1
36-
check_command gfortran "gcc" && FC="gfortran" || exit 1
37-
add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS}
38-
#check_command flang "amd" && FC="$(realpath $(command -v flang))" || exit 1
36+
if [ "${with_flang}" = "yes" ]; then
37+
check_command flang "amd" && FC="$(realpath $(command -v flang))" || exit 1
38+
else
39+
check_command gfortran "gcc" && FC="gfortran" || exit 1
40+
add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS}
41+
fi
3942
F90="${FC}"
4043
F77="${FC}"
4144
;;
@@ -50,8 +53,11 @@ case "${with_amd}" in
5053
check_dir "${pkg_install_dir}/include"
5154
check_command ${pkg_install_dir}/bin/clang "amd" && CC="${pkg_install_dir}/bin/clang" || exit 1
5255
check_command ${pkg_install_dir}/bin/clang++ "amd" && CXX="${pkg_install_dir}/bin/clang++" || exit 1
53-
check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1
54-
#check_command ${pkg_install_dir}/bin/flang "amd" && FC="${pkg_install_dir}/bin/flang" || exit 1
56+
if [ "${with_flang}" = "yes" ]; then
57+
check_command ${pkg_install_dir}/bin/flang "amd" && FC="${pkg_install_dir}/bin/flang" || exit 1
58+
else
59+
check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1
60+
fi
5561
F90="${FC}"
5662
F77="${FC}"
5763
AMD_CFLAGS="-I'${pkg_install_dir}/include'"
@@ -64,8 +70,11 @@ if [ "${with_amd}" != "__DONTUSE__" ]; then
6470
echo "CXX is ${CXX}"
6571
[ $(realpath $(command -v clang++) | grep -e aocc-compiler) ] || echo "Check the AMD C++ compiler path"
6672
echo "FC is ${FC}"
67-
#[ $(realpath $(command -v flang) | grep -e aocc-compiler) ] || echo "Check the AMD Fortran compiler path"
68-
[ $(realpath $(command -v gfortran) | grep -e aocc-compiler) ] || echo "Check the AMD Fortran compiler path"
73+
if [ "${with_flang}" = "yes" ]; then
74+
[ $(realpath $(command -v flang) | grep -e aocc-compiler) ] || echo "Check the AMD Fortran compiler path"
75+
else
76+
[ $(realpath $(command -v gfortran) | grep -e aocc-compiler) ] || echo "Check the GNU Fortran compiler path"
77+
fi
6978
cat << EOF > "${BUILDDIR}/setup_amd"
7079
export CC="${CC}"
7180
export CXX="${CXX}"

0 commit comments

Comments
 (0)