Skip to content

Commit a425984

Browse files
committed
Add example runs to one CI job, minor stdout updates to examples.
1 parent a2b73ab commit a425984

29 files changed

Lines changed: 807 additions & 223 deletions

File tree

.gitlab-ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ stages:
2222
BUILD_OMP: "OFF"
2323
BUILD_CUDA: "OFF"
2424
BUILD_HIP: "OFF"
25+
RUN_EXAMPLES: "OFF"
2526
CONFIG_LOG: "ON"
2627
CXX_FLAGS: ""
2728
EXTRA_CMAKE_FLAGS: ""
@@ -61,6 +62,7 @@ stages:
6162
-DGINKGO_BUILD_OMP=${BUILD_OMP} -DGINKGO_BUILD_CUDA=${BUILD_CUDA}
6263
-DGINKGO_BUILD_HIP=${BUILD_HIP}
6364
-DGINKGO_BUILD_TESTS=ON -DGINKGO_BUILD_EXAMPLES=ON
65+
-DGINKGO_RUN_EXAMPLES=${RUN_EXAMPLES}
6466
-DGINKGO_CONFIG_LOG_DETAILED=${CONFIG_LOG}
6567
- ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT}
6668
dependencies: []
@@ -87,12 +89,18 @@ stages:
8789
-DGINKGO_BUILD_OMP=${BUILD_OMP} -DGINKGO_BUILD_CUDA=${BUILD_CUDA}
8890
-DGINKGO_BUILD_HIP=${BUILD_HIP}
8991
-DGINKGO_BUILD_TESTS=ON -DGINKGO_BUILD_EXAMPLES=ON
92+
-DGINKGO_RUN_EXAMPLES=${RUN_EXAMPLES}
9093
-DGINKGO_CONFIG_LOG_DETAILED=${CONFIG_LOG}
9194
- ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT} install
9295
- |
9396
(( $(ctest -N | tail -1 | sed 's/Total Tests: //') != 0 )) || exit 1
9497
- ctest -V
9598
- ninja test_install
99+
- |
100+
if [ "${RUN_EXAMPLES}" == "ON" ]; then
101+
ninja run_all_examples
102+
ninja validate_all_examples
103+
fi
96104
dependencies: []
97105
except:
98106
- schedules
@@ -122,6 +130,7 @@ sync:
122130

123131

124132
# Build jobs
133+
# Job with example runs.
125134
build/cuda90/gcc/all/debug/shared:
126135
<<: *default_build_with_test
127136
image: localhost:5000/gko-cuda90-gnu5-llvm39
@@ -131,6 +140,7 @@ build/cuda90/gcc/all/debug/shared:
131140
BUILD_CUDA: "ON"
132141
BUILD_HIP: "ON"
133142
BUILD_TYPE: "Debug"
143+
RUN_EXAMPLES: "ON"
134144
CUDA_ARCH: 35
135145
only:
136146
variables:

examples/CMakeLists.txt

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ function(setup_example_target target_name)
77
target_include_directories(${target_name} PRIVATE ${PROJECT_SOURCE_DIR})
88
endfunction()
99

10+
set(EXAMPLES_EXEC_LIST "adaptiveprecision-blockjacobi;custom-logger;ginkgo-overhead;ginkgo-ranges;ilu-preconditioned-solver;ir-ilu-preconditioned-solver;inverse-iteration;iterative-refinement;mixed-precision-ir;nine-pt-stencil-solver;poisson-solver;preconditioned-solver;simple-solver;three-pt-stencil-solver;")
11+
12+
set(EXAMPLES_LIST "${EXAMPLES_EXEC_LIST};custom-matrix-format;custom-stopping-criterion;minimal-cuda-solver;papi-logging;performance-debugging;preconditioner-export;simple-solver-logging")
1013

11-
set(EXAMPLES_LIST "custom-logger;custom-matrix-format;custom-stopping-criterion;adaptiveprecision-blockjacobi;ginkgo-overhead;ginkgo-ranges;ilu-preconditioned-solver;ir-ilu-preconditioned-solver;inverse-iteration;iterative-refinement;minimal-cuda-solver;mixed-precision-ir;nine-pt-stencil-solver;papi-logging;performance-debugging;poisson-solver;preconditioned-solver;preconditioner-export;simple-solver;simple-solver-logging;three-pt-stencil-solver;")
1214
if(GINKGO_BUILD_EXTLIB_EXAMPLE)
1315
set(EXAMPLES_LIST "${EXAMPLES_LIST};external-lib-interfacing")
1416
endif()
@@ -24,4 +26,39 @@ if(GINKGO_RUN_EXAMPLES)
2426
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${example}/${example} > ${CMAKE_CURRENT_BINARY_DIR}/${example}/${example}.out
2527
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
2628
endforeach()
29+
foreach(example ${EXAMPLES_LIST})
30+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${example}/diff-command "#!/bin/bash
31+
diff <(sed -n '7,$p' ${CMAKE_CURRENT_BINARY_DIR}/${example}/${example}.out | sed -E 's/([0-9]+.)//g') <(sed -n '6,$p' ${CMAKE_SOURCE_DIR}/examples/${example}/doc/results.dox | head -n -4 | sed -E 's/([0-9]+.)//g')")
32+
add_custom_target("diff-${example}"
33+
COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/${example}/diff-command && ${CMAKE_CURRENT_BINARY_DIR}/${example}/diff-command
34+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
35+
endforeach()
36+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/run_all_examples.sh
37+
"NUM_EXAMPLES=$(wc -l < example-targets.txt)\n"
38+
"for i in $(seq 1 $NUM_EXAMPLES)\n"
39+
"do\n"
40+
" target_name=$(head -n $i example-targets.txt | tail -1)\n"
41+
" ex_target=run-\$\{target_name\}\n"
42+
" cmake --build ${CMAKE_BINARY_DIR} --target $ex_target\n"
43+
"done\n")
44+
add_custom_target("run_all_examples"
45+
COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/run_all_examples.sh && ${CMAKE_CURRENT_BINARY_DIR}/run_all_examples.sh
46+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
47+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/validate_all_examples.sh
48+
"NUM_EXAMPLES=$(wc -l < example-targets.txt)\n"
49+
"for i in $(seq 1 $NUM_EXAMPLES)\n"
50+
"do\n"
51+
" target_name=$(head -n $i example-targets.txt | tail -1)\n"
52+
" ex_target=diff-\$\{target_name\}\n"
53+
" cmake --build ${CMAKE_BINARY_DIR} --target $ex_target\n"
54+
"done\n")
55+
add_custom_target("validate_all_examples"
56+
COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/validate_all_examples.sh && ${CMAKE_CURRENT_BINARY_DIR}/validate_all_examples.sh
57+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
2758
endif()
59+
60+
set(OUT_FILE "${CMAKE_BINARY_DIR}/examples/example-targets.txt")
61+
file(WRITE ${OUT_FILE} "")
62+
foreach(example ${EXAMPLES_EXEC_LIST})
63+
file(APPEND ${OUT_FILE} "${example}\n")
64+
endforeach()

examples/adaptiveprecision-blockjacobi/adaptiveprecision-blockjacobi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ int main(int argc, char *argv[])
135135
A->apply(lend(one), lend(x), lend(neg_one), lend(b));
136136
b->compute_norm2(lend(res));
137137

138-
std::cout << "Initial residual norm sqrt(r^T r): \n";
138+
std::cout << "Initial residual norm sqrt(r^T r):\n";
139139
write(std::cout, lend(initres));
140-
std::cout << "Final residual norm sqrt(r^T r): \n";
140+
std::cout << "Final residual norm sqrt(r^T r):\n";
141141
write(std::cout, lend(res));
142142

143143
// Print solver statistics

examples/adaptiveprecision-blockjacobi/doc/results.dox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Final residual norm sqrt(r^T r):
1212
1 1
1313
5.69384e-06
1414
CG iteration count: 5
15-
CG execution time [ms]: 2.04779
15+
CG execution time [ms]: 0.080041
1616

1717
@endcode
1818

examples/custom-logger/custom-logger.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ int main(int argc, char *argv[])
232232
gko::HipExecutor::get_num_devices() > 0) {
233233
exec = gko::HipExecutor::create(0, gko::OmpExecutor::create());
234234
} else {
235-
std::cerr << "Usage: " << argv[0] << " [executor]" << std::endl;
235+
std::cerr << "Usage: executable [executor]" << std::endl;
236236
std::exit(-1);
237237
}
238238

