get GPU busy time (union of calculation time and communication time)
| 506 | |
| 507 | // get GPU busy time (union of calculation time and communication time) |
| 508 | profiler::Duration gpu_usage_time() { |
| 509 | if (m_kernel_start_finish_time.size() == 0) { |
| 510 | return profiler::Duration::zero(); |
| 511 | } |
| 512 | |
| 513 | std::sort( |
| 514 | m_kernel_start_finish_time.begin(), m_kernel_start_finish_time.end(), |
| 515 | [&](std::vector<profiler::HostTime> kernel1, |
| 516 | std::vector<profiler::HostTime> kernel2) { |
| 517 | if (kernel1[0] != kernel2[0]) { |
| 518 | return kernel1[0] < kernel2[0]; |
| 519 | } |
| 520 | return kernel1[1] < kernel2[1]; |
| 521 | }); |
| 522 | |
| 523 | HostTime current_start = profiler::HostTime::min(); |
| 524 | HostTime current_end = profiler::HostTime::min(); |
| 525 | for (size_t i = 0; i < m_kernel_start_finish_time.size(); ++i) { |
| 526 | if (current_start == profiler::HostTime::min()) { |
| 527 | current_start = m_kernel_start_finish_time[i][0]; |
| 528 | current_end = m_kernel_start_finish_time[i][1]; |
| 529 | } else if (current_end < m_kernel_start_finish_time[i][0]) { |
| 530 | m_gpu_usage_time += profiler::Duration(current_end - current_start); |
| 531 | current_start = m_kernel_start_finish_time[i][0]; |
| 532 | current_end = m_kernel_start_finish_time[i][1]; |
| 533 | } else if (current_end > m_kernel_start_finish_time[i][0]) { |
| 534 | current_end = max(current_end, m_kernel_start_finish_time[i][1]); |
| 535 | } |
| 536 | } |
| 537 | m_gpu_usage_time += profiler::Duration(current_end - current_start); |
| 538 | |
| 539 | return m_gpu_usage_time; |
| 540 | } |
| 541 | |
| 542 | // compared to gpu_usage_time, this method adds gap time between kernels in the same |
| 543 | // step |