Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def find_libraries(*shortnames: str) -> list[Path]:
lib_entry = _dist_info.ALL_LIBRARIES[shortname]
except KeyError:
raise ModuleNotFoundError(f"Unknown rocm library '{shortname}'")

if is_windows and not lib_entry.dllname:
# Library is missing on Windows, skip it.
# TODO(#827): Require callers to filter and error here instead?
continue

package = lib_entry.package
target_family = None
if package.is_target_specific:
Expand All @@ -44,8 +50,10 @@ def find_libraries(*shortnames: str) -> list[Path]:
except ModuleNotFoundError:
missing_extras.add(package.logical_name)
py_root = Path(py_module.__file__).parent # Chop __init__.py
assert not is_windows, "rocm_sdk.find_libraries not yet supported on Windows"
path = py_root / lib_entry.posix_relpath / lib_entry.soname
if is_windows:
path = py_root / lib_entry.windows_relpath / lib_entry.dllname
else:
path = py_root / lib_entry.posix_relpath / lib_entry.soname
if not path.exists():
raise FileNotFoundError(
f"Could not find rocm library '{shortname}' at path {path}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ class LibraryEntry:
"""Defines a public library that can be located by name within the overall
distribution."""

def __init__(self, shortname: str, package_name: str, soname: str):
def __init__(self, shortname: str, package_name: str, soname: str, dllname: str):
self.shortname = shortname
self.package = ALL_PACKAGES[package_name]
self.posix_relpath = "lib"
self.windows_relpath = "bin"
self.soname = soname
self.dllname = dllname
assert shortname not in ALL_LIBRARIES
ALL_LIBRARIES[shortname] = self

def __repr__(self):
return f"{self.shortname}(soname={self.soname}, package={self.package})"
return f"{self.shortname}(soname={self.soname}, dllname={self.dllname}, package={self.package})"


class PackageEntry:
Expand Down Expand Up @@ -157,20 +158,23 @@ def determine_target_family() -> str:
required=False,
)

# TODO(#703): Use patterns for version suffixes and platform differences.

# Public libraries.
LibraryEntry("amdhip64", "core", "libamdhip64.so.6")
LibraryEntry("hiprtc", "core", "libhiprtc.so.6")
LibraryEntry("roctx64", "core", "libroctx64.so.4")
LibraryEntry("rocprofiler-sdk-roctx", "core", "librocprofiler-sdk-roctx.so.1")

LibraryEntry("hipblas", "libraries", "libhipblas.so.3")
LibraryEntry("hipfft", "libraries", "libhipfft.so.0")
LibraryEntry("hiprand", "libraries", "libhiprand.so.1")
LibraryEntry("hipsparse", "libraries", "libhipsparse.so.4")
LibraryEntry("hipsolver", "libraries", "libhipsolver.so.1")
LibraryEntry("rccl", "libraries", "librccl.so.1")
LibraryEntry("hipblaslt", "libraries", "libhipblaslt.so.1")
LibraryEntry("miopen", "libraries", "libMIOpen.so.1")
LibraryEntry("amdhip64", "core", "libamdhip64.so.6", "amdhip64_6.dll")
LibraryEntry("hiprtc", "core", "libhiprtc.so.6", "hiprtc0605.dll")
LibraryEntry("roctx64", "core", "libroctx64.so.4", "")
LibraryEntry("rocprofiler-sdk-roctx", "core", "librocprofiler-sdk-roctx.so.1", "")

LibraryEntry("amd_comgr", "core", "libamd_comgr.so.3", "amd_comgr0605.dll")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the amd_comgr library definition, since MIOpen.dll depends on hiprtc0605.dll (already added) and amd_comgr0605.dll (was missing).

I tested with a Python program modeled after the pytorch init code:

import rocm_sdk

rocm_sdk.find_libraries("amdhip64")

rocm_sdk.preload_libraries(
    "amdhip64",
    # Enable once aqlprofiler is available.
    "rocprofiler-sdk-roctx",
    "hiprtc",
    "hipblas",
    "hipfft",
    "hiprand",
    "hipsparse",
    "hipsolver",
    "rccl",
    "hipblaslt",
    # "amd_comgr",  # required for miopen
    "miopen",
)

Output:

