-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_scale_axpy.sh
More file actions
executable file
·344 lines (304 loc) · 12.1 KB
/
test_scale_axpy.sh
File metadata and controls
executable file
·344 lines (304 loc) · 12.1 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/bin/bash
# Test script for scale, axpy, rtriad, and sum kernels
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="${SCRIPT_DIR}/build"
BIN_DIR="${BUILD_DIR}/bin"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
passed=0
failed=0
print_result() {
if [ $1 -eq 0 ]; then
echo -e "${GREEN}[PASS]${NC} $2"
((passed++))
else
echo -e "${RED}[FAIL]${NC} $2"
((failed++))
fi
}
print_header() {
echo ""
echo "=========================================="
echo "$1"
echo "=========================================="
}
# Check if build directory exists
if [ ! -d "$BUILD_DIR" ]; then
echo "Build directory not found. Building..."
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake ..
make -j$(nproc)
cd "$SCRIPT_DIR"
fi
if [ ! -f "$BIN_DIR/tpbcli" ]; then
echo "Error: tpbcli not found in $BIN_DIR"
exit 1
fi
print_header "TPBench Scale/AXPY Kernel Tests"
# ==============================================================================
# Test Scale Kernel (OpenMP)
# ==============================================================================
print_header "Scale Kernel Tests (OpenMP)"
# Test 1: Scale kernel basic run
echo "Test 1: Scale kernel basic run with default params"
output=$("$BIN_DIR/tpbcli" run --kernel scale --kargs ntest=5,total_memsize=64 2>&1) || true
if echo "$output" | grep -q "scale error"; then
print_result 0 "Scale kernel ran successfully"
else
print_result 1 "Scale kernel failed to run"
echo "$output"
fi
# Test 2: Scale kernel with array_size parameter
echo "Test 2: Scale kernel with array_size parameter"
output=$("$BIN_DIR/tpbcli" run --kernel scale --kargs ntest=3,array_size=1024 2>&1) || true
if echo "$output" | grep -q "scale error"; then
print_result 0 "Scale kernel with array_size ran successfully"
else
print_result 1 "Scale kernel with array_size failed"
echo "$output"
fi
# Test 3: Scale PLI executable
echo "Test 3: Scale PLI executable (.tpbx)"
if [ -f "$BIN_DIR/tpbk_scale.tpbx" ]; then
output=$("$BIN_DIR/tpbk_scale.tpbx" clock_gettime ntest=3 total_memsize=32 2>&1) || true
if echo "$output" | grep -q "scale"; then
print_result 0 "Scale PLI executable ran successfully"
else
print_result 1 "Scale PLI executable failed"
echo "$output"
fi
else
print_result 1 "Scale PLI executable not found"
fi
# ==============================================================================
# Test AXPY Kernel (OpenMP)
# ==============================================================================
print_header "AXPY Kernel Tests (OpenMP)"
# Test 4: AXPY kernel basic run
echo "Test 4: AXPY kernel basic run with default params"
output=$("$BIN_DIR/tpbcli" run --kernel axpy --kargs ntest=5,total_memsize=64 2>&1) || true
if echo "$output" | grep -q "axpy error"; then
print_result 0 "AXPY kernel ran successfully"
else
print_result 1 "AXPY kernel failed to run"
echo "$output"
fi
# Test 5: AXPY kernel with array_size parameter
echo "Test 5: AXPY kernel with array_size parameter"
output=$("$BIN_DIR/tpbcli" run --kernel axpy --kargs ntest=3,array_size=1024 2>&1) || true
if echo "$output" | grep -q "axpy error"; then
print_result 0 "AXPY kernel with array_size ran successfully"
else
print_result 1 "AXPY kernel with array_size failed"
echo "$output"
fi
# Test 6: AXPY PLI executable
echo "Test 6: AXPY PLI executable (.tpbx)"
if [ -f "$BIN_DIR/tpbk_axpy.tpbx" ]; then
output=$("$BIN_DIR/tpbk_axpy.tpbx" clock_gettime ntest=3 total_memsize=32 2>&1) || true
if echo "$output" | grep -q "axpy"; then
print_result 0 "AXPY PLI executable ran successfully"
else
print_result 1 "AXPY PLI executable failed"
echo "$output"
fi
else
print_result 1 "AXPY PLI executable not found"
fi
# ==============================================================================
# Test Verification (Error Check)
# ==============================================================================
print_header "Verification Tests"
# Test 7: Scale kernel verification (error should be small)
echo "Test 7: Scale kernel result verification"
output=$("$BIN_DIR/tpbcli" run --kernel scale --kargs ntest=10,total_memsize=128 2>&1) || true
error=$(echo "$output" | grep "scale error" | awk '{print $NF}')
if [ -n "$error" ]; then
# Check if error is less than 1e-6 (using bc for floating point comparison)
if echo "$error < 1e-6" | bc -l 2>/dev/null | grep -q "1"; then
print_result 0 "Scale verification passed (error=$error)"
else
# For zero error, bc might fail
if [ "$error" = "0.000000" ] || [ "$error" = "0" ]; then
print_result 0 "Scale verification passed (error=$error)"
else
print_result 1 "Scale verification failed (error=$error)"
fi
fi
else
print_result 1 "Could not extract error value"
fi
# Test 8: AXPY kernel verification (error should be small)
echo "Test 8: AXPY kernel result verification"
output=$("$BIN_DIR/tpbcli" run --kernel axpy --kargs ntest=10,total_memsize=128 2>&1) || true
error=$(echo "$output" | grep "axpy error" | awk '{print $NF}')
if [ -n "$error" ]; then
if echo "$error < 1e-6" | bc -l 2>/dev/null | grep -q "1"; then
print_result 0 "AXPY verification passed (error=$error)"
else
if [ "$error" = "0.000000" ] || [ "$error" = "0" ]; then
print_result 0 "AXPY verification passed (error=$error)"
else
print_result 1 "AXPY verification failed (error=$error)"
fi
fi
else
print_result 1 "Could not extract error value"
fi
# ==============================================================================
# Test Repeat Triad Kernel (OpenMP)
# ==============================================================================
print_header "Repeat Triad Kernel Tests (OpenMP)"
# Test: Rtriad kernel basic run
echo "Test: Rtriad kernel basic run with default params"
output=$("$BIN_DIR/tpbcli" run --kernel rtriad --kargs ntest=3,total_memsize=64 2>&1) || true
if echo "$output" | grep -q "rtriad error"; then
print_result 0 "Rtriad kernel ran successfully"
else
print_result 1 "Rtriad kernel failed to run"
echo "$output"
fi
# Test: Rtriad kernel with repeat parameter
echo "Test: Rtriad kernel with repeat parameter"
output=$("$BIN_DIR/tpbcli" run --kernel rtriad --kargs ntest=3,total_memsize=64,repeat=10 2>&1) || true
if echo "$output" | grep -q "rtriad error"; then
print_result 0 "Rtriad kernel with repeat ran successfully"
else
print_result 1 "Rtriad kernel with repeat failed"
echo "$output"
fi
# ==============================================================================
# Test Sum Kernel (OpenMP)
# ==============================================================================
print_header "Sum Kernel Tests (OpenMP)"
# Test: Sum kernel basic run
echo "Test: Sum kernel basic run with default params"
output=$("$BIN_DIR/tpbcli" run --kernel sum --kargs ntest=3,total_memsize=64 2>&1) || true
if echo "$output" | grep -q "sum error"; then
print_result 0 "Sum kernel ran successfully"
else
print_result 1 "Sum kernel failed to run"
echo "$output"
fi
# Test: Sum kernel verification
echo "Test: Sum kernel result verification"
output=$("$BIN_DIR/tpbcli" run --kernel sum --kargs ntest=5,total_memsize=32 2>&1) || true
error=$(echo "$output" | grep "sum error" | awk '{print $NF}')
if [ -n "$error" ]; then
print_result 0 "Sum verification passed (relative error=$error)"
else
print_result 1 "Could not extract error value"
fi
# ==============================================================================
# Test MPI Kernels (if MPI is available)
# ==============================================================================
if [ -f "$BIN_DIR/tpbk_scale_mpi.tpbx" ] && command -v mpirun &> /dev/null; then
print_header "Scale MPI Kernel Tests"
# Test 9: Scale MPI kernel with 2 ranks
echo "Test 9: Scale MPI kernel with 2 ranks"
output=$(mpirun -np 2 "$BIN_DIR/tpbk_scale_mpi.tpbx" clock_gettime ntest=3 total_memsize=64 2>&1) || true
if echo "$output" | grep -q "scale_mpi max error"; then
print_result 0 "Scale MPI kernel ran successfully"
else
print_result 1 "Scale MPI kernel failed"
echo "$output"
fi
# Test 10: Scale MPI kernel with 4 ranks
echo "Test 10: Scale MPI kernel with 4 ranks"
output=$(mpirun -np 4 "$BIN_DIR/tpbk_scale_mpi.tpbx" clock_gettime ntest=3 total_memsize=128 2>&1) || true
if echo "$output" | grep -q "scale_mpi max error"; then
print_result 0 "Scale MPI kernel with 4 ranks ran successfully"
else
print_result 1 "Scale MPI kernel with 4 ranks failed"
echo "$output"
fi
else
echo ""
echo -e "${YELLOW}[SKIP]${NC} Scale MPI tests - MPI not available or kernel not built"
fi
if [ -f "$BIN_DIR/tpbk_axpy_mpi.tpbx" ] && command -v mpirun &> /dev/null; then
print_header "AXPY MPI Kernel Tests"
# Test: AXPY MPI kernel with 2 ranks
echo "Test: AXPY MPI kernel with 2 ranks"
output=$(mpirun -np 2 "$BIN_DIR/tpbk_axpy_mpi.tpbx" clock_gettime ntest=3 total_memsize=64 2>&1) || true
if echo "$output" | grep -q "axpy_mpi max error"; then
print_result 0 "AXPY MPI kernel ran successfully"
else
print_result 1 "AXPY MPI kernel failed"
echo "$output"
fi
else
echo ""
echo -e "${YELLOW}[SKIP]${NC} AXPY MPI tests - MPI not available or kernel not built"
fi
if [ -f "$BIN_DIR/tpbk_rtriad_mpi.tpbx" ] && command -v mpirun &> /dev/null; then
print_header "Repeat Triad MPI Kernel Tests"
echo "Test: Rtriad MPI kernel with 2 ranks"
output=$(mpirun -np 2 "$BIN_DIR/tpbk_rtriad_mpi.tpbx" clock_gettime ntest=3 total_memsize=64 2>&1) || true
if echo "$output" | grep -q "rtriad_mpi max error"; then
print_result 0 "Rtriad MPI kernel ran successfully"
else
print_result 1 "Rtriad MPI kernel failed"
echo "$output"
fi
else
echo ""
echo -e "${YELLOW}[SKIP]${NC} Rtriad MPI tests - MPI not available or kernel not built"
fi
if [ -f "$BIN_DIR/tpbk_sum_mpi.tpbx" ] && command -v mpirun &> /dev/null; then
print_header "Sum MPI Kernel Tests"
echo "Test: Sum MPI kernel with 2 ranks"
output=$(mpirun -np 2 "$BIN_DIR/tpbk_sum_mpi.tpbx" clock_gettime ntest=3 total_memsize=64 2>&1) || true
if echo "$output" | grep -q "sum_mpi"; then
print_result 0 "Sum MPI kernel ran successfully"
else
print_result 1 "Sum MPI kernel failed"
echo "$output"
fi
else
echo ""
echo -e "${YELLOW}[SKIP]${NC} Sum MPI tests - MPI not available or kernel not built"
fi
# ==============================================================================
# Test with tpbcli run using --kmpiargs (if MPI kernels are registered)
# ==============================================================================
if [ -f "$BIN_DIR/tpbk_scale_mpi.tpbx" ] && command -v mpirun &> /dev/null; then
print_header "tpbcli MPI Integration Tests"
# Test 13: Scale MPI via tpbcli
echo "Test 13: Scale MPI via tpbcli run"
output=$("$BIN_DIR/tpbcli" run --kernel scale_mpi --kargs ntest=3,total_memsize=64 --kmpiargs '-np 2' 2>&1) || true
if echo "$output" | grep -q "scale_mpi"; then
print_result 0 "Scale MPI via tpbcli ran successfully"
else
print_result 1 "Scale MPI via tpbcli failed"
echo "$output"
fi
# Test 14: AXPY MPI via tpbcli
echo "Test 14: AXPY MPI via tpbcli run"
output=$("$BIN_DIR/tpbcli" run --kernel axpy_mpi --kargs ntest=3,total_memsize=64 --kmpiargs '-np 2' 2>&1) || true
if echo "$output" | grep -q "axpy_mpi"; then
print_result 0 "AXPY MPI via tpbcli ran successfully"
else
print_result 1 "AXPY MPI via tpbcli failed"
echo "$output"
fi
fi
# ==============================================================================
# Summary
# ==============================================================================
print_header "Test Summary"
total=$((passed + failed))
echo "Passed: $passed / $total"
echo "Failed: $failed / $total"
if [ $failed -gt 0 ]; then
echo -e "${RED}Some tests failed!${NC}"
exit 1
else
echo -e "${GREEN}All tests passed!${NC}"
exit 0
fi