Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TODO: add description.
- using wall_clock_t = std::chrono::high_resolution_clock;
- using time_point_t = std::chrono::time_point<wall_clock_t>;
- template <typename T, class Period>
- using time_interval_t = std::chrono::duration<T, Period>;
- // TODO: add description.
- template <typename T>
- class example_profiler {
- // TODO: add description.
- using event_list = std::vector<cl::sycl::event>;
- using time_point_list = std::vector<time_point_t>;
- public:
- // TODO: add description.
- struct profiling_data {
- T cgSubmissionTime{0}; // command group submission time
- T kernExecutionTime{0}; // exact computation time on the device
- T realExecutionTime{0}; // wall clock time
- };
- // TODO: add description.
- example_profiler() = default;
- // TODO: add description.
- example_profiler(event_list& events, const time_point_list& starts) {
- profile(events, starts);
- }
- // TODO: add description.
- void profile(event_list& eventList, const time_point_list& startTimeList) {
- // TODO: add description.
- if (startTimeList.size() != eventList.size()) {
- std::string errMsg =
- "The number of events do not match the number of starting time "
- "points.";
- throw std::runtime_error("Profiling Error:\n" + errMsg);
- }
- // TODO: add description.
- const auto eventCount = eventList.size();
- // compute the submission and execution times
- T cgSubmissionTime = 0;
- T kernExecutionTime = 0;
- T realExecutionTime = 0;
- for (size_t i = 0; i < eventCount; ++i) {
- // TODO: add description.
- auto curEvent = eventList.at(i);
- curEvent.wait();
- // TODO: add description.
- auto curStartTime = startTimeList.at(i);
- // TODO: add description.
- const auto end = wall_clock_t::now();
- time_interval_t<T, std::milli> curRealExecutionTime = end - curStartTime;
- realExecutionTime += curRealExecutionTime.count();
- // TODO: add description.
- const auto cgSubmissionTimePoint = curEvent.template get_profiling_info<
- cl::sycl::info::event_profiling::command_submit>();
- const auto startKernExecutionTimePoint =
- curEvent.template get_profiling_info<
- cl::sycl::info::event_profiling::command_start>();
- const auto endKernExecutionTimePoint =
- curEvent.template get_profiling_info<
- cl::sycl::info::event_profiling::command_end>();
- // TODO: add description.
- cgSubmissionTime +=
- to_milli(startKernExecutionTimePoint - cgSubmissionTimePoint);
- kernExecutionTime +=
- to_milli(endKernExecutionTimePoint - startKernExecutionTimePoint);
- }
- // TODO: add description.
- set_command_group_submission_time(cgSubmissionTime);
- set_kernel_execution_time(kernExecutionTime);
- set_real_execution_time(realExecutionTime);
- }
- // TODO: add description.
- inline T get_command_group_submission_time() const {
- return m_profData.cgSubmissionTime;
- }
- // TODO: add description.
- inline T get_kernel_execution_time() const {
- return m_profData.kernExecutionTime;
- }
- // TODO: add description.
- inline T get_real_execution_time() const {
- return m_profData.realExecutionTime;
- }
- private:
- // TODO: add description.
- profiling_data m_profData;
- // TODO: add description.
- inline void set_command_group_submission_time(T cgSubmissionTime) {
- m_profData.cgSubmissionTime = cgSubmissionTime;
- }
- // TODO: add description.
- inline void set_kernel_execution_time(T kernExecutionTime) {
- m_profData.kernExecutionTime = kernExecutionTime;
- }
- // TODO: add description.
- inline void set_real_execution_time(T realExecutionTime) {
- m_profData.realExecutionTime = realExecutionTime;
- }
- // TODO: add description.
- inline T to_milli(T timeValue) const {
- return timeValue * static_cast<T>(1e-6);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement