// ================================================================================================= // This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This // project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- // width of 100 characters per line. // // Author(s): // Cedric Nugteren // // This file provides helper functions for time measurement and such. // // ================================================================================================= #ifndef CLBLAST_TIMING_H_ #define CLBLAST_TIMING_H_ #include #include #include #include #include #include "utilities/utilities.hpp" #include "routines/common.hpp" namespace clblast { // ================================================================================================= template double TimeFunction(const size_t num_runs, F const &function) { function(); // warm-up auto timings = std::vector(num_runs); for (auto &timing: timings) { const auto start_time = std::chrono::steady_clock::now(); function(); const auto elapsed_time = std::chrono::steady_clock::now() - start_time; timing = std::chrono::duration(elapsed_time).count(); } return *std::min_element(timings.begin(), timings.end()); } // ================================================================================================= double RunKernelTimed(const size_t num_runs, Kernel &kernel, Queue &queue, const Device &device, std::vector global, const std::vector &local); double TimeKernel(const size_t num_runs, Kernel &kernel, Queue &queue, const Device &device, std::vector global, const std::vector &local); // ================================================================================================= using Timing = std::pair; template std::vector TimeRoutine(const size_t from, const size_t to, const size_t step, const size_t num_runs, const Queue& queue, const std::vector>& buffers, F const &routine) { auto timings = std::vector(); for (auto value = from; value < to; value += step) { printf("[ RUN ] Running with value %zu\n", value); try { const auto FunctionToTune = [&]() { routine(value, queue, buffers); }; const auto time_ms = TimeFunction(num_runs, FunctionToTune); printf("[ OK ] Took %.2lf ms\n", time_ms); timings.push_back({value, time_ms}); } catch (...) { printf("[ ERROR ] Exception caught\n"); timings.push_back({value, -1.0}); // invalid } } return timings; } // ================================================================================================= } // namespace clblast // CLBLAST_TIMING_H_ #endif