From 7ccd12634b5f4da767d3d91aa29d974ba0f8cb95 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Fri, 6 Jul 2018 18:25:55 -0500 Subject: [PATCH] fixing hsa queues profiling enabling Change-Id: Ifec5a60ec32bdba40c366ac302659d69d47cc275 [ROCm/rocprofiler commit: 19fa38b29463c0c24a1a7fe118213d8afaabc448] --- projects/rocprofiler/LICENSE | 14 +++++------- .../rocprofiler/src/core/intercept_queue.h | 22 +++++++++++++------ projects/rocprofiler/src/core/tracker.h | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/projects/rocprofiler/LICENSE b/projects/rocprofiler/LICENSE index 84d470f4dc..9e78331e70 100644 --- a/projects/rocprofiler/LICENSE +++ b/projects/rocprofiler/LICENSE @@ -1,6 +1,4 @@ -MIT License - -Copyright (c) 2018 ROCm Core Technology +Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,13 +7,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/projects/rocprofiler/src/core/intercept_queue.h b/projects/rocprofiler/src/core/intercept_queue.h index 51e4eb1d68..0d9f29e17c 100644 --- a/projects/rocprofiler/src/core/intercept_queue.h +++ b/projects/rocprofiler/src/core/intercept_queue.h @@ -65,8 +65,8 @@ class InterceptQueue { group_segment_size, queue, &status); if (status != HSA_STATUS_SUCCESS) abort(); - if (tracker_on_ && (tracker_ == NULL)) { - tracker_ = new Tracker(timeout_); + if (tracker_on_) { + if (tracker_ == NULL) tracker_ = new Tracker(timeout_); status = hsa_amd_profiling_set_profiler_enabled(*queue, true); if (status != HSA_STATUS_SUCCESS) abort(); } @@ -106,21 +106,26 @@ class InterceptQueue { InterceptQueue* obj = reinterpret_cast(data); Queue* proxy = obj->proxy_; + // Travers input packets for (uint64_t j = 0; j < count; ++j) { - bool to_submit = true; const packet_t* packet = &packets_arr[j]; + bool to_submit = true; + // Checking for dispatch packet type if ((GetHeaderType(packet) == HSA_PACKET_TYPE_KERNEL_DISPATCH) && (dispatch_callback_ != NULL)) { - rocprofiler_group_t group = {}; const hsa_kernel_dispatch_packet_t* dispatch_packet = reinterpret_cast(packet); - const char* kernel_name = GetKernelName(dispatch_packet); + + // Adding kernel timing tracker const rocprofiler_dispatch_record_t* record = NULL; if (tracker_ != NULL) { const auto* entry = tracker_->Add(obj->agent_info_->dev_id, dispatch_packet->completion_signal); const_cast(dispatch_packet)->completion_signal = entry->signal; record = entry->record; } + + // Prepareing dispatch callback data + const char* kernel_name = GetKernelName(dispatch_packet); rocprofiler_callback_data_t data = {obj->agent_info_->dev_id, obj->agent_info_->dev_index, obj->queue_, @@ -128,8 +133,12 @@ class InterceptQueue { dispatch_packet, kernel_name, record}; + + // Calling dispatch callback + rocprofiler_group_t group = {}; hsa_status_t status = dispatch_callback_(&data, callback_data_, &group); free(const_cast(kernel_name)); + // Injecting profiling start/stop packets if ((status == HSA_STATUS_SUCCESS) && (group.context != NULL)) { Context* context = reinterpret_cast(group.context); const pkt_vector_t& start_vector = context->StartPackets(group.index); @@ -147,6 +156,7 @@ class InterceptQueue { } } + // Submitting the original packets if profiling was not enabled if (to_submit) { if (writer != NULL) { writer(packet, 1); @@ -154,8 +164,6 @@ class InterceptQueue { proxy->Submit(packet, 1); } } - - packet += 1; } } diff --git a/projects/rocprofiler/src/core/tracker.h b/projects/rocprofiler/src/core/tracker.h index 95e015ee50..c35f0d1c03 100644 --- a/projects/rocprofiler/src/core/tracker.h +++ b/projects/rocprofiler/src/core/tracker.h @@ -102,7 +102,7 @@ class Tracker { status = hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP, &record->dispatch); if (status != HSA_STATUS_SUCCESS) EXC_RAISING(status, "hsa_system_get_info(HSA_SYSTEM_INFO_TIMESTAMP)"); - hsa_amd_signal_async_handler(entry->signal, HSA_SIGNAL_CONDITION_LT, 1, Handler, entry); + status = hsa_amd_signal_async_handler(entry->signal, HSA_SIGNAL_CONDITION_LT, 1, Handler, entry); if (status != HSA_STATUS_SUCCESS) EXC_RAISING(status, "hsa_amd_signal_async_handler"); if (trace_on_) {