diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp index 8271cb5904..f47d4ac4ee 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp @@ -583,6 +583,14 @@ hsa_status_t KfdDriver::GetDeviceHandle(uint32_t node_id, void** device_handle) return HSA_STATUS_SUCCESS; } +hsa_status_t KfdDriver::GetClockCounters(uint32_t node_id, HsaClockCounters* clock_counter) const { + assert(clock_counter); + + if (HSAKMT_CALL(hsaKmtGetClockCounters(node_id, clock_counter)) != HSAKMT_STATUS_SUCCESS) + return HSA_STATUS_ERROR; + return HSA_STATUS_SUCCESS; +} + hsa_status_t KfdDriver::IsModelEnabled(bool* enable) const { // AIE does not support streaming performance monitor. HSAKMT_STATUS status = HSAKMT_STATUS_ERROR; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp index 52c50d92f4..375364ca55 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp @@ -881,5 +881,9 @@ hsa_status_t XdnaDriver::GetDeviceHandle(uint32_t node_id, void** device_handle) return HSA_STATUS_ERROR; } +hsa_status_t XdnaDriver::GetClockCounters(uint32_t node_id, HsaClockCounters* clock_counter) const { + return HSA_STATUS_ERROR; +} + } // namespace AMD } // namespace rocr diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_kfd_driver.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_kfd_driver.h index 7932f373ff..f20619d20a 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_kfd_driver.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_kfd_driver.h @@ -125,6 +125,7 @@ public: hsa_status_t SetTrapHandler(uint32_t node_id, const void* base, uint64_t base_size, const void* buffer_base, uint64_t buffer_base_size) const override; hsa_status_t GetDeviceHandle(uint32_t node_id, void** device_handle) const override; + hsa_status_t GetClockCounters(uint32_t node_id, HsaClockCounters* clock_counter) const override; hsa_status_t OpenSMI(uint32_t node_id, int* fd) const override; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_xdna_driver.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_xdna_driver.h index 42833e5aef..6857c0e973 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_xdna_driver.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_xdna_driver.h @@ -239,6 +239,7 @@ public: hsa_status_t SetTrapHandler(uint32_t node_id, const void* base, uint64_t base_size, const void* buffer_base, uint64_t buffer_base_size) const override; hsa_status_t GetDeviceHandle(uint32_t node_id, void** device_handle) const override; + hsa_status_t GetClockCounters(uint32_t node_id, HsaClockCounters* clock_counter) const override; hsa_status_t IsModelEnabled(bool* enable) const override; diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/driver.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/driver.h index 21add45cb5..5ae5278597 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/driver.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/driver.h @@ -276,6 +276,13 @@ public: virtual hsa_status_t GetDeviceHandle(uint32_t node_id, void** device_handle) const = 0; + /// @brief Gets clock counters for particular Node + /// @param[in] node_id Node ID of the agent + /// @param[out] clock_counter Clock counter + /// @return HSA_STATUS_SUCCESS if the driver successfully returns the clock + virtual hsa_status_t GetClockCounters(uint32_t node_id, + HsaClockCounters* clock_counter) const = 0; + /// @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/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index 013fa119f5..f2fdbfcc6e 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -125,10 +125,10 @@ GpuAgent::GpuAgent(HSAuint32 node, const HsaNodeProperties& node_props, bool xna if (node_props.Capability.ui32.DoorbellType != 2) throw AMD::hsa_exception(HSA_STATUS_ERROR, "Agent creation failed.\nThe GPU node uses a deprecated doorbell type\n"); - HSAKMT_STATUS err = HSAKMT_CALL(hsaKmtGetClockCounters(node_id(), &t0_)); + hsa_status_t err = driver().GetClockCounters(node_id(), &t0_); t1_ = t0_; historical_clock_ratio_ = 0.0; - assert(err == HSAKMT_STATUS_SUCCESS && "hsaGetClockCounters error"); + assert(err == HSA_STATUS_SUCCESS && "hsaGetClockCounters error"); const core::Isa *isa_base; @@ -1678,7 +1678,8 @@ hsa_status_t GpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const { HsaClockCounters hsakmt_counters = {}; hsa_amd_clock_counters_t* counters = static_cast(value); - if (hsaKmtGetClockCounters(node_id(), &hsakmt_counters) == HSAKMT_STATUS_SUCCESS ) { + hsa_status_t err = driver().GetClockCounters(node_id(), &hsakmt_counters); + if (err == HSA_STATUS_SUCCESS) { counters->cpu_clock_counter = hsakmt_counters.CPUClockCounter; counters->gpu_clock_counter = hsakmt_counters.GPUClockCounter; counters->system_clock_counter = hsakmt_counters.SystemClockCounter; @@ -2199,8 +2200,8 @@ uint16_t GpuAgent::GetSdmaMicrocodeVersion() const { } void GpuAgent::SyncClocks() { - HSAKMT_STATUS err = HSAKMT_CALL(hsaKmtGetClockCounters(node_id(), &t1_)); - assert(err == HSAKMT_STATUS_SUCCESS && "hsaGetClockCounters error"); + hsa_status_t err = driver().GetClockCounters(node_id(), &t1_); + assert(err == HSA_STATUS_SUCCESS && "hsaGetClockCounters error"); } hsa_status_t GpuAgent::UpdateTrapHandlerWithPCS(pcs_sampling_data_t* pcs_hosttrap_buffers, pcs_sampling_data_t* pcs_stochastic_buffers) {