Skip to content

Commit

Permalink
add test framework for benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Jul 19, 2023
1 parent dcffc1a commit 280ba1f
Show file tree
Hide file tree
Showing 63 changed files with 5,458 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ compile_commands.json
CTestTestfile.cmake
build

### Python
__pycache__

### IDE
# Clion
.idea
Expand Down
3 changes: 3 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ add_subdirectory(solver)
add_subdirectory(sparse_blas)
add_subdirectory(spmv)
add_subdirectory(tools)
if (GINKGO_BUILD_TESTS)
add_subdirectory(test)
endif()

configure_file(run_all_benchmarks.sh run_all_benchmarks.sh COPYONLY)

Expand Down
2 changes: 1 addition & 1 deletion benchmark/blas/distributed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ginkgo_add_typed_benchmark_executables(multi-vector-distributed "NO" multi_vector.cpp)
ginkgo_add_typed_benchmark_executables(multi_vector_distributed "NO" multi_vector.cpp)
2 changes: 1 addition & 1 deletion benchmark/conversions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ginkgo_add_typed_benchmark_executables(conversions "NO" conversions.cpp)
ginkgo_add_typed_benchmark_executables(conversion "NO" conversions.cpp)
2 changes: 1 addition & 1 deletion benchmark/solver/distributed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ginkgo_add_typed_benchmark_executables(solver-distributed "YES" solver.cpp)
ginkgo_add_typed_benchmark_executables(solver_distributed "YES" solver.cpp)
2 changes: 1 addition & 1 deletion benchmark/spmv/distributed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ginkgo_add_typed_benchmark_executables(spmv-distributed "YES" spmv.cpp)
ginkgo_add_typed_benchmark_executables(spmv_distributed "YES" spmv.cpp)
28 changes: 28 additions & 0 deletions benchmark/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
find_package(Python3 COMPONENTS Interpreter REQUIRED)
function(add_benchmark_test test_name)
configure_file(${test_name}.py ${test_name}.py COPYONLY)
add_test(NAME benchmark_${test_name}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/${test_name}.py
WORKING_DIRECTORY "$<TARGET_FILE_DIR:ginkgo>")
set(regenerate_target benchmark_test_${test_name}_regenerate)
add_custom_target(${regenerate_target}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/${test_name}.py --generate
COMMENT "Regenerating reference output for ${test_name}"
WORKING_DIRECTORY "$<TARGET_FILE_DIR:ginkgo>")
add_dependencies(${regenerate_target} ${test_name})
add_dependencies(benchmark_test_regenerate ${regenerate_target})
endfunction()
add_custom_target(benchmark_test_regenerate)
configure_file(test_framework.py.in test_framework.py @ONLY)
add_benchmark_test(blas)
add_benchmark_test(conversion)
add_benchmark_test(matrix_statistics)
add_benchmark_test(preconditioner)
add_benchmark_test(solver)
add_benchmark_test(sparse_blas)
add_benchmark_test(spmv)
if (GINKGO_BUILD_MPI)
add_benchmark_test(multi_vector_distributed)
add_benchmark_test(spmv_distributed)
add_benchmark_test(solver_distributed)
endif()
25 changes: 25 additions & 0 deletions benchmark/test/blas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
import test_framework
# check that all input modes work:
# parameter
test_framework.compare_output(["blas/blas", "-input", '[{"n": 100}]'],
expected_stdout="blas.simple.stdout",
expected_stderr="blas.simple.stderr")

# stdin
test_framework.compare_output(["blas/blas"],
expected_stdout="blas.simple.stdout",
expected_stderr="blas.simple.stderr",
stdin='[{"n": 100}]')

# file
test_framework.compare_output(["blas/blas", "-input", str(test_framework.sourcepath / "input.blas.json")],
expected_stdout="blas.simple.stdout",
expected_stderr="blas.simple.stderr",
stdin='[{"n": 100}]')

# profiler annotations
test_framework.compare_output(["blas/blas", "-input", '[{"n": 100}]', '-profile', '-profiler_hook', 'debug'],
expected_stdout="blas.profile.stdout",
expected_stderr="blas.profile.stderr",
stdin='[{"n": 100}]')
28 changes: 28 additions & 0 deletions benchmark/test/conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
import test_framework
# check that all input modes work:
# parameter
test_framework.compare_output(["conversion/conversion", "-input", '[{"size": 100, "stencil": "7pt"}]', "-formats", "coo,csr"],
expected_stdout="conversion.simple.stdout",
expected_stderr="conversion.simple.stderr")

