rocr: Update Driver queue-related APIs

Update the user-mode driver queue APIs to leverage KMT types.

Move queue-related calls to the core::Driver API.


[ROCm/ROCR-Runtime commit: e03d44d742]
This commit is contained in:
Tony Gutierrez
2025-06-16 12:04:29 -07:00
committed by Gutierrez, Tony
parent 39bddd8b9d
commit a62368e2ba
12 changed files with 249 additions and 130 deletions
@@ -55,10 +55,10 @@
namespace rocr {
namespace AMD {
AieAgent::AieAgent(uint32_t node)
: core::Agent(core::Runtime::runtime_singleton_->AgentDriver(
core::DriverType::XDNA),
node, core::Agent::DeviceType::kAmdAieDevice) {
AieAgent::AieAgent(uint32_t node, const HsaNodeProperties& node_props)
: core::Agent(core::Runtime::runtime_singleton_->AgentDriver(core::DriverType::XDNA), node,
core::Agent::DeviceType::kAmdAieDevice),
node_props_(node_props) {
InitRegionList();
InitAllocators();
GetAgentProperties();
@@ -102,16 +102,26 @@ AieAqlQueue::AieAqlQueue(core::SharedQueue* shared_queue, AieAgent* agent, size_
signal_.queue_ptr = &amd_queue_;
active_ = true;
auto &drv = static_cast<XdnaDriver &>(agent_.driver());
drv.CreateQueue(*this);
HsaQueueResource queue_resource = {};
hsa_status_t status =
agent_.driver().CreateQueue(node_id, HSA_QUEUE_COMPUTE_AQL, 0, HSA_QUEUE_PRIORITY_NORMAL, 0,
nullptr, queue_size_bytes_, nullptr, queue_resource);
if (status != HSA_STATUS_SUCCESS) {
throw AMD::hsa_exception(status, "Failed to create a hardware context for an AIE queue.");
}
queue_id_ = queue_resource.QueueId;
amd_queue_.hsa_queue.id = GetQueueId();
}
AieAqlQueue::~AieAqlQueue() {
AieAqlQueue::Inactivate();
if (ring_buf_) agent_.system_deallocator()(ring_buf_);
if (shared_queue_) core::Runtime::runtime_singleton_->system_deallocator()(shared_queue_);
if (ring_buf_) {
agent_.system_deallocator()(ring_buf_);
}
if (shared_queue_) {
core::Runtime::runtime_singleton_->system_deallocator()(shared_queue_);
}
}
hsa_status_t AieAqlQueue::Inactivate() {
@@ -119,9 +129,7 @@ hsa_status_t AieAqlQueue::Inactivate() {
hsa_status_t status(HSA_STATUS_SUCCESS);
if (active) {
auto &drv = static_cast<XdnaDriver &>(agent_.driver());
status = drv.DestroyQueue(*this);
hw_ctx_handle_ = std::numeric_limits<uint32_t>::max();
agent_.driver().DestroyQueue(queue_id_);
}
return status;
@@ -237,7 +245,8 @@ void AieAqlQueue::SubmitPackets() {
// Call into the driver to submit from cur_id to write_dispatch_id.
// Submitting the command chain might create a new hardware context.
hsa_status_t status = driver.SubmitCmdChain(pkt, num_cont_start_cu_pkts, *this);
hsa_status_t status = driver.SubmitCmdChain(pkt, num_cont_start_cu_pkts, queue_id_,
agent_.properties().NumNeuralCores);
if (status != HSA_STATUS_SUCCESS) {
assert(false && "Could not submit packets");
}
@@ -195,10 +195,9 @@ hsa_status_t BlitSdma<RingIndexTy, HwIndexMonotonic, SizeToCountOffset, useGCR>:
// boolean flag
const HSA_QUEUE_TYPE kQueueType_ = rec_eng >= 0 ? HSA_QUEUE_SDMA_BY_ENG_ID :
(use_xgmi ? HSA_QUEUE_SDMA_XGMI : HSA_QUEUE_SDMA);
if (HSAKMT_STATUS_SUCCESS != HSAKMT_CALL(hsaKmtCreateQueueExt(agent_->node_id(), kQueueType_, 100,
HSA_QUEUE_PRIORITY_MAXIMUM, rec_eng,
queue_start_addr_, kQueueSize, NULL,
&queue_resource_))) {
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) {
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
}
@@ -173,7 +173,7 @@ GpuAgent* DiscoverGpu(HSAuint32 node_id, HsaNodeProperties& node_prop, bool xnac
}
void DiscoverAie(uint32_t node_id, HsaNodeProperties& node_prop) {
AieAgent* aie = new AieAgent(node_id);
AieAgent* aie = new AieAgent(node_id, node_prop);
core::Runtime::runtime_singleton_->RegisterAgent(aie, true);
}