Skip to content

[BUILD] Modularize device runtime into per-backend DSOs#19593

Closed
tqchen wants to merge 1 commit into
apache:mainfrom
tqchen:runtime-modularize
Closed

[BUILD] Modularize device runtime into per-backend DSOs#19593
tqchen wants to merge 1 commit into
apache:mainfrom
tqchen:runtime-modularize

Conversation

@tqchen
Copy link
Copy Markdown
Member

@tqchen tqchen commented May 21, 2026

Summary

Modularize libtvm_runtime into per-backend shared libraries (libtvm_runtime_cuda, libtvm_runtime_vulkan, etc.) and libtvm_runtime_extra for contrib/disco modules.

  • Each backend can be built independently (USE_CUDA=ON produces only libtvm_runtime.so + libtvm_runtime_cuda.so)
  • During Python import, available backend DSOs are discovered and loaded automatically, with missing backends silently skipped
  • libtvm_runtime_extra is always produced if it has sources (disco, contrib modules)
  • No user-visible config flag changes — existing USE_CUDA, USE_VULKAN, etc. continue to work

Test plan

  • Build with USE_CUDA=ON — verify libtvm_runtime.so, libtvm_runtime_cuda.so, libtvm_runtime_extra.so produced
  • python -c "import tvm; print(tvm.cuda(0).exist)" prints True
  • Runtime GPU tests pass
  • Moving libtvm_runtime_cuda.so out of lib/ — CUDA unavailable, no crash

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the TVM runtime build system to split the monolithic runtime into a core library, per-backend dynamic shared objects (DSOs) for CUDA, Vulkan, OpenCL, Metal, ROCm, and Hexagon, and a separate libtvm_runtime_extra library for contrib and disco sources. Correspondingly, the Python loading logic was updated to dynamically discover and load these backend DSOs. Review feedback identified a missing compile definition for the cuDNN frontend and a package naming inconsistency in the library loading utility that could lead to resolution failures.

Comment thread cmake/modules/CUDA.cmake Outdated
Comment thread python/tvm/libinfo.py Outdated
@tqchen tqchen force-pushed the runtime-modularize branch from 9c78db7 to 0a12a3c Compare May 21, 2026 14:49
@tqchen
Copy link
Copy Markdown
Member Author

tqchen commented May 21, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the TVM runtime build system to split backend-specific code (CUDA, Vulkan, OpenCL, Metal, ROCm, Hexagon) and various contrib modules into separate dynamic shared libraries, specifically introducing libtvm_runtime_extra. This change allows for a more modular runtime and dynamic loading of backends in Python. Feedback includes concerns regarding regressions for monolithic Hexagon DSP builds where Disco sources might be missing, the need to gate the creation of the extra runtime library for Hexagon, and improving the robustness of the CMake logic when no extra sources are present.

Comment thread CMakeLists.txt
Comment thread CMakeLists.txt
include(cmake/modules/contrib/vllm.cmake)
include(cmake/modules/Git.cmake)

# ---- libtvm_runtime_extra assembly ----
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The libtvm_runtime_extra assembly block should be gated to avoid creating a shared library when building for the Hexagon DSP (BUILD_FOR_HEXAGON). Hexagon DSP builds typically use static linking and a monolithic runtime, and the standard shared library mechanism used here may not be appropriate for the DSP environment.

# ---- libtvm_runtime_extra assembly ----
if(NOT BUILD_FOR_HEXAGON)

Comment thread CMakeLists.txt Outdated
@tqchen tqchen force-pushed the runtime-modularize branch 9 times, most recently from 029ad2c to 31200ba Compare May 21, 2026 19:01
Modularize libtvm_runtime into per-backend shared libraries
(libtvm_runtime_cuda, libtvm_runtime_vulkan, etc.) and
libtvm_runtime_extra for contrib/disco modules.

Each backend can be built independently. During Python import,
available backend DSOs are discovered and loaded automatically,
with missing backends silently skipped.
@tqchen tqchen force-pushed the runtime-modularize branch from 31200ba to 3e89882 Compare May 22, 2026 02:21
@tqchen
Copy link
Copy Markdown
Member Author

tqchen commented May 22, 2026

Reopening from upstream branch to pick up Jenkins groovy changes.

@tqchen tqchen closed this May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants