From 2837825b1476f7abe1843533d22b2e63b855f8c2 Mon Sep 17 00:00:00 2001 From: Yiannis Papadopoulos Date: Fri, 25 Oct 2024 18:36:36 +0000 Subject: [PATCH] rocr: Adding pointer to the owner driver in Agent class Change-Id: If913d7c7e4caf6d6e6eee3a858a27c6027c2923f --- runtime/hsa-runtime/core/inc/agent.h | 36 ++++++++----------- runtime/hsa-runtime/core/inc/amd_gpu_agent.h | 5 +-- runtime/hsa-runtime/core/inc/amd_kfd_driver.h | 2 +- .../hsa-runtime/core/inc/amd_xdna_driver.h | 3 +- .../core/runtime/amd_aie_agent.cpp | 9 ++--- .../core/runtime/amd_aie_aql_queue.cpp | 8 ++--- .../core/runtime/amd_cpu_agent.cpp | 26 +++++++------- .../core/runtime/amd_memory_region.cpp | 7 ++-- 8 files changed, 46 insertions(+), 50 deletions(-) diff --git a/runtime/hsa-runtime/core/inc/agent.h b/runtime/hsa-runtime/core/inc/agent.h index d9a895a8c8..d79986ee39 100644 --- a/runtime/hsa-runtime/core/inc/agent.h +++ b/runtime/hsa-runtime/core/inc/agent.h @@ -2,24 +2,24 @@ // // The University of Illinois/NCSA // Open Source License (NCSA) -// +// // Copyright (c) 2014-2020, 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 @@ -118,21 +118,12 @@ class Agent : public Checked<0xF6BC25EB17E6F917> { // @brief Agent class contructor. // // @param [in] type CPU or GPU or other. - explicit Agent(DriverType drv_type, uint32_t node_id, DeviceType type) - : driver_type(drv_type), node_id_(node_id), device_type_(uint32_t(type)), + explicit Agent(Driver &driver, uint32_t node_id, DeviceType type) + : node_id_(node_id), device_type_(uint32_t(type)), driver_(&driver), profiling_enabled_(false), enabled_(false) { public_handle_ = Convert(this); } - // @brief Agent class contructor. - // - // @param [in] type CPU or GPU or other. - explicit Agent(DriverType drv_type, uint32_t node_id, uint32_t type) - : driver_type(drv_type), node_id_(node_id), device_type_(type), - profiling_enabled_(false) { - public_handle_ = Convert(this); - } - // @brief Agent class destructor. virtual ~Agent() {} @@ -309,6 +300,9 @@ class Agent : public Checked<0xF6BC25EB17E6F917> { // @brief Returns node id associated with this agent. __forceinline uint32_t node_id() const { return node_id_; } + // @brief Returns the driver associated with this agent. + __forceinline Driver &driver() { return *driver_; } + // @brief Getter for profiling_enabled_. __forceinline bool profiling_enabled() const { return profiling_enabled_; } @@ -330,8 +324,6 @@ class Agent : public Checked<0xF6BC25EB17E6F917> { for (auto region : regions()) region->Trim(); } - const DriverType driver_type; - protected: // Intention here is to have a polymorphic update procedure for public_handle_ // which is callable on any Agent* but only from some class dervied from @@ -366,6 +358,8 @@ protected: const uint32_t device_type_; + Driver *driver_; + bool profiling_enabled_; bool enabled_; diff --git a/runtime/hsa-runtime/core/inc/amd_gpu_agent.h b/runtime/hsa-runtime/core/inc/amd_gpu_agent.h index f8d57ea267..038ffdfd40 100644 --- a/runtime/hsa-runtime/core/inc/amd_gpu_agent.h +++ b/runtime/hsa-runtime/core/inc/amd_gpu_agent.h @@ -74,8 +74,9 @@ class GpuAgentInt : public core::Agent { public: // @brief Constructor GpuAgentInt(uint32_t node_id) - : core::Agent(core::DriverType::KFD, node_id, - core::Agent::DeviceType::kAmdGpuDevice) {} + : core::Agent(core::Runtime::runtime_singleton_->AgentDriver( + core::DriverType::KFD), + node_id, core::Agent::DeviceType::kAmdGpuDevice) {} // @brief Ensure blits are ready (performance hint). virtual void PreloadBlits() {} diff --git a/runtime/hsa-runtime/core/inc/amd_kfd_driver.h b/runtime/hsa-runtime/core/inc/amd_kfd_driver.h index 764384dd8d..d8d2af8b7a 100644 --- a/runtime/hsa-runtime/core/inc/amd_kfd_driver.h +++ b/runtime/hsa-runtime/core/inc/amd_kfd_driver.h @@ -60,7 +60,7 @@ class Queue; namespace AMD { -class KfdDriver : public core::Driver { +class KfdDriver final : public core::Driver { public: KfdDriver(std::string devnode_name); diff --git a/runtime/hsa-runtime/core/inc/amd_xdna_driver.h b/runtime/hsa-runtime/core/inc/amd_xdna_driver.h index 2bb67c5b8e..ae3197ea95 100644 --- a/runtime/hsa-runtime/core/inc/amd_xdna_driver.h +++ b/runtime/hsa-runtime/core/inc/amd_xdna_driver.h @@ -55,9 +55,8 @@ class Queue; namespace AMD { -class XdnaDriver : public core::Driver { +class XdnaDriver final : public core::Driver { public: - XdnaDriver() = delete; XdnaDriver(std::string devnode_name); ~XdnaDriver(); diff --git a/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp index 7239aba405..5cd42be45a 100644 --- a/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_aie_agent.cpp @@ -54,8 +54,9 @@ namespace rocr { namespace AMD { AieAgent::AieAgent(uint32_t node) - : core::Agent(core::DriverType::XDNA, node, - core::Agent::DeviceType::kAmdAieDevice) { + : core::Agent(core::Runtime::runtime_singleton_->AgentDriver( + core::DriverType::XDNA), + node, core::Agent::DeviceType::kAmdAieDevice) { InitRegionList(); InitAllocators(); GetAgentProperties(); @@ -230,8 +231,8 @@ void AieAgent::InitRegionList() { } void AieAgent::GetAgentProperties() { - core::Runtime::runtime_singleton_->AgentDriver(driver_type) - .GetAgentProperties(*this); + auto &drv = static_cast(driver()); + drv.GetAgentProperties(*this); } void AieAgent::InitAllocators() { diff --git a/runtime/hsa-runtime/core/runtime/amd_aie_aql_queue.cpp b/runtime/hsa-runtime/core/runtime/amd_aie_aql_queue.cpp index ac1827055f..4018c7b193 100644 --- a/runtime/hsa-runtime/core/runtime/amd_aie_aql_queue.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_aie_aql_queue.cpp @@ -100,8 +100,8 @@ AieAqlQueue::AieAqlQueue(AieAgent *agent, size_t req_size_pkts, signal_.queue_ptr = &amd_queue_; active_ = true; - core::Runtime::runtime_singleton_->AgentDriver(agent_.driver_type) - .CreateQueue(*this); + auto &drv = static_cast(agent_.driver()); + drv.CreateQueue(*this); } AieAqlQueue::~AieAqlQueue() { Inactivate(); } @@ -111,8 +111,8 @@ hsa_status_t AieAqlQueue::Inactivate() { hsa_status_t status(HSA_STATUS_SUCCESS); if (active) { - status = core::Runtime::runtime_singleton_->AgentDriver(agent_.driver_type) - .DestroyQueue(*this); + auto &drv = static_cast(agent_.driver()); + status = drv.DestroyQueue(*this); hw_ctx_handle_ = std::numeric_limits::max(); } diff --git a/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp index 7188c895ef..8d66fdc4a0 100644 --- a/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_cpu_agent.cpp @@ -2,24 +2,24 @@ // // The University of Illinois/NCSA // Open Source License (NCSA) -// +// // Copyright (c) 2014-2020, 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 @@ -55,7 +55,9 @@ namespace rocr { namespace AMD { CpuAgent::CpuAgent(HSAuint32 node, const HsaNodeProperties &node_props) - : core::Agent(core::DriverType::KFD, node, kAmdCpuDevice), + : core::Agent( + core::Runtime::runtime_singleton_->AgentDriver(core::DriverType::KFD), + node, kAmdCpuDevice), properties_(node_props) { InitRegionList(); @@ -193,12 +195,12 @@ hsa_status_t CpuAgent::IterateSupportedIsas( } hsa_status_t CpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const { - + // agent, and vendor name size limit const size_t attribute_u = static_cast(attribute); - + switch (attribute_u) { - + // The code copies HsaNodeProperties.MarketingName a Unicode string // which is encoded in UTF-16 as a 7-bit ASCII string. The value of // HsaNodeProperties.MarketingName is obtained from the "model name" diff --git a/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp b/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp index efe40d4ac9..6696864ba5 100644 --- a/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp @@ -177,8 +177,8 @@ hsa_status_t MemoryRegion::AllocateImpl(size_t& size, AllocateFlags alloc_flags, size = AlignUp(size, kPageSize()); - return core::Runtime::runtime_singleton_->AgentDriver(owner()->driver_type) - .AllocateMemory(*this, alloc_flags, address, size, agent_node_id); + return owner()->driver().AllocateMemory(*this, alloc_flags, address, size, + agent_node_id); } hsa_status_t MemoryRegion::Free(void* address, size_t size) const { @@ -189,8 +189,7 @@ hsa_status_t MemoryRegion::Free(void* address, size_t size) const { hsa_status_t MemoryRegion::FreeImpl(void* address, size_t size) const { if (fragment_allocator_.free(address)) return HSA_STATUS_SUCCESS; - return core::Runtime::runtime_singleton_->AgentDriver(owner()->driver_type) - .FreeMemory(address, size); + return owner()->driver().FreeMemory(address, size); } // TODO: Look into a better name and/or making this process transparent to exporting.