diff --git a/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp b/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp index bc273985eb..5e7c9851cf 100644 --- a/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp +++ b/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp @@ -484,6 +484,13 @@ hsa_status_t KfdDriver::SPMSetDestBuffer(uint32_t preferred_node_id, uint32_t si return HSA_STATUS_SUCCESS; } +hsa_status_t KfdDriver::OpenSMI(uint32_t node_id, int* fd) const { + if (HSAKMT_CALL(hsaKmtOpenSMI(node_id, fd)) != HSAKMT_STATUS_SUCCESS) { + return HSA_STATUS_ERROR; + } + return HSA_STATUS_SUCCESS; +} + void *KfdDriver::AllocateKfdMemory(const HsaMemFlags &flags, uint32_t node_id, size_t size) { void *mem = nullptr; diff --git a/runtime/hsa-runtime/core/inc/amd_kfd_driver.h b/runtime/hsa-runtime/core/inc/amd_kfd_driver.h index 5212089b30..2308226c64 100644 --- a/runtime/hsa-runtime/core/inc/amd_kfd_driver.h +++ b/runtime/hsa-runtime/core/inc/amd_kfd_driver.h @@ -123,6 +123,8 @@ public: uint32_t* size_copied, void* dest_mem_addr, bool* is_spm_data_loss) const override; + hsa_status_t OpenSMI(uint32_t node_id, int* fd) const override; + hsa_status_t IsModelEnabled(bool* enable) const override; private: diff --git a/runtime/hsa-runtime/core/inc/driver.h b/runtime/hsa-runtime/core/inc/driver.h index 8613a6170c..e8c48b00fc 100644 --- a/runtime/hsa-runtime/core/inc/driver.h +++ b/runtime/hsa-runtime/core/inc/driver.h @@ -249,6 +249,15 @@ public: uint32_t* timeout, uint32_t* size_copied, void* dest_mem_addr, bool* is_spm_data_loss) const = 0; + /// @brief Open anonymous file descriptor to enable events and read SMI events. + /// @param[in] node_id Node ID to receive the SMI event from. + /// @param[out] fd Anonymous file descriptor. + /// @retval HSA_STATUS_ERROR_INVALID_AGENT if the agent's driver doesn't support + /// SMI events. + virtual hsa_status_t OpenSMI(uint32_t node_id, int* fd) const { + return HSA_STATUS_ERROR_INVALID_AGENT; + } + /// @brief Check if the HSA KMT Model is enabled /// @param[out] enable True if the model is enabled, false otherwise virtual hsa_status_t IsModelEnabled(bool* enable) const = 0; diff --git a/runtime/hsa-runtime/core/runtime/svm_profiler.cpp b/runtime/hsa-runtime/core/runtime/svm_profiler.cpp index e0665cf298..b63d89ee4f 100644 --- a/runtime/hsa-runtime/core/runtime/svm_profiler.cpp +++ b/runtime/hsa-runtime/core/runtime/svm_profiler.cpp @@ -3,7 +3,7 @@ // The University of Illinois/NCSA // Open Source License (NCSA) // -// Copyright (c) 2022-2022, Advanced Micro Devices, Inc. All rights reserved. +// Copyright (c) 2022-2025, Advanced Micro Devices, Inc. All rights reserved. // // Developed by: // @@ -47,8 +47,6 @@ #include #include -#include "hsakmt/hsakmt.h" - #include "core/util/utils.h" #include "core/inc/runtime.h" #include "core/inc/agent.h" @@ -143,9 +141,9 @@ void SvmProfileControl::PollSmi() { HSA_SMI_EVENT_MASK_FROM_INDEX(HSA_SMI_EVENT_UNMAP_FROM_GPU); for (int i = 0; i < core::Runtime::runtime_singleton_->gpu_agents().size(); i++) { - auto err = HSAKMT_CALL(hsaKmtOpenSMI(core::Runtime::runtime_singleton_->gpu_agents()[i]->node_id(), - &files[i + 1].fd)); - assert(err == HSAKMT_STATUS_SUCCESS); + auto gpu_agent = core::Runtime::runtime_singleton_->gpu_agents()[i]; + auto err = gpu_agent->driver().OpenSMI(gpu_agent->node_id(), &files[i + 1].fd); + assert(err == HSA_STATUS_SUCCESS); files[i + 1].events = POLLIN; files[i + 1].revents = 0; // Enable collecting masked events. @@ -377,6 +375,6 @@ std::string SvmProfileControl::format(const char* format, Args... args) { } return std::string(&format_buffer[0]); } - + } // namespace AMD } // namespace rocr