Preloading paths:
  D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\_rocm_sdk_core\bin\amdhip64_6.dll
  D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\_rocm_sdk_core\bin\hiprtc0605.dll
  D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\_rocm_sdk_libraries_gfx110X_dgpu\bin\hipfft.dll
  D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\_rocm_sdk_libraries_gfx110X_dgpu\bin\hiprand.dll
  D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\_rocm_sdk_libraries_gfx110X_dgpu\bin\hipsparse.dll
  D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\_rocm_sdk_libraries_gfx110X_dgpu\bin\hipsolver.dll
  D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\_rocm_sdk_libraries_gfx110X_dgpu\bin\hipblaslt.dll
  D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\_rocm_sdk_libraries_gfx110X_dgpu\bin\MIOpen.dll
Traceback (most recent call last):
  File "D:\scratch\check_rocmsdk.py", line 5, in <module>
    rocm_sdk.preload_libraries(
  File "D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\rocm_sdk\__init__.py", line 106, in preload_libraries
    cdll = ctypes.CDLL(str(path), mode=mode)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\ctypes\__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: Could not find module 'D:\scratch\therock\python_rocm_2\.venv\Lib\site-packages\_rocm_sdk_libraries_gfx110X_dgpu\bin\MIOpen.dll' (or one of its dependencies). Try using the full path with constructor syntax.

Here's the GUI view of Dependencies for MIOpen.dll:
image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I need to double check this. I had been building from incomplete artifacts fetched by https://github.com/ROCm/TheRock/blob/main/build_tools/fetch_artifacts.py instead of a complete artifacts list from a source build (or cloud download command). Really need to fix that script or at least give it a --all-yes-really-everything mode.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems plausible. It is legal for people to depend directly on comgr, although most people get it via hip APIs. So fine to add.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ideally, such internal dependencies should happen happen automatically... but windows and I know you aren't there yet)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd love to extend this at some point to inspect the COFF file and display a nicer error message and give the information that the depends gui does. These errors are deadly in the field to debug...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'll flush what I can to get the wheels working and building with automation then we can go back and widen the support path (famous last words...).

Comment thread
ScottTodd marked this conversation as resolved.
Resolved
LibraryEntry("hipblas", "libraries", "libhipblas.so.3", "libhipblas.dll")
LibraryEntry("hipfft", "libraries", "libhipfft.so.0", "hipfft.dll")
LibraryEntry("hiprand", "libraries", "libhiprand.so.1", "hiprand.dll")
LibraryEntry("hipsparse", "libraries", "libhipsparse.so.4", "hipsparse.dll")
LibraryEntry("hipsolver", "libraries", "libhipsolver.so.1", "hipsolver.dll")
LibraryEntry("rccl", "libraries", "librccl.so.1", "")
LibraryEntry("hipblaslt", "libraries", "libhipblaslt.so.1", "hipblaslt.dll")
LibraryEntry("miopen", "libraries", "libMIOpen.so.1", "MIOpen.dll")

# Overall ROCM package version.
__version__ = "DEFAULT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,25 @@
so_paths = utils.get_module_shared_libraries(core_mod)
is_windows = platform.system() == "Windows"


CONSOLE_SCRIPT_TESTS = [
LINUX_CONSOLE_SCRIPT_TESTS = [
# These currently only have unprefixed names (e.g. 'clang') on Windows.
("amdclang", ["--help"], "clang LLVM compiler", True),
("amdclang++", ["--help"], "clang LLVM compiler", True),
("amdclang-cpp", ["--help"], "clang LLVM compiler", True),
("amdclang-cl", ["-help"], "clang LLVM compiler", True),
("amdflang", ["--help"], "clang LLVM compiler", True),
("amdlld", ["-flavor", "ld.lld", "--help"], "USAGE:", True),
("hipcc", ["--help"], "clang LLVM compiler", True),
("hipconfig", [], "HIP version:", True),
# These tools are only available on Linux.
("rocm_agent_enumerator", [], "", not is_windows),
("rocminfo", [], "", not is_windows),
("rocm-smi", [], "Management", not is_windows),
("rocm_agent_enumerator", [], "", True),
("rocminfo", [], "", True),
("rocm-smi", [], "Management", True),
]

CONSOLE_SCRIPT_TESTS = [
("hipcc", ["--help"], "clang LLVM compiler", True),
("hipconfig", [], "HIP version:", True),
] + (LINUX_CONSOLE_SCRIPT_TESTS if not is_windows else [])

exe_suffix = ".exe" if is_windows else ""


Expand Down