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 eafdbe76ec..72bb644b66 100644 --- a/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp +++ b/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp @@ -611,5 +611,21 @@ hsa_status_t KfdDriver::IsModelEnabled(bool* enable) const { return HSA_STATUS_SUCCESS; } +hsa_status_t KfdDriver::GetWallclockFrequency(uint32_t node_id, uint64_t* frequency) const { + assert(frequency); + + amdgpu_gpu_info info; + amdgpu_device_handle handle; + if (GetDeviceHandle(node_id, reinterpret_cast(&handle)) != HSA_STATUS_SUCCESS) + return HSA_STATUS_ERROR; + + if (DRM_CALL(amdgpu_query_gpu_info(handle, &info)) < 0) return HSA_STATUS_ERROR; + + // Reported by libdrm in KHz. + *frequency = uint64_t(info.gpu_counter_freq) * 1000ull; + + return HSA_STATUS_SUCCESS; +} + } // namespace AMD } // namespace rocr diff --git a/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp b/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp index e2a0f60e82..fd7fa21a04 100644 --- a/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp +++ b/runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp @@ -890,5 +890,9 @@ hsa_status_t XdnaDriver::GetTileConfig(uint32_t node_id, HsaGpuTileConfig* confi return HSA_STATUS_ERROR; } +hsa_status_t XdnaDriver::GetWallclockFrequency(uint32_t node_id, uint64_t* frequency) const { + return HSA_STATUS_ERROR; +} + } // namespace AMD } // namespace rocr diff --git a/runtime/hsa-runtime/core/inc/amd_kfd_driver.h b/runtime/hsa-runtime/core/inc/amd_kfd_driver.h index f673221731..4c56b8b9fe 100644 --- a/runtime/hsa-runtime/core/inc/amd_kfd_driver.h +++ b/runtime/hsa-runtime/core/inc/amd_kfd_driver.h @@ -127,6 +127,7 @@ public: 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 GetTileConfig(uint32_t node_id, HsaGpuTileConfig* config) const override; + hsa_status_t GetWallclockFrequency(uint32_t node_id, uint64_t* frequency) const override; hsa_status_t OpenSMI(uint32_t node_id, int* fd) const override; diff --git a/runtime/hsa-runtime/core/inc/amd_xdna_driver.h b/runtime/hsa-runtime/core/inc/amd_xdna_driver.h index f3f0ac2c9b..8642c8d462 100644 --- a/runtime/hsa-runtime/core/inc/amd_xdna_driver.h +++ b/runtime/hsa-runtime/core/inc/amd_xdna_driver.h @@ -241,6 +241,7 @@ public: 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 GetTileConfig(uint32_t node_id, HsaGpuTileConfig* config) const override; + hsa_status_t GetWallclockFrequency(uint32_t node_id, uint64_t* frequency) const override; hsa_status_t IsModelEnabled(bool* enable) const override; diff --git a/runtime/hsa-runtime/core/inc/driver.h b/runtime/hsa-runtime/core/inc/driver.h index 70ea3b1601..a74670b31a 100644 --- a/runtime/hsa-runtime/core/inc/driver.h +++ b/runtime/hsa-runtime/core/inc/driver.h @@ -294,6 +294,13 @@ public: /// @param[out] enable True if the model is enabled, false otherwise virtual hsa_status_t IsModelEnabled(bool* enable) const = 0; + /// @brief Gets the wallclock frequency for a specific node. + /// @param[in] node_id Node ID of the agent + /// @param[out] frequency Pointer to the wallclock frequency + /// @return HSA_STATUS_SUCCESS if the wallclock frequency was successfully retrieved, or an error + /// code. + virtual hsa_status_t GetWallclockFrequency(uint32_t node_id, uint64_t* frequency) const = 0; + /// Unique identifier for supported kernel-mode drivers. const DriverType kernel_driver_type_; diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index f2fdbfcc6e..446ec50ae6 100644 --- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -218,13 +218,11 @@ GpuAgent::GpuAgent(HSAuint32 node, const HsaNodeProperties& node_props, bool xna if (model_enabled) { wallclock_frequency_ = 0; } else { - // Get wallclock freq from libdrm. - amdgpu_gpu_info info; - if (DRM_CALL(amdgpu_query_gpu_info(ldrm_dev_, &info)) < 0) - throw AMD::hsa_exception(HSA_STATUS_ERROR, "Agent creation failed.\nlibdrm query failed.\n"); - - // Reported by libdrm in KHz. - wallclock_frequency_ = uint64_t(info.gpu_counter_freq) * 1000ull; + // Get wallclock freq + err = driver().GetWallclockFrequency(node_id(), &wallclock_frequency_); + if (err != HSA_STATUS_SUCCESS) { + throw AMD::hsa_exception(err, "Agent creation failed.\nGetWallclockFrequency error.\n"); + } } #endif