# stdin
test_framework.compare_output(["conversion/conversion", "-formats", "coo,csr"],
expected_stdout="conversion.simple.stdout",
expected_stderr="conversion.simple.stderr",
stdin='[{"size": 100, "stencil": "7pt"}]')

# input file
test_framework.compare_output(["conversion/conversion", "-input", str(test_framework.sourcepath / "input.mtx.json"), "-formats", "coo,csr"],
expected_stdout="conversion.simple.stdout",
expected_stderr="conversion.simple.stderr")

# check that all conversions work
test_framework.compare_output(["conversion/conversion", "-input", '[{"size": 100, "stencil": "7pt"}]', "-formats", "coo,csr,ell,sellp,hybrid"],
expected_stdout="conversion.all.stdout",
expected_stderr="conversion.all.stderr")

# profiler annotations
test_framework.compare_output(["conversion/conversion", "-input", '[{"size": 100, "stencil": "7pt"}]', "-formats", "coo,csr", '-profile', '-profiler_hook', 'debug'],
expected_stdout="conversion.profile.stdout",
expected_stderr="conversion.profile.stderr")
5 changes: 5 additions & 0 deletions benchmark/test/input.blas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"n": 100
}
]
7 changes: 7 additions & 0 deletions benchmark/test/input.distributed_mtx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"size": 100,
"stencil": "7pt",
"comm_pattern": "stencil"
}
]
10 changes: 10 additions & 0 deletions benchmark/test/input.distributed_solver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"size": 100,
"stencil": "7pt",
"comm_pattern": "stencil",
"optimal": {
"spmv": "csr-csr"
}
}
]
6 changes: 6 additions & 0 deletions benchmark/test/input.mtx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"size": 100,
"stencil": "7pt"
}
]
9 changes: 9 additions & 0 deletions benchmark/test/input.solver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"size": 100,
"stencil": "7pt",
"optimal": {
"spmv": "csr"
}
}
]
18 changes: 18 additions & 0 deletions benchmark/test/matrix_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
import test_framework
# check that all input modes work:
# parameter
test_framework.compare_output(["matrix_statistics/matrix_statistics", "-input", '[{"size": 100, "stencil": "7pt"}]'],
expected_stdout="matrix_statistics.simple.stdout",
expected_stderr="matrix_statistics.simple.stderr")

# stdin
test_framework.compare_output(["matrix_statistics/matrix_statistics"],
expected_stdout="matrix_statistics.simple.stdout",
expected_stderr="matrix_statistics.simple.stderr",
stdin='[{"size": 100, "stencil": "7pt"}]')

# input file
test_framework.compare_output(["matrix_statistics/matrix_statistics", "-input", '[{"size": 100, "stencil": "7pt"}]'],
expected_stdout="matrix_statistics.simple.stdout",
expected_stderr="matrix_statistics.simple.stderr")
30 changes: 30 additions & 0 deletions benchmark/test/multi_vector_distributed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
import test_framework
base_flags = ["blas/distributed/multi_vector_distributed"]
# check that all input modes work:
# parameter
test_framework.compare_output_distributed(base_flags + ["-input", '[{"n": 100}]'],
expected_stdout="multi_vector_distributed.simple.stdout",
expected_stderr="multi_vector_distributed.simple.stderr",
num_procs=3)

# stdin
test_framework.compare_output_distributed(base_flags,
expected_stdout="multi_vector_distributed.simple.stdout",
expected_stderr="multi_vector_distributed.simple.stderr",
stdin='[{"n": 100}]',
num_procs=3)

# file
test_framework.compare_output_distributed(base_flags + ["-input", str(test_framework.sourcepath / "input.blas.json")],
expected_stdout="multi_vector_distributed.simple.stdout",
expected_stderr="multi_vector_distributed.simple.stderr",
stdin='[{"n": 100}]',
num_procs=3)

# profiler annotations
test_framework.compare_output_distributed(base_flags + ["-input", '[{"n": 100}]', '-profile', '-profiler_hook', 'debug'],
expected_stdout="multi_vector_distributed.profile.stdout",
expected_stderr="multi_vector_distributed.profile.stderr",
stdin='[{"n": 100}]',
num_procs=3)
23 changes: 23 additions & 0 deletions benchmark/test/preconditioner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
import test_framework
# check that all input modes work:
# parameter
test_framework.compare_output(["preconditioner/preconditioner", "-input", '[{"size": 100, "stencil": "7pt"}]'],
expected_stdout="preconditioner.simple.stdout",
expected_stderr="preconditioner.simple.stderr")

