rocr: SDMA improvements (#326)

- When SDMA queue gets full when copying 2GB or more it blocks async
copy api
- Improve/format logging
This commit is contained in:
mat3ix
2025-08-13 07:25:29 -07:00
committed by GitHub
parent 483315fd0a
commit c41050d01f
4 changed files with 28 additions and 19 deletions
@@ -678,7 +678,7 @@ hsa_status_t BlitKernel::SubmitLinearCopyCommand(
std::atomic_thread_fence(std::memory_order_release);
queue_buffer[(write_index)&queue_bitmask_].header = kBarrierPacketHeader;
LogPrint(HSA_AMD_LOG_FLAG_BLIT_KERNEL_PKTS,
LogPrint(HSA_AMD_LOG_FLAG_AQL,
"HWq=%p, id=%lu, Barrier Header = "
"0x%x (type=%d, barrier=%d, acquire=%d, release=%d), "
"dep_signal=[0x%zx 0x%zx 0x%zx 0x%zx 0x%zx], completion_signal=0x%zx "
@@ -693,12 +693,12 @@ hsa_status_t BlitKernel::SubmitLinearCopyCommand(
HSA_PACKET_HEADER_WIDTH_SCACQUIRE_FENCE_SCOPE),
extractAqlBits(kBarrierPacketHeader, HSA_PACKET_HEADER_SCRELEASE_FENCE_SCOPE,
HSA_PACKET_HEADER_WIDTH_SCRELEASE_FENCE_SCOPE),
barrier_packet.dep_signal[0].handle,
barrier_packet.dep_signal[0].handle,
barrier_packet.dep_signal[1].handle,
barrier_packet.dep_signal[2].handle,
barrier_packet.dep_signal[3].handle,
barrier_packet.dep_signal[3].handle,
barrier_packet.dep_signal[4].handle,
barrier_packet.completion_signal.handle,
barrier_packet.completion_signal.handle,
queue_->LoadReadIndexRelaxed(), write_index);
++write_index;
@@ -900,7 +900,7 @@ void BlitKernel::PopulateQueue(uint64_t index, uint64_t code_handle, void* args,
__atomic_store_n(&(queue_buffer[index & queue_bitmask_].full_header),
kDispatchPacketHeader | packet.setup << 16, __ATOMIC_RELEASE);
LogPrint(HSA_AMD_LOG_FLAG_BLIT_KERNEL_PKTS,
LogPrint(HSA_AMD_LOG_FLAG_AQL,
"HWq=%p, id=%lu, Dispatch Header = "
"0x%x (type=%d, barrier=%d, acquire=%d, release=%d), "
"setup=%d, grid=[%zu, %zu, %zu], workgroup=[%zu, %zu, %zu], private_seg_size=%zu, "
@@ -3,7 +3,7 @@
// The University of Illinois/NCSA
// Open Source License (NCSA)
//
// Copyright (c) 2014-2020, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2014-2025, Advanced Micro Devices, Inc. All rights reserved.
//
// Developed by:
//
@@ -71,7 +71,7 @@ inline uint32_t ptrhigh32(const void* p) {
#endif
}
const size_t BlitSdmaBase::kQueueSize = 1024 * 1024;
const size_t BlitSdmaBase::kQueueSize = 1024 * 1024 * 8;
const size_t BlitSdmaBase::kCopyPacketSize = sizeof(SDMA_PKT_COPY_LINEAR);
const size_t BlitSdmaBase::kMaxSingleCopySize = SDMA_PKT_COPY_LINEAR::kMaxSize_;
const size_t BlitSdmaBase::kMaxSingleFillSize = SDMA_PKT_CONSTANT_FILL::kMaxSize_;
@@ -186,6 +186,8 @@ hsa_status_t BlitSdma<useGCR>::Initialize(const core::Agent& agent, bool use_xgm
if (agent_->driver().CreateQueue(agent_->node_id(), kQueueType_, 100, HSA_QUEUE_PRIORITY_MAXIMUM,
rec_eng, queue_start_addr_, kQueueSize, nullptr,
queue_resource_) != HSA_STATUS_SUCCESS) {
LogPrint(HSA_AMD_LOG_FLAG_INFO, "Failed to create queue, size=%d, type=%d,"
" priority=%d, engine_id=%d", kQueueSize, kQueueType_, HSA_QUEUE_PRIORITY_MAXIMUM, rec_eng);
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
}
@@ -49,23 +49,25 @@
#include <string>
#include <algorithm>
#include <locale>
#include <iomanip>
namespace rocr {
FILE* log_file = stderr;
uint8_t log_flags[8];
void log_printf(const char* file, int line, const char* format, ...) {
va_list ap;
std::stringstream str_thrd_id;
str_thrd_id << std::hex << std::this_thread::get_id();
va_start(ap, format);
char message[4096];
vsnprintf(message, sizeof(message), format, ap);
va_end(ap);
fprintf(log_file, ":%-25s:%-4d: %010lld us: [pid:%-5d tid:0x%s] [***rocr***] %s\n",
file, line, os::ReadAccurateClock()/1000ULL, os::GetProcessId(),
str_thrd_id.str().c_str(), message);
fflush(log_file);
va_list ap;
std::stringstream pidtid;
pidtid << "[pid:" << os::GetProcessId() << " tid: 0x" ;
pidtid << std::hex << std::setw(5) << std::this_thread::get_id() << "]";
va_start(ap, format);
char message[4096];
vsnprintf(message, sizeof(message), format, ap);
va_end(ap);
fprintf(log_file, ":7:%-25s:%-4d: %010lld us: %s [***rocr***] %s\n",
file, line, os::ReadAccurateClock()/1000ULL,
pidtid.str().c_str(), message);
fflush(log_file);
}
// split at separators
@@ -3646,8 +3646,13 @@ hsa_status_t hsa_amd_queue_get_info(hsa_queue_t* queue, hsa_queue_info_attribute
* @brief logging types
*/
typedef enum hsa_amd_log_flag_s {
/* Log AQL packets internally enqueued by HSA for Blit Kernels */
/* Log AQL packets internally enqueued by ROCr */
HSA_AMD_LOG_FLAG_BLIT_KERNEL_PKTS = 0,
HSA_AMD_LOG_FLAG_AQL = 0,
/* Log SDMA packets */
HSA_AMD_LOG_FLAG_SDMA = 1,
/* Log INFO */
HSA_AMD_LOG_FLAG_INFO = 2,
} hsa_amd_log_flag_t;
/**