Skip to content

[python] Support find_libraries and preload_libraries on Windows. - #898

Merged
ScottTodd merged 5 commits into
mainfrom
users/scotttodd/windows-python-find-libraries
Jun 24, 2025
Merged

ScottTodd merged 5 commits into
mainfrom
users/scotttodd/windows-python-find-libraries

Conversation

@ScottTodd

Copy link
Copy Markdown
Member

Progress on #827. Latest rocm-sdk test output: https://gist.github.com/ScottTodd/23955d6a89643a1217e2184af09bd17c.

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

Next, I'll modify external-builds/pytorch/build_prod_wheels.py to work on Windows. That might require adding a amd_comgr preload to pytorch by amending 0015-Preload-rocm-sdk-binaries-if-available.patch.

We may want to track a dependency graph between these libraries so preloading one library also loads its dependencies. I can either manually snapshot such a graph by running dlls files through https://github.com/lucasg/Dependencies or we can populate dynamically using our existing build system logic somehow.

Note: probably requires adding `amd_comgr` preload to pytorch (can amend that patch)
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...).

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
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.

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
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)

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
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...

Base automatically changed from users/scotttodd/windows-python-console-scripts-2 to main June 24, 2025 17:18
Comment on lines +37 to +38
if not lib_entry.dllname:

if is_windows and not lib_entry.dllname:

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.

Oops, almost merged with a bug. We need to start testing these packages on PRs, not just with nightly jobs.

@ScottTodd
ScottTodd merged commit d783b09 into main Jun 24, 2025
@ScottTodd
ScottTodd deleted the users/scotttodd/windows-python-find-libraries branch June 24, 2025 21:38
@github-project-automation github-project-automation Bot moved this from TODO to Done in TheRock Triage Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants