Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. // TODO: add description.
  2. using wall_clock_t = std::chrono::high_resolution_clock;
  3. using time_point_t = std::chrono::time_point<wall_clock_t>;
  4. template <typename T, class Period>
  5. using time_interval_t = std::chrono::duration<T, Period>;
  6.  
  7. // TODO: add description.
  8. template <typename T>
  9. class example_profiler {
  10. // TODO: add description.
  11. using event_list = std::vector<cl::sycl::event>;
  12. using time_point_list = std::vector<time_point_t>;
  13.  
  14. public:
  15. // TODO: add description.
  16. struct profiling_data {
  17. T cgSubmissionTime{0}; // command group submission time
  18. T kernExecutionTime{0}; // exact computation time on the device
  19. T realExecutionTime{0}; // wall clock time
  20. };
  21.  
  22. // TODO: add description.
  23. example_profiler() = default;
  24. // TODO: add description.
  25. example_profiler(event_list& events, const time_point_list& starts) {
  26. profile(events, starts);
  27. }
  28.  
  29. // TODO: add description.
  30. void profile(event_list& eventList, const time_point_list& startTimeList) {
  31. // TODO: add description.
  32. if (startTimeList.size() != eventList.size()) {
  33. std::string errMsg =
  34. "The number of events do not match the number of starting time "
  35. "points.";
  36. throw std::runtime_error("Profiling Error:\n" + errMsg);
  37. }
  38.  
  39. // TODO: add description.
  40. const auto eventCount = eventList.size();
  41.  
  42. // compute the submission and execution times
  43. T cgSubmissionTime = 0;
  44. T kernExecutionTime = 0;
  45. T realExecutionTime = 0;
  46. for (size_t i = 0; i < eventCount; ++i) {
  47. // TODO: add description.
  48. auto curEvent = eventList.at(i);
  49. curEvent.wait();
  50. // TODO: add description.
  51. auto curStartTime = startTimeList.at(i);
  52.  
  53. // TODO: add description.
  54. const auto end = wall_clock_t::now();
  55. time_interval_t<T, std::milli> curRealExecutionTime = end - curStartTime;
  56. realExecutionTime += curRealExecutionTime.count();
  57.  
  58. // TODO: add description.
  59. const auto cgSubmissionTimePoint = curEvent.template get_profiling_info<
  60. cl::sycl::info::event_profiling::command_submit>();
  61. const auto startKernExecutionTimePoint =
  62. curEvent.template get_profiling_info<
  63. cl::sycl::info::event_profiling::command_start>();
  64. const auto endKernExecutionTimePoint =
  65. curEvent.template get_profiling_info<
  66. cl::sycl::info::event_profiling::command_end>();
  67.  
  68. // TODO: add description.
  69. cgSubmissionTime +=
  70. to_milli(startKernExecutionTimePoint - cgSubmissionTimePoint);
  71. kernExecutionTime +=
  72. to_milli(endKernExecutionTimePoint - startKernExecutionTimePoint);
  73. }
  74.  
  75. // TODO: add description.
  76. set_command_group_submission_time(cgSubmissionTime);
  77. set_kernel_execution_time(kernExecutionTime);
  78. set_real_execution_time(realExecutionTime);
  79. }
  80.  
  81. // TODO: add description.
  82. inline T get_command_group_submission_time() const {
  83. return m_profData.cgSubmissionTime;
  84. }
  85. // TODO: add description.
  86. inline T get_kernel_execution_time() const {
  87. return m_profData.kernExecutionTime;
  88. }
  89. // TODO: add description.
  90. inline T get_real_execution_time() const {
  91. return m_profData.realExecutionTime;
  92. }
  93.  
  94. private:
  95. // TODO: add description.
  96. profiling_data m_profData;
  97.  
  98. // TODO: add description.
  99. inline void set_command_group_submission_time(T cgSubmissionTime) {
  100. m_profData.cgSubmissionTime = cgSubmissionTime;
  101. }
  102. // TODO: add description.
  103. inline void set_kernel_execution_time(T kernExecutionTime) {
  104. m_profData.kernExecutionTime = kernExecutionTime;
  105. }
  106. // TODO: add description.
  107. inline void set_real_execution_time(T realExecutionTime) {
  108. m_profData.realExecutionTime = realExecutionTime;
  109. }
  110.  
  111. // TODO: add description.
  112. inline T to_milli(T timeValue) const {
  113. return timeValue * static_cast<T>(1e-6);
  114. }
  115. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement