diff --git a/scripts/rocm/rocm_mgr.py b/scripts/rocm/rocm_mgr.py index bb6b2c9a3..61fbe1456 100644 --- a/scripts/rocm/rocm_mgr.py +++ b/scripts/rocm/rocm_mgr.py @@ -115,8 +115,59 @@ def _get_root() -> str: return str(script_path) +_libs_pkg_cache: Optional[str] = None + +def _get_libs_pkg() -> str: + """Return the _rocm_sdk_libraries_ folder name present in site-packages, or ''. + + Scans site-packages for a directory matching '_rocm_sdk_libraries_*'. + When multiple are found (unusual), prefers the one matching the detected GPU + via modules.rocm; falls back to the first candidate. + Result is cached for the process lifetime. + """ + global _libs_pkg_cache # pylint: disable=global-statement + if _libs_pkg_cache is not None: + return _libs_pkg_cache + import sysconfig # pylint: disable=import-outside-toplevel + site_pkgs = sysconfig.get_path('purelib') + if not site_pkgs or not os.path.isdir(site_pkgs): + _libs_pkg_cache = "" + return "" + try: + candidates = [e for e in os.listdir(site_pkgs) if e.startswith("_rocm_sdk_libraries_")] + except OSError: + _libs_pkg_cache = "" + return "" + if not candidates: + _libs_pkg_cache = "" + return "" + if len(candidates) == 1: + _libs_pkg_cache = candidates[0] + return _libs_pkg_cache + # Multiple libraries packages — pick the one matching the active GPU + try: + from modules import rocm as _rocm # pylint: disable=import-outside-toplevel + import torch # pylint: disable=import-outside-toplevel + for i in range(torch.cuda.device_count()): + agent = _rocm.Agent(i) + therock = agent.therock + if therock: + suffix = therock.split("/")[-1].replace("-", "_") + folder = "_rocm_sdk_libraries_" + suffix + if folder in candidates: + _libs_pkg_cache = folder + return _libs_pkg_cache + except Exception: + pass + _libs_pkg_cache = candidates[0] + return _libs_pkg_cache + + def _expand_venv(value: str) -> str: - return value.replace("{VIRTUAL_ENV}", _get_venv()).replace("{ROOT}", _get_root()) + return (value + .replace("{VIRTUAL_ENV}", _get_venv()) + .replace("{ROOT}", _get_root()) + .replace("{LIBS_PKG}", _get_libs_pkg())) def _collapse_venv(value: str) -> str: diff --git a/scripts/rocm/rocm_vars.py b/scripts/rocm/rocm_vars.py index 1537d038b..431f41eb3 100644 --- a/scripts/rocm/rocm_vars.py +++ b/scripts/rocm/rocm_vars.py @@ -16,14 +16,14 @@ def _sitepackages_subpath(*parts: str) -> str: GENERAL_VARS: Dict[str, Dict[str, Any]] = { "MIOPEN_SYSTEM_DB_PATH": { - "default": _sitepackages_subpath("_rocm_sdk_devel", "bin") + os.sep, - "desc": "MIOpen system DB path", + "default": _sitepackages_subpath("{LIBS_PKG}", "bin") + os.sep, + "desc": "MIOpen system path", "widget": "textbox", "options": None, "restart_required": True, }, "ROCBLAS_TENSILE_LIBPATH": { - "default": _sitepackages_subpath("_rocm_sdk_devel", "bin", "rocblas", "library"), + "default": _sitepackages_subpath("{LIBS_PKG}", "bin", "rocblas", "library"), "desc": "rocBLAS Tensile library path", "widget": "textbox", "options": None, diff --git a/scripts/rocm_ext.py b/scripts/rocm_ext.py index 85c36adf5..463b186b2 100644 --- a/scripts/rocm_ext.py +++ b/scripts/rocm_ext.py @@ -47,22 +47,11 @@ class ROCmScript(scripts_manager.Script): section("ROCm / HIP") for k, v in d.get("rocm", {}).items(): row(k, v) - section("System DB") - sdb = d.get("system_db", {}) - row("path", sdb.get("path", "")) - for sub in ("solver_db", "find_db", "kernel_db"): - for fname, sz in sdb.get(sub, {}).items(): - row(sub.replace("_", " "), f"{fname}   {sz}") section("User DB (~/.miopen/db)") udb = d.get("user_db", {}) row("path", udb.get("path", "")) for fname, finfo in udb.get("files", {}).items(): row(fname, finfo) - section("User cache (~/.miopen/cache)") - ucache = d.get("user_cache", {}) - row("path", ucache.get("path", "")) - for fname, sz in ucache.get("files", {}).items(): - row(fname, sz) return f"{''.join(rows)}
" def _build_style(unavailable, hipblaslt_disabled=False):