Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuichi Asahi committed Jan 31, 2024
1 parent f312ba4 commit 928fd3d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 107 deletions.
195 changes: 99 additions & 96 deletions fft/perf_test/Benchmark_Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,111 +11,114 @@
#include <KokkosFFT_Version_Info.hpp>

namespace KokkosFFTBenchmark {
/// \brief Remove unwanted spaces and colon signs from input string. In case of
/// invalid input it will return an empty string.
inline std::string remove_unwanted_characters(std::string str) {
auto from = str.find_first_not_of(" :");
auto to = str.find_last_not_of(" :");

if (from == std::string::npos || to == std::string::npos) {
return "";
}

// return extracted part of string without unwanted spaces and colon signs
return str.substr(from, to + 1);
/// \brief Remove unwanted spaces and colon signs from input string. In case of
/// invalid input it will return an empty string.
inline std::string remove_unwanted_characters(std::string str) {
auto from = str.find_first_not_of(" :");
auto to = str.find_last_not_of(" :");

if (from == std::string::npos || to == std::string::npos) {
return "";
}

/// \brief Extract all key:value pairs from kokkos configuration and add it to
/// the benchmark context
inline void add_kokkos_configuration(bool verbose) {
std::ostringstream msg;
Kokkos::print_configuration(msg, verbose);
KokkosFFT::print_configuration(msg);

// Iterate over lines returned from kokkos and extract key:value pairs
std::stringstream ss{msg.str()};
for (std::string line; std::getline(ss, line, '\n');) {
auto found = line.find_first_of(':');
if (found != std::string::npos) {
auto val = remove_unwanted_characters(line.substr(found + 1));
// Ignore line without value, for example a category name
if (!val.empty()) {
benchmark::AddCustomContext(
remove_unwanted_characters(line.substr(0, found)), val);
}
// return extracted part of string without unwanted spaces and colon signs
return str.substr(from, to + 1);
}

/// \brief Extract all key:value pairs from kokkos configuration and add it to
/// the benchmark context
inline void add_kokkos_configuration(bool verbose) {
std::ostringstream msg;
Kokkos::print_configuration(msg, verbose);
KokkosFFT::print_configuration(msg);

// Iterate over lines returned from kokkos and extract key:value pairs
std::stringstream ss{msg.str()};
for (std::string line; std::getline(ss, line, '\n');) {
auto found = line.find_first_of(':');
if (found != std::string::npos) {
auto val = remove_unwanted_characters(line.substr(found + 1));
// Ignore line without value, for example a category name
if (!val.empty()) {
benchmark::AddCustomContext(
remove_unwanted_characters(line.substr(0, found)), val);
}
}
}

/// \brief Add Kokkos Kernels git info and google benchmark release to
/// benchmark context.
inline void add_version_info() {
using namespace KokkosFFT::Impl;

if (!GIT_BRANCH.empty()) {
benchmark::AddCustomContext("GIT_BRANCH", std::string(GIT_BRANCH));
benchmark::AddCustomContext("GIT_COMMIT_HASH",
std::string(GIT_COMMIT_HASH));
benchmark::AddCustomContext("GIT_CLEAN_STATUS",
std::string(GIT_CLEAN_STATUS));
benchmark::AddCustomContext("GIT_COMMIT_DESCRIPTION",
std::string(GIT_COMMIT_DESCRIPTION));
benchmark::AddCustomContext("GIT_COMMIT_DATE",
std::string(GIT_COMMIT_DATE));
}
if (!BENCHMARK_VERSION.empty()) {
benchmark::AddCustomContext("GOOGLE_BENCHMARK_VERSION",
std::string(BENCHMARK_VERSION));
}
}

/// \brief Add Kokkos Kernels git info and google benchmark release to
/// benchmark context.
inline void add_version_info() {
using namespace KokkosFFT::Impl;

if (!GIT_BRANCH.empty()) {
benchmark::AddCustomContext("GIT_BRANCH", std::string(GIT_BRANCH));
benchmark::AddCustomContext("GIT_COMMIT_HASH",
std::string(GIT_COMMIT_HASH));
benchmark::AddCustomContext("GIT_CLEAN_STATUS",
std::string(GIT_CLEAN_STATUS));
benchmark::AddCustomContext("GIT_COMMIT_DESCRIPTION",
std::string(GIT_COMMIT_DESCRIPTION));
benchmark::AddCustomContext("GIT_COMMIT_DATE",
std::string(GIT_COMMIT_DATE));
}

inline void add_env_info() {
auto num_threads = std::getenv("OMP_NUM_THREADS");
if (num_threads) {
benchmark::AddCustomContext("OMP_NUM_THREADS", num_threads);
}
auto dynamic = std::getenv("OMP_DYNAMIC");
if (dynamic) {
benchmark::AddCustomContext("OMP_DYNAMIC", dynamic);
}
auto proc_bind = std::getenv("OMP_PROC_BIND");
if (proc_bind) {
benchmark::AddCustomContext("OMP_PROC_BIND", proc_bind);
}
auto places = std::getenv("OMP_PLACES");
if (places) {
benchmark::AddCustomContext("OMP_PLACES", places);
}
if (!BENCHMARK_VERSION.empty()) {
benchmark::AddCustomContext("GOOGLE_BENCHMARK_VERSION",
std::string(BENCHMARK_VERSION));
}
}

/// \brief Gather all context information and add it to benchmark context
inline void add_benchmark_context(bool verbose = false) {
add_kokkos_configuration(verbose);
add_version_info();
add_env_info();
inline void add_env_info() {
auto num_threads = std::getenv("OMP_NUM_THREADS");
if (num_threads) {
benchmark::AddCustomContext("OMP_NUM_THREADS", num_threads);
}

/**
* \brief Report throughput and amount of data processed for simple View
* operations
*/
template <typename InViewType, typename OutViewType>
void report_results(benchmark::State& state, InViewType in, OutViewType out, double time) {
// data processed in megabytes
const double in_data_processed = static_cast<double>(in.size() *
sizeof(typename InViewType::value_type)) /
1.0e6;
const double out_data_processed = static_cast<double>(out.size() *
sizeof(typename OutViewType::value_type)) /
1.0e6;

state.SetIterationTime(time);
state.counters["MB (In)"] = benchmark::Counter(in_data_processed);
state.counters["MB (Out)"] = benchmark::Counter(out_data_processed);
state.counters["GB/s"] = benchmark::Counter(
(in_data_processed + out_data_processed) / 1.0e3, benchmark::Counter::kIsIterationInvariantRate);
auto dynamic = std::getenv("OMP_DYNAMIC");
if (dynamic) {
benchmark::AddCustomContext("OMP_DYNAMIC", dynamic);
}

} // namespace KokkosFFTBenchmark
auto proc_bind = std::getenv("OMP_PROC_BIND");
if (proc_bind) {
benchmark::AddCustomContext("OMP_PROC_BIND", proc_bind);
}
auto places = std::getenv("OMP_PLACES");
if (places) {
benchmark::AddCustomContext("OMP_PLACES", places);
}
}

/// \brief Gather all context information and add it to benchmark context
inline void add_benchmark_context(bool verbose = false) {
add_kokkos_configuration(verbose);
add_version_info();
add_env_info();
}

/**
* \brief Report throughput and amount of data processed for simple View
* operations
*/
template <typename InViewType, typename OutViewType>
void report_results(benchmark::State& state, InViewType in, OutViewType out,
double time) {
// data processed in megabytes
const double in_data_processed =
static_cast<double>(in.size() * sizeof(typename InViewType::value_type)) /
1.0e6;
const double out_data_processed =
static_cast<double>(out.size() *
sizeof(typename OutViewType::value_type)) /
1.0e6;

state.SetIterationTime(time);
state.counters["MB (In)"] = benchmark::Counter(in_data_processed);
state.counters["MB (Out)"] = benchmark::Counter(out_data_processed);
state.counters["GB/s"] =
benchmark::Counter((in_data_processed + out_data_processed) / 1.0e3,
benchmark::Counter::kIsIterationInvariantRate);
}

} // namespace KokkosFFTBenchmark

#endif
9 changes: 3 additions & 6 deletions fft/perf_test/KokkosFFT_PrintConfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,14 @@ inline void print_enabled_tpls(std::ostream& os) {
#endif
}


inline void print_version(std::ostream& os) {

// KOKKOSFFT_VERSION is used because MAJOR, MINOR and PATCH macros
// are not available in FFT
os << " "
<< "KokkosFFT Version: " << KOKKOSFFT_VERSION_MAJOR << "."
<< KOKKOSFFT_VERSION_MINOR << "." << KOKKOSFFT_VERSION_PATCH
<< '\n';
<< KOKKOSFFT_VERSION_MINOR << "." << KOKKOSFFT_VERSION_PATCH << '\n';
}
} // namespace Impl
} // namespace Impl

inline void print_configuration(std::ostream& os) {
Impl::print_version(os);
Expand All @@ -80,6 +77,6 @@ inline void print_configuration(std::ostream& os) {
Impl::print_enabled_tpls(os);
}

} // namespace KokkosFFT
} // namespace KokkosFFT

#endif
2 changes: 1 addition & 1 deletion fft/perf_test/KokkosFFT_TplsVersion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ inline std::string cufft_version_string() {
}
#endif

} // namespace KokkosFFT
} // namespace KokkosFFT
#endif
2 changes: 1 addition & 1 deletion fft/perf_test/PerfTest_FFT1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ BENCHMARK(IRFFT_1DView<double, Kokkos::LayoutRight>)
->UseManualTime()
->Unit(benchmark::kMicrosecond);

} // namespace KokkosFFTBenchmark
} // namespace KokkosFFTBenchmark
6 changes: 3 additions & 3 deletions fft/perf_test/PerfTest_FFT1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void RFFT_1DView(benchmark::State& state) {

const int n = state.range(0);
RealView1DType x("x", n);
ComplexView1DType x_hat("x_hat", n/2+1);
ComplexView1DType x_hat("x_hat", n / 2 + 1);

rfft(x, x_hat, state);
}
Expand All @@ -92,12 +92,12 @@ static void IRFFT_1DView(benchmark::State& state) {
Kokkos::View<Kokkos::complex<T>*, LayoutType, execution_space>;

const int n = state.range(0);
ComplexView1DType x("x", n/2+1);
ComplexView1DType x("x", n / 2 + 1);
RealView1DType x_hat("x_hat", n);

irfft(x, x_hat, state);
}

} // namespace KokkosFFTBenchmark
} // namespace KokkosFFTBenchmark

#endif

0 comments on commit 928fd3d

Please sign in to comment.