rocr/driver: move wallclock frequency query to driver layer

Move the wallclock frequency query from GpuAgent to driver layer to improve
code organization and support multiple driver types. This change:

1. Add GetWallclockFrequency API to KFD/XDNA drivers
2. Move libdrm GPU info query from GpuAgent to driver implementation
3. Update GpuAgent to use the new driver API

Signed-off-by: Honglei Huang <Honglei1.Huang@amd.com>
이 커밋은 다음에 포함됨:
Honglei Huang
2025-06-30 14:41:19 +08:00
커밋한 사람 Huang, Honglei1
부모 9bc38e2ee6
커밋 412e386b50
6개의 변경된 파일34개의 추가작업 그리고 7개의 파일을 삭제
+16
파일 보기
@@ -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<void**>(&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
+4
파일 보기
@@ -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
+1
파일 보기
@@ -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;
+1
파일 보기
@@ -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;
+7
파일 보기
@@ -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_;
+5 -7
파일 보기
@@ -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