Skip to content

Commit

Permalink
Merge improved benchmark setup
Browse files Browse the repository at this point in the history
Major refactoring of our benchmark code to use nlohmann-json and a shared runner framework to reduce code duplication.
Additionally, this PR also simplifies the output, making it more user-friendly

Related PR: #1323
  • Loading branch information
upsj authored Aug 30, 2023
2 parents 3d39615 + fe3789c commit 1100cbd
Show file tree
Hide file tree
Showing 94 changed files with 2,500 additions and 5,293 deletions.
105 changes: 8 additions & 97 deletions ABOUT-LICENSING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ the following license:
When compiling Ginkgo with `-DGINKGO_BUILD_BENCHMARKS=ON` the build system will
download, build, and link [gflags](https://github.com/gflags/gflags) and
[RapidJSON](https://github.com/Tencent/rapidjson) with the
[nlohmann-json](https://github.com/nlohmann/json) with the
benchmark suites. gtest is available under the following license:

> Copyright (c) 2006, Google Inc.
Expand Down Expand Up @@ -108,110 +108,22 @@ benchmark suites. gtest is available under the following license:
> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
RapidJSON is available under the following license (note that Ginkgo's build
system automatically removes the `bin/jsonchecker/` directory which is licensed
under the problematic JSON license):
nlohmann-json is available under the following license:

> Tencent is pleased to support the open source community by making RapidJSON
> available.
>
> Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
> rights reserved.
>
> If you have downloaded a copy of the RapidJSON binary from Tencent, please
> note that the RapidJSON binary is licensed under the MIT License. If you have
> downloaded a copy of the RapidJSON source code from Tencent, please note that
> RapidJSON source code is licensed under the MIT License, except for the
> third-party components listed below which are subject to different license
> terms. Your integration of RapidJSON into your own projects may require
> compliance with the MIT License, as well as the other licenses applicable to
> the third-party components included within RapidJSON. To avoid the problematic
> JSON license in your own projects, it's sufficient to exclude the
> bin/jsonchecker/ directory, as it's the only code under the JSON license. A
> copy of the MIT License is included in this file.
>
> Other dependencies and licenses:
>
> Open Source Software Licensed Under the BSD License:
> --------------------------------------------------------------------
>
> The msinttypes r29
>
> Copyright (c) 2006-2013 Alexander Chemeris
> All rights reserved.
>
> Redistribution and use in source and binary forms, with or without
> modification, are permitted provided that the following conditions are met:
>
> * Redistributions of source code must retain the above copyright notice, this
> list of conditions and the following disclaimer.
> * Redistributions in binary form must reproduce the above copyright notice,
> this list of conditions and the following disclaimer in the documentation
> and/or other materials provided with the distribution.
> * Neither the name of copyright holder nor the names of its contributors may
> be used to endorse or promote products derived from this software without
> specific prior written permission.
>
> THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
> EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
> WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
> DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
> (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
> LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
> ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>
> Open Source Software Licensed Under the JSON License:
> --------------------------------------------------------------------
>
> json.org
> Copyright (c) 2002
> JSON.org All Rights Reserved.
>
> JSON_checker
> Copyright (c) 2002 JSON.org
> All Rights Reserved.
>
>
> Terms of the JSON License:
> ---------------------------------------------------
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> The Software shall be used for Good, not Evil.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
>
>
> Terms of the MIT License:
> --------------------------------------------------------------------
>
> MIT License
>
> Copyright (c) 2013-2022 Niels Lohmann
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -220,7 +132,6 @@ under the problematic JSON license):
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.

For generating the documentation of Ginkgo, some scripts from the deal.II
library are used. You can refer to the `doc/` folder to see which files are a
modified version of deal.II's documentation generation scripts. Additionally,
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ if(GINKGO_BUILD_TESTS)
endif()
if(GINKGO_BUILD_BENCHMARKS)
find_package(gflags 2.2.2 QUIET)
find_package(RapidJSON 1.1.0 QUIET)
find_package(nlohmann_json 3.9.1 QUIET)
endif()

# System provided, third party libraries (not bundled!)
Expand Down
6 changes: 3 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Ginkgo adds the following additional switches to control what is being built:
* `-DGINKGO_FAST_TESTS={ON, OFF}` reduces the input sizes for a few slow tests
to speed them up, default is `OFF`.
* `-DGINKGO_BUILD_BENCHMARKS={ON, OFF}` builds Ginkgo's benchmarks
(will download gflags and rapidjson), default is `ON`.
(will download gflags and nlohmann-json), default is `ON`.
* `-DGINKGO_BUILD_EXAMPLES={ON, OFF}` builds Ginkgo's examples, default is `ON`
* `-DGINKGO_BUILD_EXTLIB_EXAMPLE={ON, OFF}` builds the interfacing example
with deal.II, default is `OFF`.
Expand Down Expand Up @@ -205,7 +205,7 @@ packages can be turned off by disabling the relevant options.
Test](https://github.com/google/googletest);
+ GINKGO_BUILD_BENCHMARKS=ON: For argument management we use
[gflags](https://github.com/gflags/gflags) and for JSON parsing we use
[RapidJSON](https://github.com/Tencent/rapidjson);
[nlohmann-json](https://github.com/nlohmann/json);
+ GINKGO_DEVEL_TOOLS=ON:
[git-cmake-format](https://github.com/gflegar/git-cmake-format) is our CMake
helper for code formatting.
Expand All @@ -224,7 +224,7 @@ packages can be turned off by disabling the relevant options.
Ginkgo attempts to use pre-installed versions of these package if they match
version requirements using `find_package`. Otherwise, the configuration step
will download the files for each of the packages `GTest`, `gflags`,
`RapidJSON` and `hwloc` and build them internally.
`nlohmann-json` and `hwloc` and build them internally.

Note that, if the external packages were not installed to the default location,
the CMake option `-DCMAKE_PREFIX_PATH=<path-list>` needs to be set to the
Expand Down
8 changes: 4 additions & 4 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ endfunction()


# Generates an executable for one precision. Each executable will be linked to
# `ginkgo`, `gflags` and `rapidjson`.
# `ginkgo`, `gflags` and `nlohmann-json`.
# Note: This should only be used by `ginkgo_add_typed_benchmark_executables`
#
# \param name name for the executable to create (including type suffix)
Expand All @@ -57,7 +57,7 @@ endfunction()
# All remaining arguments will be treated as source files
function(ginkgo_add_single_benchmark_executable name use_lib_linops macro_def type)
add_executable("${name}" ${ARGN})
target_link_libraries("${name}" ginkgo gflags rapidjson)
target_link_libraries("${name}" ginkgo gflags nlohmann_json::nlohmann_json)
# always include the device timer
if (GINKGO_BUILD_CUDA)
target_compile_definitions("${name}" PRIVATE HAS_CUDA_TIMER=1)
Expand Down Expand Up @@ -96,7 +96,7 @@ endfunction(ginkgo_add_single_benchmark_executable)


# Generates an executable for each supported precision. Each executable will be
# linked to `ginkgo`, `gflags` and `rapidjson`.
# linked to `ginkgo`, `gflags` and `nlohmann-json`.
#
# \param name base-name for the executable to create
# \param use_lib_linops Boolean indicating if linking against hipsparse/cusparse
Expand Down Expand Up @@ -149,7 +149,7 @@ if (GINKGO_BUILD_MPI)
endif()

add_subdirectory(blas)
add_subdirectory(conversions)
add_subdirectory(conversion)
add_subdirectory(matrix_generator)
add_subdirectory(matrix_statistics)
add_subdirectory(preconditioner)
Expand Down
21 changes: 6 additions & 15 deletions benchmark/blas/blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,17 @@ Parameters for a benchmark case are:
stride_B: stride for B matrix in gemm (optional, default m)
stride_C: stride for C matrix in gemm (optional, default m)
)";
std::string format = example_config;
std::string format = Generator::get_example_config();
initialize_argument_parsing(&argc, &argv, header, format);

std::string extra_information =
"The operations are " + FLAGS_operations + "\n";
std::string extra_information = "The operations are " + FLAGS_operations;
print_general_information(extra_information);
auto exec = executor_factory.at(FLAGS_executor)(FLAGS_gpu_timer);

rapidjson::IStreamWrapper jcin(get_input_stream());
rapidjson::Document test_cases;
test_cases.ParseStream(jcin);
if (!test_cases.IsArray()) {
std::cerr
<< "Input has to be a JSON array of benchmark configurations:\n"
<< format;
std::exit(1);
}
auto test_cases = json::parse(get_input_stream());

run_blas_benchmarks(exec, get_timer(exec, FLAGS_gpu_timer), operation_map,
test_cases, true);
run_test_cases(BlasBenchmark{operation_map}, exec,
get_timer(exec, FLAGS_gpu_timer), test_cases);

std::cout << test_cases << std::endl;
std::cout << std::setw(4) << test_cases << std::endl;
}
Loading

0 comments on commit 1100cbd

Please sign in to comment.