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>
이 커밋은 다음에 포함됨:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
새 이슈에서 참조
사용자 차단