diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index d780a62981e875ab76e14393c43c014b6cbaf205..40a45e0d922f2a7c326781f39060a336426b438e 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -16,5 +16,28 @@ add_subdirectory(common) # Adding Benchmarks # ------------------------------------------------------------------------------ -add_subdirectory(micro) +# We only build the following tests when source the is also being built. +if(BUILD_SOURCE) + add_subdirectory(baseline) + add_subdirectory(micro) +endif() +# -------------------------------------------------------------------------------------------------- +# Resolving Dependencies +# -------------------------------------------------------------------------------------------------- +if(PROJECT_FEATURE_CUDA) + target_link_libraries(libbenchzell PUBLIC zell::cuda) +endif() + +if(PROJECT_FEATURE_HIP) + target_link_libraries(libbenchzell PUBLIC zell::hip) +endif() + +if(PROJECT_FEATURE_MPI) + target_link_libraries(libbenchzell PUBLIC zell::mpi) +endif() + +target_link_libraries(libbenchzell PUBLIC zell::cxx) +target_link_libraries(libbenchzell PUBLIC zell::c) + +target_link_libraries(libbenchzell PUBLIC Catch2::Catch2) diff --git a/bench/baseline/CMakeLists.txt b/bench/baseline/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6d5bbb9319ac8a7057a56baee3a97c5231ff1b9a --- /dev/null +++ b/bench/baseline/CMakeLists.txt @@ -0,0 +1,5 @@ +# -------------------------------------------------------------------------------------------------- +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +# -------------------------------------------------------------------------------------------------- +add_subdirectory(cpp) diff --git a/bench/baseline/cpp/CMakeLists.txt b/bench/baseline/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..45cb8c9c7c12032c9159c21f558b5ac088d46cb5 --- /dev/null +++ b/bench/baseline/cpp/CMakeLists.txt @@ -0,0 +1,11 @@ +# -------------------------------------------------------------------------------------------------- +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +# -------------------------------------------------------------------------------------------------- + +add_executable(baseline.compute.b compute.b.cpp) +add_test(baseline.compute.b baseline.compute.b) +set_property(TEST baseline.compute.b PROPERTY LABELS "baseline_bench,production.bench") +target_link_libraries(baseline.compute.b PRIVATE libbenchzell) + + diff --git a/bench/baseline/cpp/compute.b.cpp b/bench/baseline/cpp/compute.b.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2261a270a419f4a210f7b16265566d575ed51bf3 --- /dev/null +++ b/bench/baseline/cpp/compute.b.cpp @@ -0,0 +1,97 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- + +/* + * The objective of this program is to run a program of approximately 4 GFLOP + * and measure the performance of the underlying CPU. + */ + +#include <chrono> +#include <cmath> +#include <cstddef> +#include <cstdint> +#include <iomanip> +#include <iostream> +#include <limits> + +auto main() -> int +{ + // Gather Information about the Clock + using steady_clock_t = std::chrono::steady_clock; + using clock_period_t = steady_clock_t::duration::period; + constexpr long double duration + = static_cast<long double>(clock_period_t::num) / clock_period_t::den; + + std::int64_t const max_iteration = 1'000'000'000; + double x_value[16]; + double y_value[16]; + double z_value[16]; + double w_value[16]; + for (std::int64_t k = 0; k < 16; ++k) { + x_value[k] = 0.7; + y_value[k] = 0.7; + z_value[k] = 0.7; + w_value[k] = 0.7; + } + + auto const single_run_start = steady_clock_t::now(); + for (std::int64_t i = 0; i < max_iteration; ++i) { + for (std::int64_t k = 0; k < 16; ++k) { + x_value[k] = 3.8 * x_value[k] * (1 - x_value[k]); + x_value[k] = 3.8 * x_value[k] * (1 - x_value[k]); + y_value[k] = 3.8 * y_value[k] * (1 - y_value[k]); + y_value[k] = 3.8 * y_value[k] * (1 - y_value[k]); + z_value[k] = 3.8 * z_value[k] * (1 - z_value[k]); + z_value[k] = 3.8 * z_value[k] * (1 - z_value[k]); + w_value[k] = 3.8 * w_value[k] * (1 - w_value[k]); + w_value[k] = 3.8 * w_value[k] * (1 - w_value[k]); + } + } + auto const single_run_end = steady_clock_t::now(); + auto const single_run_delta = (single_run_end - single_run_start); + + auto const double_run_start = steady_clock_t::now(); + for (std::int64_t j = 0; j < 2; ++j) { + for (std::int64_t i = 0; i < max_iteration; ++i) { + for (std::int64_t k = 0; k < 16; ++k) { + x_value[k] = 3.8 * x_value[k] * (1 - x_value[k]); + x_value[k] = 3.8 * x_value[k] * (1 - x_value[k]); + y_value[k] = 3.8 * y_value[k] * (1 - y_value[k]); + y_value[k] = 3.8 * y_value[k] * (1 - y_value[k]); + z_value[k] = 3.8 * z_value[k] * (1 - z_value[k]); + z_value[k] = 3.8 * z_value[k] * (1 - z_value[k]); + w_value[k] = 3.8 * w_value[k] * (1 - w_value[k]); + w_value[k] = 3.8 * w_value[k] * (1 - w_value[k]); + } + } + } + auto const double_run_end = steady_clock_t::now(); + auto const double_run_delta = (double_run_end - double_run_start); + + auto const normalized_run_delta = double_run_delta - single_run_delta; + [[maybe_unused]] auto const speed + = static_cast<long double>(16 * 8 * 4.0) / (normalized_run_delta.count() * duration); + std::cout << "Processor Time = " << (normalized_run_delta.count() * duration) << " s\n"; + std::cout << "Processor Speed = " << speed << " GFLOP/s\n"; + + constexpr auto epsilon = 10 * std::numeric_limits<double>::epsilon(); + if (std::abs(x_value[0] - 0.8305942139168042) > epsilon) { + std::cout << std::setprecision(16) << "Value = " << x_value[0] << "\n"; + return EXIT_FAILURE; + } + if (std::abs(y_value[0] - 0.8305942139168042) > epsilon) { + std::cout << std::setprecision(16) << "Value = " << y_value[0] << "\n"; + return EXIT_FAILURE; + } + if (std::abs(z_value[0] - 0.8305942139168042) > epsilon) { + std::cout << std::setprecision(16) << "Value = " << z_value[0] << "\n"; + return EXIT_FAILURE; + } + if (std::abs(w_value[0] - 0.8305942139168042) > epsilon) { + std::cout << std::setprecision(16) << "Value = " << w_value[0] << "\n"; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/src/cpp/include/mol/bench.hpp b/src/cpp/include/mol/bench.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dce0f5696596967756bca5d2e66613a5a72b640c --- /dev/null +++ b/src/cpp/include/mol/bench.hpp @@ -0,0 +1,11 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- + +#ifndef MOL_BENCH_HPP +#define MOL_BENCH_HPP + +#define MOL_BENCH(name) MOL_DETAIL_BENCH_IMPL(name) + +#endif // MOL_BENCH_HPP