From e39ad34d9cbad0bd95d21ab3d5edd55cdcebab54 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 2 Dec 2022 00:49:26 +0000 Subject: [PATCH] Check for debug support after parsing topology Thunk keeps an internal cache of system topology that can be used to speed up subsequent calls to hsaKmtAcquireSystemProperties(). This cache is cleared by calling hsaKmtReleaseSystemProperties() at the beginning of BuildTopology(). hsaKmtRuntimeEnable() also calls hsaKmtAcquireSystemProperties() inside Thunk. Move call to hsaKmtRuntimeEnable() after BuildTopology() so that we can re-use Thunks internal cache. Parsing of of topology can take ~150 ms on systems for large number of nodes. Change-Id: I741709d49d67d244f5fbd707fe8f01ab923bb153 --- runtime/hsa-runtime/core/runtime/amd_topology.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/runtime/hsa-runtime/core/runtime/amd_topology.cpp b/runtime/hsa-runtime/core/runtime/amd_topology.cpp index 7da34e4aa5..264a5f30e0 100644 --- a/runtime/hsa-runtime/core/runtime/amd_topology.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_topology.cpp @@ -374,15 +374,21 @@ bool Load() { } MAKE_NAMED_SCOPE_GUARD(kfd, [&]() { hsaKmtCloseKFD(); }); + // Build topology table. + BuildTopology(); + // Register runtime and optionally enable the debugger + // BuildTopology calls hsaKmtAcquireSystemProperties() causes libhsakmt to cache topology + // information. So we need to call hsaKmtRuntimeEnable() after calling BuildTopology() so that + // Thunk can re-use it's cached copy instead of re-parsing whole system topology. Otherwise + // BuildTopology will cause libhsakmt to destroyed cached copy because it calls + // hsaKmtReleaseSystemProperties() at the beginning. + HSAKMT_STATUS err = hsaKmtRuntimeEnable(&_amdgpu_r_debug, core::Runtime::runtime_singleton_->flag().debug()); if ((err != HSAKMT_STATUS_SUCCESS) && (err != HSAKMT_STATUS_NOT_SUPPORTED)) return false; core::Runtime::runtime_singleton_->KfdVersion(err != HSAKMT_STATUS_NOT_SUPPORTED); - // Build topology table. - BuildTopology(); - kfd.Dismiss(); return true; }