From 787941237cc3ed401567e1aacfb33ca5ec67687a Mon Sep 17 00:00:00 2001 From: foreman Date: Wed, 15 Nov 2017 16:22:18 -0500 Subject: [PATCH] P4 to Git Change 1482914 by wchau@wchau_OCL_boltzmann on 2017/11/15 16:12:45 SWDEV-137374 - Collecting counters from some TCC, TCP and TA block instances causes kernel to hang - fixed by using the new AQLProfile feature to obtain precise size for command/data buffers Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccounters.cpp#2 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#46 edit [ROCm/clr commit: 0e9cee7205e7742f34553340f836bc53376c70fc] --- .../runtime/device/rocm/roccounters.cpp | 40 ++++++++----------- .../rocclr/runtime/device/rocm/rocvirtual.cpp | 11 ++++- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/projects/clr/rocclr/runtime/device/rocm/roccounters.cpp b/projects/clr/rocclr/runtime/device/rocm/roccounters.cpp index d13ec3e26e..eea3dba3a1 100644 --- a/projects/clr/rocclr/runtime/device/rocm/roccounters.cpp +++ b/projects/clr/rocclr/runtime/device/rocm/roccounters.cpp @@ -366,55 +366,49 @@ bool PerfCounterProfile::initialize() { uint32_t cmd_buf_size; uint32_t out_buf_size; - if (api_.hsa_ven_amd_aqlprofile_get_info( - &profile_, - HSA_VEN_AMD_AQLPROFILE_INFO_COMMAND_BUFFER_SIZE, - &cmd_buf_size) != HSA_STATUS_SUCCESS) { - return false; - } + // save the current command and output buffer information + hsa_ven_amd_aqlprofile_descriptor_t cmd_buf = profile_.command_buffer; + hsa_ven_amd_aqlprofile_descriptor_t out_buf = profile_.output_buffer; - if (api_.hsa_ven_amd_aqlprofile_get_info( - &profile_, - HSA_VEN_AMD_AQLPROFILE_INFO_PMC_DATA_SIZE, - &out_buf_size) != HSA_STATUS_SUCCESS) { + // determine the required buffer sizes for the profiling events + profile_.events = &events_[0]; + profile_.event_count = events_.size(); + profile_.command_buffer = {nullptr, 0}; + profile_.output_buffer = {nullptr, 0}; + + if (api_.hsa_ven_amd_aqlprofile_start(&profile_, nullptr) != HSA_STATUS_SUCCESS) { return false; } const uint32_t alignment = amd::Os::pageSize(); // use page alignment - hsa_ven_amd_aqlprofile_descriptor_t cmd_buf = profile_.command_buffer; - if (cmd_buf.ptr != nullptr && cmd_buf.size != cmd_buf_size) { + if (cmd_buf.ptr != nullptr && cmd_buf.size != profile_.command_buffer.size) { roc_device_.memFree(cmd_buf.ptr, cmd_buf.size); cmd_buf.ptr = nullptr; } if (cmd_buf.ptr == nullptr) { - void *buf_ptr = roc_device_.hostAlloc(cmd_buf_size, alignment, 1); + void *buf_ptr = roc_device_.hostAlloc(profile_.command_buffer.size, alignment, 1); if (buf_ptr != nullptr) { - cmd_buf.ptr = buf_ptr; - cmd_buf.size = cmd_buf_size; - profile_.command_buffer = cmd_buf; + profile_.command_buffer.ptr = buf_ptr; } else { return false; } } - hsa_ven_amd_aqlprofile_descriptor_t out_buf = profile_.output_buffer; - if (out_buf.ptr != nullptr && out_buf.size != out_buf_size) { + if (out_buf.ptr != nullptr && out_buf.size != profile_.output_buffer.size) { roc_device_.memFree(out_buf.ptr, out_buf.size); out_buf.ptr = nullptr; } if (out_buf.ptr == nullptr) { - void *buf_ptr = roc_device_.hostAlloc(out_buf_size, alignment, 1); + void *buf_ptr = roc_device_.hostAlloc(profile_.output_buffer.size, alignment, 1); if (buf_ptr != nullptr) { - out_buf.ptr = buf_ptr; - out_buf.size = out_buf_size; - profile_.output_buffer = out_buf; + profile_.output_buffer.ptr = buf_ptr; } else { - roc_device_.hostFree(cmd_buf.ptr, cmd_buf.size); + roc_device_.hostFree(profile_.command_buffer.ptr, profile_.command_buffer.size); return false; } } diff --git a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp index 97c0af820d..5b902c9742 100644 --- a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp +++ b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp @@ -1984,7 +1984,11 @@ void VirtualGPU::submitPerfCounter(amd::PerfCounterCommand& vcmd) { } // create the AQL packet for start profiling - profileRef->createStartPacket(); + if (profileRef->createStartPacket() == nullptr) { + LogError("Failed to create AQL packet for start profiling"); + vcmd.setStatus(CL_INVALID_OPERATION); + } + dispatchCounterAqlPacket(profileRef->prePacket(), counter->gfxVersion(), false, profileRef->api()); @@ -1997,7 +2001,10 @@ void VirtualGPU::submitPerfCounter(amd::PerfCounterCommand& vcmd) { PerfCounterProfile* profileRef = counter->profileRef(); // create the AQL packet for stop profiling - profileRef->createStopPacket(); + if (profileRef->createStopPacket() == nullptr) { + LogError("Failed to create AQL packet for stop profiling"); + vcmd.setStatus(CL_INVALID_OPERATION); + } dispatchCounterAqlPacket(profileRef->postPacket(), counter->gfxVersion(), true, profileRef->api()); } else {