Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,24 @@ if (USE_SW)
include_directories(${SW_MATH}/include)
include_directories(${SW_FFT}/include)

# Keep test and main target link dependencies consistent in USE_SW mode.
list(APPEND math_libs
${SW_MATH}/libswfft.a
${SW_MATH}/libswscalapack.a
${SW_MATH}/libswlapack.a
${SW_MATH}/libswblas.a
gfortran)

# Provide a unified ScaLAPACK target for unit tests and modules.
# In USE_SW mode, map it to SW math libraries instead of find_package(ScaLAPACK).
if(NOT TARGET ScaLAPACK::ScaLAPACK)
add_library(ScaLAPACK::ScaLAPACK INTERFACE IMPORTED GLOBAL)
set_target_properties(
ScaLAPACK::ScaLAPACK
PROPERTIES INTERFACE_LINK_LIBRARIES
"${SW_MATH}/libswscalapack.a;${SW_MATH}/libswlapack.a;${SW_MATH}/libswblas.a")
endif()

target_link_libraries(${ABACUS_BIN_NAME} ${SW_FFT}/lib/libfftw3.a)
endif()

Expand Down Expand Up @@ -811,14 +829,6 @@ if(ENABLE_RAPIDJSON)
target_link_libraries(${ABACUS_BIN_NAME} json_output)
endif()

if (USE_SW)
target_link_libraries(${ABACUS_BIN_NAME} ${SW_MATH}/libswfft.a)
target_link_libraries(${ABACUS_BIN_NAME} ${SW_MATH}/libswscalapack.a)
target_link_libraries(${ABACUS_BIN_NAME} ${SW_MATH}/libswlapack.a)
target_link_libraries(${ABACUS_BIN_NAME} ${SW_MATH}/libswblas.a)
list(APPEND math_libs gfortran)
endif()

list(APPEND math_libs m)
target_link_libraries(${ABACUS_BIN_NAME} ${math_libs})

Expand Down
18 changes: 18 additions & 0 deletions PR_DESCRIPTION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Title: Add gtest support for Sunway builds

Summary:
- Add a Sunway-specific gtest build script and documentation under tools.
- Update CMake test definitions to better handle Sunway constraints and selective test enabling.
- Register additional unit test CMakeLists for hsolver and LCAO RT modules.

Files Changed:
- CMakeLists.txt
- source/source_base/module_container/ATen/kernels/test/CMakeLists.txt
- source/source_base/module_container/test/CMakeLists.txt
- source/source_hsolver/test/CMakeLists.txt
- source/source_lcao/module_rt/test/CMakeLists.txt
- tools/README.md
- tools/gtest_on_sunway/gtest_on_sunway.sh

Testing:
- Not run (please confirm if you ran any tests)
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
AddTest(
TARGET MODULE_BASE_container_kernels_uts
LIBS parameter ${math_libs}
SOURCES blas_test.cpp lapack_test.cpp
memory_test.cpp linalg_test.cpp
)
if(USE_SW)
message(WARNING "Skip MODULE_BASE_container_kernels_uts on USE_SW.")
else()
AddTest(
TARGET MODULE_BASE_container_kernels_uts
LIBS parameter ${math_libs}
SOURCES blas_test.cpp lapack_test.cpp
memory_test.cpp linalg_test.cpp
)

target_link_libraries(MODULE_BASE_container_kernels_uts container base device)
target_link_libraries(MODULE_BASE_container_kernels_uts container base device)
endif()
19 changes: 12 additions & 7 deletions source/source_base/module_container/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
remove_definitions(-D__MPI)

