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.
This commit is contained in:
Tony Gutierrez
2025-06-16 12:04:29 -07:00
committed by Gutierrez, Tony
parent b3c48cc68c
commit e03d44d742
12 changed files with 249 additions and 130 deletions
+27 -34
View File
@@ -55,53 +55,45 @@ class AieAgent : public core::Agent {
public:
/// @brief AIE agent constructor.
/// @param [in] node Node id.
AieAgent(uint32_t node);
AieAgent(uint32_t node, const HsaNodeProperties& node_props);
// @brief AIE agent destructor.
~AieAgent();
// @brief AIE agent destructor.
~AieAgent();
hsa_status_t VisitRegion(bool include_peer,
hsa_status_t (*callback)(hsa_region_t region,
void *data),
void *data) const;
hsa_status_t IterateRegion(hsa_status_t (*callback)(hsa_region_t region,
void *data),
void *data) const override;
hsa_status_t VisitRegion(bool include_peer,
hsa_status_t (*callback)(hsa_region_t region, void* data),
void* data) const;
hsa_status_t IterateRegion(hsa_status_t (*callback)(hsa_region_t region, void* data),
void* data) const override;
hsa_status_t IterateCache(hsa_status_t (*callback)(hsa_cache_t cache,
void *data),
void *value) const override;
hsa_status_t IterateCache(hsa_status_t (*callback)(hsa_cache_t cache, void* data),
void* value) const override;
hsa_status_t IterateSupportedIsas(
hsa_status_t (*callback)(hsa_isa_t isa, void* data),
void* data) const override;
hsa_status_t IterateSupportedIsas(hsa_status_t (*callback)(hsa_isa_t isa, void* data),
void* data) const override;
hsa_status_t GetInfo(hsa_agent_info_t attribute, void *value) const override;
hsa_status_t GetInfo(hsa_agent_info_t attribute, void* value) const override;
hsa_status_t QueueCreate(size_t size, hsa_queue_type32_t queue_type, uint64_t flags,
core::HsaEventCallback event_callback, void* data,
uint32_t private_segment_size, uint32_t group_segment_size,
core::Queue** queue) override;
hsa_status_t QueueCreate(size_t size, hsa_queue_type32_t queue_type, uint64_t flags,
core::HsaEventCallback event_callback, void* data,
uint32_t private_segment_size, uint32_t group_segment_size,
core::Queue** queue) override;
// @brief Override from core::Agent.
const std::vector<const core::Isa*>& supported_isas() const override {
return supported_isas_;
}
// @brief Override from core::Agent.
const std::vector<const core::Isa*>& supported_isas() const override { return supported_isas_; }
const std::vector<const core::MemoryRegion *> &regions() const override {
return regions_;
}
const std::vector<const core::MemoryRegion*>& regions() const override { return regions_; }
/// @brief Getter for the AIE system allocator.
const std::function<void *(size_t size, size_t align,
core::MemoryRegion::AllocateFlags flags)> &
system_allocator() const {
return system_allocator_;
}
/// @brief Getter for the AIE system allocator.
const std::function<void*(size_t size, size_t align, core::MemoryRegion::AllocateFlags flags)>&
system_allocator() const {
return system_allocator_;
}
/// @brief Getter for the AIE system deallocator.
const std::function<void(void*)>& system_deallocator() const { return system_deallocator_; }
const HsaNodeProperties& properties() const { return node_props_; }
// AIE agent methods.
/// @brief Get the number of columns on this AIE agent.
uint32_t GetNumCols() const { return num_cols_; }
@@ -134,6 +126,7 @@ private:
const uint32_t max_aql_size_ = 0x40;
const uint32_t max_queues_ = 1;
const HsaNodeProperties node_props_;
/// @brief Number of columns in the AIE array.
uint32_t num_cols_ = 0;
/// @brief Number of rows of core tiles in the AIE array. Not all rows in a
@@ -103,14 +103,6 @@ class AieAqlQueue : public core::Queue,
/// @brief Returns the agent associated with this queue.
AieAgent& GetAgent() { return agent_; }
/// @brief Sets the hardware context.
void SetHwCtxHandle(uint32_t hw_ctx_handle) {
hw_ctx_handle_ = hw_ctx_handle;
}
/// @brief Returns the hardware context.
uint32_t GetHwCtxHandle() const { return hw_ctx_handle_; }
// GPU-specific queue functions are unsupported.
hsa_status_t GetCUMasking(uint32_t num_cu_mask_count,
@@ -141,17 +133,6 @@ class AieAqlQueue : public core::Queue,
/// @brief Called when the doorbell is rung to submit all queued packets.
void SubmitPackets();
/// @brief Handle for an application context on the AIE device.
///
/// Each user queue will have an associated context. This handle is assigned
/// by the driver on context creation.
///
/// TODO: For now we support a single context that allocates all core tiles in
/// the array. In the future we can make the number of tiles configurable so
/// that multiple workloads with different core tile configurations can
/// execute on the AIE agent at the same time.
uint32_t hw_ctx_handle_ = std::numeric_limits<uint32_t>::max();
/// @brief Indicates if queue is active.
std::atomic<bool> active_;
static __forceinline int& rtti_id() {
+9 -11
View File
@@ -2,24 +2,24 @@
//
// 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:
//
//
// AMD Research and AMD HSA Software Development
//
//
// Advanced Micro Devices, Inc.
//
//
// www.amd.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal with the Software without restriction, including without limitation
// the rights 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:
//
//
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimers.
// - Redistributions in binary form must reproduce the above copyright
@@ -29,7 +29,7 @@
// nor the names of its contributors may be used to endorse or promote
// products derived from this Software without specific prior written
// permission.
//
//
// 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
@@ -47,8 +47,6 @@
#include <stdint.h>
#include <vector>
#include "hsakmt/hsakmt.h"
#include "core/inc/amd_gpu_agent.h"
#include "core/inc/blit.h"
#include "core/inc/runtime.h"
+11 -2
View File
@@ -97,8 +97,17 @@ public:
void **mem, size_t size,
uint32_t node_id) override;
hsa_status_t FreeMemory(void *mem, size_t size) override;
hsa_status_t CreateQueue(core::Queue &queue) const override;
hsa_status_t DestroyQueue(core::Queue &queue) const override;
hsa_status_t CreateQueue(uint32_t node_id, HSA_QUEUE_TYPE type, uint32_t queue_pct,
HSA_QUEUE_PRIORITY priority, uint32_t sdma_engine_id, void* queue_addr,
uint64_t queue_size_bytes, HsaEvent* event,
HsaQueueResource& queue_resource) const override;
hsa_status_t UpdateQueue(HSA_QUEUEID queue_id, uint32_t queue_pct, HSA_QUEUE_PRIORITY priority,
void* queue_addr, uint64_t queue_size, HsaEvent* event) const override;
hsa_status_t DestroyQueue(HSA_QUEUEID queue_id) const override;
hsa_status_t SetQueueCUMask(HSA_QUEUEID queue_id, uint32_t cu_mask_count,
uint32_t* queue_cu_mask) const override;
hsa_status_t AllocQueueGWS(HSA_QUEUEID queue_id, uint32_t num_gws,
uint32_t* first_gws) const override;
hsa_status_t ExportDMABuf(void *mem, size_t size, int *dmabuf_fd,
size_t *offset) override;
hsa_status_t ImportDMABuf(int dmabuf_fd, core::Agent &agent,
+15 -7
View File
@@ -95,8 +95,6 @@ class Queue;
namespace AMD {
class AieAqlQueue;
// @brief: Used to transform an address into a device address
constexpr uint32_t DEV_ADDR_BASE = 0x04000000;
constexpr uint32_t DEV_ADDR_OFFSET_MASK = 0x02FFFFFF;
@@ -209,8 +207,17 @@ public:
void **mem, size_t size,
uint32_t node_id) override;
hsa_status_t FreeMemory(void *mem, size_t size) override;
hsa_status_t CreateQueue(core::Queue &queue) const override;
hsa_status_t DestroyQueue(core::Queue &queue) const override;
hsa_status_t CreateQueue(uint32_t node_id, HSA_QUEUE_TYPE type, uint32_t queue_pct,
HSA_QUEUE_PRIORITY priority, uint32_t sdma_engine_id, void* queue_addr,
uint64_t queue_size_bytes, HsaEvent* event,
HsaQueueResource& queue_resource) const override;
hsa_status_t UpdateQueue(HSA_QUEUEID queue_id, uint32_t queue_pct, HSA_QUEUE_PRIORITY priority,
void* queue_addr, uint64_t queue_size, HsaEvent* event) const override;
hsa_status_t DestroyQueue(HSA_QUEUEID queue_id) const override;
hsa_status_t SetQueueCUMask(HSA_QUEUEID queue_id, uint32_t cu_mask_count,
uint32_t* queue_cu_mask) const override;
hsa_status_t AllocQueueGWS(HSA_QUEUEID queue_id, uint32_t num_gws,
uint32_t* first_gws) const override;
hsa_status_t ExportDMABuf(void *mem, size_t size, int *dmabuf_fd,
size_t *offset) override;
hsa_status_t ImportDMABuf(int dmabuf_fd, core::Agent &agent,
@@ -223,7 +230,7 @@ public:
/// @brief Submits @p num_pkts packets in a command chain.
hsa_status_t SubmitCmdChain(hsa_amd_aie_ert_packet_t* first_pkt, uint32_t num_pkts,
AieAqlQueue& aie_queue);
HSA_QUEUEID& queue_id, uint32_t num_core_tiles);
hsa_status_t SPMAcquire(uint32_t preferred_node_id) const override;
hsa_status_t SPMRelease(uint32_t preferred_node_id) const override;
@@ -243,7 +250,8 @@ public:
BOHandle FindBOHandle(void* mem) const;
/// @brief Creates a new hardware context with the given PDI BO handles.
hsa_status_t ConfigHwCtx(const PDICache& pdi_bo_handles, AieAqlQueue& aie_queue);
hsa_status_t ConfigHwCtx(const PDICache& pdi_bo_handles, HSA_QUEUEID& queue_id,
uint32_t num_core_tiles);
hsa_status_t QueryDriverVersion();
@@ -274,7 +282,7 @@ public:
/// @param bo_handles handles associated with the command
/// @param aie_queue queue to submit to
hsa_status_t ExecCmdAndWait(const BOHandle& cmd_chain_bo_handle,
const std::vector<uint32_t>& bo_handles, AieAqlQueue& aie_queue);
const std::vector<uint32_t>& bo_handles, HSA_QUEUEID queue_id);
/// TODO: Remove this in the future and rely on the core Runtime
/// object to track handle allocations. Using the VMEM API for mapping XDNA
+47 -2
View File
@@ -43,6 +43,7 @@
#ifndef HSA_RUNTME_CORE_INC_DRIVER_H_
#define HSA_RUNTME_CORE_INC_DRIVER_H_
#include <cstdint>
#include <limits>
#include <string>
@@ -146,9 +147,53 @@ public:
virtual hsa_status_t FreeMemory(void *mem, size_t size) = 0;
virtual hsa_status_t CreateQueue(Queue &queue) const = 0;
/// @brief Create an agent dispatch queue with user-mode access rights.
/// @param[in] node_id Node ID of the agent on which the queue is being created.
/// @param[in] type Queue's type.
/// @param[in] queue_pct Maximum percentage of a queue's occupancy allowed.
/// @param[in] priority Queue's priority for scheduling.
/// @param[in] sdma_engine_id ID of the SDMA engine on which the queue is being created. Only used
/// if @p type is one of the SDMA queue types.
/// @param[in] queue_addr Address of the queue's ring buffer.
/// @param[in] queue_size_bytes Size of the queue's ring buffer in bytes.
/// @param[in] event HsaEvent for event-driven callbacks.
/// @param[out] queue_resource Queue resource information populated by the driver.
virtual hsa_status_t CreateQueue(uint32_t node_id, HSA_QUEUE_TYPE type, uint32_t queue_pct,
HSA_QUEUE_PRIORITY priority, uint32_t sdma_engine_id,
void* queue_addr, uint64_t queue_size_bytes, HsaEvent* event,
HsaQueueResource& queue_resource) const = 0;
virtual hsa_status_t DestroyQueue(Queue &queue) const = 0;
/// @brief Destroy a queue.
/// @param queue_id Kernel-mode driver's assigned queue ID.
virtual hsa_status_t DestroyQueue(HSA_QUEUEID queue_id) const = 0;
/// @brief Update a queue's properties.
/// @param[in] queue_id Kernel-mode driver's assigned queue ID.
/// @param[in] queue_pct Maximum percentage of a queue's occupancy allowed.
/// @param[in] priority Queue's priority for scheduling.
/// @param[in] queue_addr Queue's ring buffer base address.
/// @param[in] queue_size_bytes Size of the queue's ring buffer in bytes.
/// @param[in] event HsaEvent for event-driven callbacks.
virtual hsa_status_t UpdateQueue(HSA_QUEUEID queue_id, uint32_t queue_pct,
HSA_QUEUE_PRIORITY priority, void* queue_addr,
uint64_t queue_size_bytes, HsaEvent* event) const = 0;
/// @brief Set the CU mask for a queue.
/// @details This sets the CU bitmask for a queue. The CU mask determines which CUs
/// a queue's dispatches can target. Currently this is only supported for GPU devices.
/// @param[in] queue_id Kernel-mode driver's assigned queue ID.
/// @param[in] cu_mask_count Number of CU bits in the mask.
/// @param[in] queue_cu_mask New CU mask for the queue.
virtual hsa_status_t SetQueueCUMask(HSA_QUEUEID queue_id, uint32_t cu_mask_count,
uint32_t* queue_cu_mask) const = 0;
/// @brief Allocate global wave sync (GWS) resource for a queue. This is only supported for GPUs.
/// GWS can be used to synchronize wavefronts across the entire GPU device.
/// @param[in] queue_id Kernel-mode driver's assigned queue ID.
/// @param[in] num_gws Number of GWS slots.
/// @param[in] first_gws First GWS slot.
virtual hsa_status_t AllocQueueGWS(HSA_QUEUEID queue_id, uint32_t num_gws,
uint32_t* first_gws) const = 0;
/// @brief Imports memory using dma-buf.
///