@@ -292,7 +292,7 @@ int main(int argc, char *argv[])
292292
solver->apply(gko::lend(b), gko::lend(x));
293293

294294
// Print the solution to the command line.
295-
std::cout << "Solution (x): \n";
295+
std::cout << "Solution (x):\n";
296296
write(std::cout, gko::lend(x));
297297

298298
// Print the table of the residuals obtained from the logger
@@ -311,6 +311,6 @@ int main(int argc, char *argv[])
311311
A->apply(gko::lend(one), gko::lend(x), gko::lend(neg_one), gko::lend(b));
312312
b->compute_norm2(gko::lend(res));
313313

314-
std::cout << "Residual norm sqrt(r^T r): \n";
314+
std::cout << "Residual norm sqrt(r^T r):\n";
315315
write(std::cout, gko::lend(res));
316316
}

examples/custom-matrix-format/custom-matrix-format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ int main(int argc, char *argv[])
242242
using cg = gko::solver::Cg<ValueType>;
243243

244244
if (argc < 2) {
245-
std::cerr << "Usage: " << argv[0] << " DISCRETIZATION_POINTS [executor]"
245+
std::cerr << "Usage: executable DISCRETIZATION_POINTS [executor]"
246246
<< std::endl;
247247
std::exit(-1);
248248
}

examples/custom-stopping-criterion/custom-stopping-criterion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ int main(int argc, char *argv[])
155155
gko::HipExecutor::get_num_devices() > 0) {
156156
exec = gko::HipExecutor::create(0, gko::OmpExecutor::create(), true);
157157
} else {
158-
std::cerr << "Usage: " << argv[0] << " [executor]" << std::endl;
158+
std::cerr << "Usage: executable [executor]" << std::endl;
159159
std::exit(-1);
160160
}
161161

examples/ginkgo-overhead/doc/results.dox

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ This is the expected output:
33

44
@code{.cpp}
55

6-
Running 1000000 iterations of the CG solver took a total of 1.62987 seconds.
7-
Average library overhead: 1629.87 [nanoseconds / iteration]
6+
Running 1000000 iterations of the CG solver took a total of 1.60337 seconds.
7+
Average library overhead: 1603.37 [nanoseconds / iteration]
88

99
@endcode
1010

examples/ginkgo-overhead/ginkgo-overhead.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838
#include <iostream>
3939

4040

41-
[[noreturn]] void print_usage_and_exit(const char *name)
42-
{
41+
[[noreturn]] void print_usage_and_exit(const char *name) {
4342
std::cerr << "Usage: " << name << " [NUM_ITERS]" << std::endl;
4443
std::exit(-1);
4544
}
@@ -56,7 +55,7 @@ int main(int argc, char *argv[])
5655

5756
long unsigned num_iters = 1000000;
5857
if (argc > 2) {
59-
print_usage_and_exit(argv[0]);
58+
print_usage_and_exit("executable");
6059
}
6160
if (argc == 2) {
6261
num_iters = std::atol(argv[1]);

examples/ilu-preconditioned-solver/ilu-preconditioned-solver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
6868
gko::HipExecutor::get_num_devices() > 0) {
6969
exec = gko::HipExecutor::create(0, gko::OmpExecutor::create(), true);
7070
} else {
71-
std::cerr << "Usage: " << argv[0] << " [executor]" << std::endl;
71+
std::cerr << "Usage: executable [executor]" << std::endl;
7272
std::exit(-1);
7373
}
7474

@@ -116,7 +116,7 @@ int main(int argc, char *argv[])
116116
ilu_gmres->apply(gko::lend(b), gko::lend(x));
117117

118118
// Print solution
119-
std::cout << "Solution (x): \n";
119+
std::cout << "Solution (x):\n";
120120
write(std::cout, gko::lend(x));
121121

122122
// Calculate residual
@@ -126,6 +126,6 @@ int main(int argc, char *argv[])
126126
A->apply(gko::lend(one), gko::lend(x), gko::lend(neg_one), gko::lend(b));
127127
b->compute_norm2(gko::lend(res));
128128

129-
std::cout << "Residual norm sqrt(r^T r): \n";
129+
std::cout << "Residual norm sqrt(r^T r):\n";
130130
write(std::cout, gko::lend(res));
131131
}

0 commit comments

Comments
 (0)