AddTest(
TARGET MODULE_BASE_CONTAINER_Unittests
LIBS parameter container base device ${math_libs}
SOURCES tensor_test.cpp tensor_shape_test.cpp allocator_test.cpp
tensor_buffer_test.cpp tensor_map_test.cpp
tensor_utils_test.cpp tensor_accessor_test.cpp
)
# Disable this test on Sunway (USE_SW) due to LAPACK symbol issues.
if(USE_SW)
message(WARNING "Skip MODULE_BASE_CONTAINER_Unittests on USE_SW.")
else()
AddTest(
TARGET MODULE_BASE_CONTAINER_Unittests
LIBS parameter container base device ${math_libs}
SOURCES tensor_test.cpp tensor_shape_test.cpp allocator_test.cpp
tensor_buffer_test.cpp tensor_map_test.cpp
tensor_utils_test.cpp tensor_accessor_test.cpp
)
endif()
4 changes: 4 additions & 0 deletions source/source_hsolver/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ if (ENABLE_MPI)
LIBS parameter ${math_libs} base device MPI::MPI_CXX
SOURCES parallel_k2d_test.cpp ../parallel_k2d.cpp ../../source_cell/parallel_kpoints.cpp
)
if (USE_SW)
message(WARNING "Skip MODULE_HSOLVER_parak2d_test on USE_SW due to LAPACK symbol issues.")
else()
AddTest(
TARGET MODULE_HSOLVER_bpcg
LIBS parameter ${math_libs} base psi device container
Expand All @@ -16,6 +19,7 @@ if (ENABLE_MPI)
../../source_hamilt/operator.cpp
../../source_pw/module_pwdft/op_pw.cpp
)
endif()
AddTest(
TARGET MODULE_HSOLVER_cg
LIBS parameter ${math_libs} base psi device container
Expand Down
4 changes: 4 additions & 0 deletions source/source_lcao/module_rt/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
remove_definitions(-D __MPI)

if (USE_SW)
message(WARNING "Skip MODULE_LCAO_tddft tests on USE_SW due to LAPACK symbol issues.")
else()
add_library(tddft_test_lib tddft_test.cpp)
target_link_libraries(tddft_test_lib Threads::Threads GTest::gtest_main GTest::gmock_main)
#target_include_directories(tddft_test_lib PUBLIC $<$<COMPILE_LANGUAGE:CXX>:${GTEST_INCLUDE_DIRS}>)
Expand Down Expand Up @@ -34,3 +37,4 @@ AddTest(
SOURCES propagator_test1.cpp propagator_test2.cpp propagator_test3.cpp ../propagator.cpp ../propagator_cn2.cpp ../propagator_taylor.cpp ../propagator_etrs.cpp
)

endif()
4 changes: 3 additions & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ opt_orb_pytorch_dpsi: related to generating NAO basis set.

qo: generate quasiatomic orbital (qo).

selective_dynamics: used to do selective dynamics with ABACUS + Phonopy.
selective_dynamics: used to do selective dynamics with ABACUS + Phonopy.

gtest_on_sunway: install gtest on sunway
208 changes: 208 additions & 0 deletions tools/gtest_on_sunway/gtest_on_sunway.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
#!/usr/bin/env bash
set -euo pipefail

# Build ABACUS in two modes:
# 1) no-tests mode (default): preserve original build flow without GTest
# 2) with-tests mode: build and use local/offline GoogleTest
# Usage:
# bash tools/gtest_on_sunway/gtest_on_sunway.sh --no-tests [abacus_root]
# bash tools/gtest_on_sunway/gtest_on_sunway.sh --with-tests [abacus_root] /path/to/googletest
# GTEST_SRC=/path/to/googletest bash tools/gtest_on_sunway/gtest_on_sunway.sh --with-tests [abacus_root]
# CC=mpicc CXX=mpic++ bash tools/gtest_on_sunway/gtest_on_sunway.sh --with-tests /path/to/googletest
# bash tools/gtest_on_sunway/gtest_on_sunway.sh --with-tests --cc mpicc --cxx mpic++ /path/to/googletest
# bash tools/gtest_on_sunway/gtest_on_sunway.sh --with-tests --install /path/to/googletest
# bash tools/gtest_on_sunway/gtest_on_sunway.sh --with-tests --use-elpa /path/to/googletest
# Defaults are aligned with your known-good build command and can be overridden
# by environment variables: USE_OPENMP_FLAG, ENABLE_LCAO_FLAG, USE_SW_FLAG,
# SW_MATH_PATH, SW_FFT_PATH, CEREAL_INCLUDE_DIR, CXX_FLAGS_EXTRA.

# Recommended usage for SW platform:
# CC=mpicc CXX=mpic++ bash tools/gtest_on_sunway/gtest_on_sunway.sh --with-tests /path/to/googletest/googletest/

ABACUS_ROOT="$PWD"
GTEST_SRC="${GTEST_SRC:-}"
ENABLE_TESTING="OFF"
C_COMPILER="${CC:-}"
CXX_COMPILER="${CXX:-}"
DO_INSTALL="OFF"
USE_ELPA_FLAG="OFF"
USE_OPENMP_FLAG="${USE_OPENMP_FLAG:-OFF}"
ENABLE_LCAO_FLAG="${ENABLE_LCAO_FLAG:-ON}"
USE_SW_FLAG="${USE_SW_FLAG:-ON}"
SW_MATH_PATH="${SW_MATH_PATH:-/usr/sw/yyzlib/xMath-SACA}"
SW_FFT_PATH="${SW_FFT_PATH:-/usr/sw/yyzlib/fftw-3.3.8}"
CEREAL_INCLUDE_DIR="${CEREAL_INCLUDE_DIR:-}"
CXX_FLAGS_EXTRA="${CXX_FLAGS_EXTRA:--I/usr/sw/yyzlib/xMath-SACA/include}"

POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
--with-tests)
ENABLE_TESTING="ON"
shift
;;
--no-tests)
ENABLE_TESTING="OFF"
shift
;;
--cc)
C_COMPILER="${2:-}"
shift 2
;;
--cxx)
CXX_COMPILER="${2:-}"
shift 2
;;
--install)
DO_INSTALL="ON"
shift
;;
--no-install)
DO_INSTALL="OFF"
shift
;;
--use-elpa)
USE_ELPA_FLAG="ON"
shift
;;
--no-elpa)
USE_ELPA_FLAG="OFF"
shift
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done

if [[ ${#POSITIONAL_ARGS[@]} -ge 2 ]]; then
ABACUS_ROOT="${POSITIONAL_ARGS[0]}"
GTEST_SRC="${POSITIONAL_ARGS[1]}"
elif [[ ${#POSITIONAL_ARGS[@]} -eq 1 ]]; then
# Single-argument mode:
# - with-tests: argument is googletest path
# - no-tests: argument is ABACUS root
if [[ "${ENABLE_TESTING}" == "ON" ]]; then
GTEST_SRC="${POSITIONAL_ARGS[0]}"
else
ABACUS_ROOT="${POSITIONAL_ARGS[0]}"
fi
fi

CMAKE_COMPILER_ARGS=()
if [[ -n "${C_COMPILER}" ]]; then
CMAKE_COMPILER_ARGS+=("-DCMAKE_C_COMPILER=${C_COMPILER}")
fi
if [[ -n "${CXX_COMPILER}" ]]; then
CMAKE_COMPILER_ARGS+=("-DCMAKE_CXX_COMPILER=${CXX_COMPILER}")
fi

ABACUS_CMAKE_ARGS=()
ABACUS_CMAKE_ARGS+=("-DUSE_ELPA=${USE_ELPA_FLAG}")
ABACUS_CMAKE_ARGS+=("-DUSE_OPENMP=${USE_OPENMP_FLAG}")
ABACUS_CMAKE_ARGS+=("-DENABLE_LCAO=${ENABLE_LCAO_FLAG}")
ABACUS_CMAKE_ARGS+=("-DUSE_SW=${USE_SW_FLAG}")
ABACUS_CMAKE_ARGS+=("-DSW_MATH=${SW_MATH_PATH}")
ABACUS_CMAKE_ARGS+=("-DSW_FFT=${SW_FFT_PATH}")
ABACUS_CMAKE_ARGS+=("-DCEREAL_INCLUDE_DIR=${CEREAL_INCLUDE_DIR}")

ABACUS_CMAKE_ARGS+=("-DCMAKE_CXX_FLAGS=${CXX_FLAGS_EXTRA}")

if [[ ! -f "${ABACUS_ROOT}/CMakeLists.txt" ]]; then
echo "Error: invalid ABACUS root: ${ABACUS_ROOT}"
exit 1
fi

NPROC="$(command -v nproc >/dev/null 2>&1 && nproc || getconf _NPROCESSORS_ONLN || echo 4)"

GTEST_PREFIX="${ABACUS_ROOT}/_local/gtest"
GTEST_BUILD_DIR="${ABACUS_ROOT}/_build_gtest"
ABACUS_BUILD_DIR="${ABACUS_ROOT}/build_local_gtest"
ABACUS_INSTALL_PREFIX="${ABACUS_BUILD_DIR}/install"

if [[ "${ENABLE_TESTING}" == "ON" ]]; then
if [[ -z "${GTEST_SRC}" ]]; then
echo "Error: with-tests mode requires googletest source path (arg or GTEST_SRC)"
exit 1
fi
if [[ ! -f "${GTEST_SRC}/CMakeLists.txt" ]]; then
echo "Error: invalid googletest source path: ${GTEST_SRC}"
exit 1
fi

# If user passed repo subdir .../googletest, normalize to repo root so gmock is built too.
if [[ -d "${GTEST_SRC}/../googlemock" && -f "${GTEST_SRC}/../CMakeLists.txt" ]]; then
GTEST_SRC="$(cd "${GTEST_SRC}/.." && pwd)"
fi

echo "== [1/5] Build and install googletest to ${GTEST_PREFIX}"
cmake -S "${GTEST_SRC}" -B "${GTEST_BUILD_DIR}" \
"${CMAKE_COMPILER_ARGS[@]}" \
-DBUILD_GTEST=ON \
-DBUILD_GMOCK=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${GTEST_PREFIX}"

cmake --build "${GTEST_BUILD_DIR}" -j"${NPROC}"

# Always install googletest to a user-writable local prefix.
cmake --install "${GTEST_BUILD_DIR}"

# Use install-tree package config for stable imported targets.
GTEST_CMAKE_DIR=""
for d in "${GTEST_PREFIX}/lib/cmake/GTest" "${GTEST_PREFIX}/lib64/cmake/GTest"; do
if [[ -f "${d}/GTestConfig.cmake" ]]; then
GTEST_CMAKE_DIR="${d}"
break
fi
done

if [[ -z "${GTEST_CMAKE_DIR}" ]]; then
echo "Error: GTestConfig.cmake not found in build or install tree"
exit 1
fi

echo "== [2/5] Configure ABACUS with local GTest (offline mode)"
cmake -S "${ABACUS_ROOT}" -B "${ABACUS_BUILD_DIR}" \
"${CMAKE_COMPILER_ARGS[@]}" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${ABACUS_INSTALL_PREFIX}" \
"${ABACUS_CMAKE_ARGS[@]}" \
-DBUILD_TESTING=ON \
-DGTest_DIR="${GTEST_CMAKE_DIR}" \
-DGTEST_DIR="${GTEST_CMAKE_DIR}" \
-DCMAKE_PREFIX_PATH="${GTEST_PREFIX}" \
-DFETCHCONTENT_FULLY_DISCONNECTED=ON
else
echo "== [1/3] Configure ABACUS without tests (original mode)"
cmake -S "${ABACUS_ROOT}" -B "${ABACUS_BUILD_DIR}" \
"${CMAKE_COMPILER_ARGS[@]}" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${ABACUS_INSTALL_PREFIX}" \
"${ABACUS_CMAKE_ARGS[@]}" \
-DBUILD_TESTING=OFF
fi

echo "== Build ABACUS"
cmake --build "${ABACUS_BUILD_DIR}" -j"${NPROC}"

if [[ "${DO_INSTALL}" == "ON" ]]; then
echo "== Install ABACUS"
cmake --install "${ABACUS_BUILD_DIR}"
else
echo "== Skip install (use --install to enable)"
fi

if [[ "${ENABLE_TESTING}" == "ON" ]]; then
echo "== [5/5] List tests"
cd "${ABACUS_BUILD_DIR}"
ctest -N || true
fi

if [[ "${ENABLE_TESTING}" == "ON" ]]; then
echo "Done. ABACUS is configured to use local GTest at: ${GTEST_CMAKE_DIR}"
else
echo "Done. ABACUS is built in original mode without GTest (BUILD_TESTING=OFF)."
fi

Loading