forked from flagos-ai/FlagCX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_unit_test.sh
More file actions
173 lines (152 loc) · 5.47 KB
/
Copy pathrun_unit_test.sh
File metadata and controls
173 lines (152 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <set-env-script> <suite>" >&2
exit 2
fi
SET_ENV_SCRIPT=$1
SUITE=$2
PROJECT_ROOT=${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)}
if [[ ! -f "$SET_ENV_SCRIPT" ]]; then
echo "Platform environment script not found: $SET_ENV_SCRIPT" >&2
exit 1
fi
# The platform script owns accelerator-specific compiler flags and device
# topology. It is sourced (rather than executed) so it can provide arrays and
# hook functions without unsafe string evaluation.
# shellcheck source=/dev/null
source "$SET_ENV_SCRIPT"
if declare -F flagcx_ci_configure_suite >/dev/null; then
flagcx_ci_configure_suite "$SUITE"
fi
: "${MPI_HOME:?The platform set_env script must define MPI_HOME}"
declare -p FLAGCX_CI_PROJECT_MAKE_ARGS >/dev/null 2>&1 || {
echo "The platform set_env script must define FLAGCX_CI_PROJECT_MAKE_ARGS" >&2
exit 1
}
declare -p FLAGCX_CI_TEST_MAKE_ARGS >/dev/null 2>&1 || {
echo "The platform set_env script must define FLAGCX_CI_TEST_MAKE_ARGS" >&2
exit 1
}
export PATH="$MPI_HOME/bin:$PATH"
export LD_LIBRARY_PATH="$PROJECT_ROOT/build/lib:${LD_LIBRARY_PATH:-}"
if declare -F flagcx_ci_prepare >/dev/null; then
flagcx_ci_prepare "$SUITE"
fi
build_googletest() {
cmake -S "$PROJECT_ROOT/third-party/googletest" \
-B "$PROJECT_ROOT/third-party/googletest/build"
cmake --build "$PROJECT_ROOT/third-party/googletest/build" --parallel "$(nproc)"
}
build_project() {
local -a args=("${FLAGCX_CI_PROJECT_MAKE_ARGS[@]}")
make -C "$PROJECT_ROOT" --jobs="$(nproc)" "${args[@]}"
}
build_suite() {
local suite_dir="$PROJECT_ROOT/test/unittest/$SUITE"
local -a args=("${FLAGCX_CI_TEST_MAKE_ARGS[@]}")
make -C "$suite_dir" --jobs="$(nproc)" "${args[@]}"
}
run_device_api() {
local suite_dir="$PROJECT_ROOT/test/unittest/device_api"
local -a common_env=(
-x FLAGCX_USE_HETERO_COMM=1
-x FLAGCX_MEM_ENABLE=1
-x FLAGCX_VMM_ENABLE=0
-x FLAGCX_P2P_DISABLE=1
-x LD_LIBRARY_PATH
)
local -a flags=(-b 1M -e 4M -f 2 -R 1)
declare -p FLAGCX_CI_NODE1_MPI_ARGS >/dev/null 2>&1 || {
echo "The platform set_env script must define FLAGCX_CI_NODE1_MPI_ARGS" >&2
exit 1
}
declare -p FLAGCX_CI_NODE2_MPI_ARGS >/dev/null 2>&1 || {
echo "The platform set_env script must define FLAGCX_CI_NODE2_MPI_ARGS" >&2
exit 1
}
: "${FLAGCX_CI_INTRA_NP:?The platform set_env script must define FLAGCX_CI_INTRA_NP}"
: "${FLAGCX_CI_NODE_NP:?The platform set_env script must define FLAGCX_CI_NODE_NP}"
cd "$suite_dir"
mpirun -np "$FLAGCX_CI_INTRA_NP" --allow-run-as-root "${common_env[@]}" \
build/bin/test_device_api_intra "${flags[@]}"
mpirun -np "$FLAGCX_CI_INTRA_NP" --allow-run-as-root "${common_env[@]}" \
build/bin/test_device_ir_intra "${flags[@]}"
mpirun --allow-run-as-root \
-np "$FLAGCX_CI_NODE_NP" "${common_env[@]}" "${FLAGCX_CI_NODE1_MPI_ARGS[@]}" \
build/bin/test_device_api_inter "${flags[@]}" \
: -np "$FLAGCX_CI_NODE_NP" "${common_env[@]}" "${FLAGCX_CI_NODE2_MPI_ARGS[@]}" \
build/bin/test_device_api_inter "${flags[@]}"
mpirun --allow-run-as-root \
-np "$FLAGCX_CI_NODE_NP" "${common_env[@]}" "${FLAGCX_CI_NODE1_MPI_ARGS[@]}" \
build/bin/test_device_ir_inter "${flags[@]}" \
: -np "$FLAGCX_CI_NODE_NP" "${common_env[@]}" "${FLAGCX_CI_NODE2_MPI_ARGS[@]}" \
build/bin/test_device_ir_inter "${flags[@]}"
# Unified IR tests (INTRA + WORLD teams, INTER + WORLD teams)
# Intra test: single-node, 8 ranks
mpirun -np "$FLAGCX_CI_INTRA_NP" --allow-run-as-root "${common_env[@]}" \
build/bin/test_device_ir_unified_intra "${flags[@]}"
# Inter test: multi-node simulation, 8 ranks split into 2 nodes
mpirun --allow-run-as-root \
-np "$FLAGCX_CI_NODE_NP" "${common_env[@]}" "${FLAGCX_CI_NODE1_MPI_ARGS[@]}" \
build/bin/test_device_ir_unified_inter "${flags[@]}" \
: -np "$FLAGCX_CI_NODE_NP" "${common_env[@]}" "${FLAGCX_CI_NODE2_MPI_ARGS[@]}" \
build/bin/test_device_ir_unified_inter "${flags[@]}"
}
run_suite() {
local suite_dir="$PROJECT_ROOT/test/unittest/$SUITE"
local -a args=("${FLAGCX_CI_TEST_MAKE_ARGS[@]}")
case "$SUITE" in
adaptor|core|service)
make -C "$suite_dir" run-unit "${args[@]}"
;;
p2p)
FLAGCX_USE_HETERO_COMM=1 FLAGCX_MEM_ENABLE=1 FLAGCX_VMM_ENABLE=0 \
make -C "$suite_dir" run-unit "${args[@]}"
;;
rma)
make -C "$suite_dir" run-mpi "${args[@]}"
;;
runner)
: "${FLAGCX_CI_RUNNER_NP:?The platform set_env script must define FLAGCX_CI_RUNNER_NP}"
make -C "$suite_dir" run-unit "${args[@]}"
cd "$suite_dir"
mpirun -np "$FLAGCX_CI_RUNNER_NP" --allow-run-as-root \
./build/bin/runner_mpi_tests
mpirun -np "$FLAGCX_CI_RUNNER_NP" --allow-run-as-root \
-x FLAGCX_MEM_ENABLE=1 \
-x FLAGCX_CLUSTER_SPLIT_LIST=2 \
./build/bin/runner_mpi_tests
mpirun -np "$FLAGCX_CI_RUNNER_NP" --allow-run-as-root \
-x FLAGCX_MEM_ENABLE=1 \
-x FLAGCX_CLUSTER_SPLIT_LIST=2 \
-x FLAGCX_P2P_DISABLE=1 \
-x FLAGCX_VMM_ENABLE=0 \
./build/bin/runner_mpi_tests
;;
symmem)
bash "$PROJECT_ROOT/test/script/symmem_test.sh"
;;
device_api)
run_device_api
;;
*)
echo "Unsupported unit test suite: $SUITE" >&2
exit 2
;;
esac
}
case "$SUITE" in
device_api|symmem)
;;
adaptor|core|p2p|rma|runner|service)
build_googletest
;;
*)
echo "Unsupported unit test suite: $SUITE" >&2
exit 2
;;
esac
build_project
build_suite
run_suite