# stdin
test_framework.compare_output(["preconditioner/preconditioner"],
expected_stdout="preconditioner.simple.stdout",
expected_stderr="preconditioner.simple.stderr",
stdin='[{"size": 100, "stencil": "7pt"}]')

# input file
test_framework.compare_output(["preconditioner/preconditioner", "-input", str(test_framework.sourcepath / "input.mtx.json")],
expected_stdout="preconditioner.simple.stdout",
expected_stderr="preconditioner.simple.stderr")

# profiler annotations
test_framework.compare_output(["preconditioner/preconditioner", "-input", '[{"size": 100, "stencil": "7pt"}]', '-profile', '-profiler_hook', 'debug'],
expected_stdout="preconditioner.profile.stdout",
expected_stderr="preconditioner.profile.stderr")
130 changes: 130 additions & 0 deletions benchmark/test/reference/blas.profile.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
This is Ginkgo 1.5.0 (develop)
running with core module 1.5.0 (develop)
Running on reference(0)
Running with 0 warm iterations and 1 running iterations
The random seed for right hand sides is 42
The operations are copy,axpy,scalRunning test case
{
"n": 100,
"blas": {}
}
DEBUG: begin n = 100
DEBUG: begin copy
DEBUG: begin allocate
DEBUG: end allocate
DEBUG: begin allocate
DEBUG: end allocate
DEBUG: begin dense::fill
DEBUG: end dense::fill
DEBUG: begin dense::copy
DEBUG: end dense::copy
DEBUG: begin free
DEBUG: end free
DEBUG: begin free
DEBUG: end free
DEBUG: end copy
Current state:
[
{
"n": 100,
"blas": {
"copy": {
"time": 1.0,
"flops": 1.0,
"bandwidth": 1.0,
"repetitions": 1,
"completed": true
}
}
}
]
DEBUG: begin axpy
DEBUG: begin allocate
DEBUG: end allocate
DEBUG: begin allocate
DEBUG: end allocate
DEBUG: begin allocate
DEBUG: end allocate
DEBUG: begin dense::fill
DEBUG: end dense::fill
DEBUG: begin dense::fill
DEBUG: end dense::fill
DEBUG: begin dense::fill
DEBUG: end dense::fill
DEBUG: begin dense::add_scaled
DEBUG: end dense::add_scaled
DEBUG: begin free
DEBUG: end free
DEBUG: begin free
DEBUG: end free
DEBUG: begin free
DEBUG: end free
DEBUG: end axpy
Current state:
[
{
"n": 100,
"blas": {
"copy": {
"time": 1.0,
"flops": 1.0,
"bandwidth": 1.0,
"repetitions": 1,
"completed": true
},
"axpy": {
"time": 1.0,
"flops": 1.0,
"bandwidth": 1.0,
"repetitions": 1,
"completed": true
}
}
}
]
DEBUG: begin scal
DEBUG: begin allocate
DEBUG: end allocate
DEBUG: begin allocate
DEBUG: end allocate
DEBUG: begin dense::fill
DEBUG: end dense::fill
DEBUG: begin dense::fill
DEBUG: end dense::fill
DEBUG: begin dense::scale
DEBUG: end dense::scale
DEBUG: begin free
DEBUG: end free
DEBUG: begin free
DEBUG: end free
DEBUG: end scal
Current state:
[
{
"n": 100,
"blas": {
"copy": {
"time": 1.0,
"flops": 1.0,
"bandwidth": 1.0,
"repetitions": 1,
"completed": true
},
"axpy": {
"time": 1.0,
"flops": 1.0,
"bandwidth": 1.0,
"repetitions": 1,
"completed": true
},
"scal": {
"time": 1.0,
"flops": 1.0,
"bandwidth": 1.0,
"repetitions": 1,
"completed": true
}
}
}
]
DEBUG: end n = 100
29 changes: 29 additions & 0 deletions benchmark/test/reference/blas.profile.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

[
{
"n": 100,
"blas": {
"copy": {
"time": 1.0,
"flops": 1.0,
"bandwidth": 1.0,
"repetitions": 1,
"completed": true
},
"axpy": {
"time": 1.0,
"flops": 1.0,
"bandwidth": 1.0,
"repetitions": 1,
"completed": true
},
"scal": {
"time": 1.0,
"flops": 1.0,
"bandwidth": 1.0,
"repetitions": 1,
"completed": true
}
}
}
]
Loading

0 comments on commit 280ba1f

Please sign in to comment.