Skip to content

[REFACTOR][RUNTIME] Structural reorganization: locality moves for thread_map, texture, minrpc, disco, contrib#19628

Merged
tlopex merged 7 commits into
apache:mainfrom
tqchen:tvm-runtime-structure-reorg
May 27, 2026
Merged

[REFACTOR][RUNTIME] Structural reorganization: locality moves for thread_map, texture, minrpc, disco, contrib#19628
tlopex merged 7 commits into
apache:mainfrom
tqchen:tvm-runtime-structure-reorg

Conversation

@tqchen
Copy link
Copy Markdown
Member

@tqchen tqchen commented May 27, 2026

Background

The TVM runtime has been growing organically. Several headers and directories
live at the top level of src/runtime/ despite only being consumed by a
single backend subsystem. This PR applies the locality principle: code that
has exactly one consumer moves to live next to that consumer.

Changes

Move 1: thread_map.hsrc/runtime/vulkan/

ThreadMap is only used by Vulkan device API headers. Moving it under
src/runtime/vulkan/ reflects this exclusive ownership.

Move 2: texture.hsrc/runtime/opencl/

Texture storage utilities are OpenCL/Adreno-specific. Moving the header
under src/runtime/opencl/ makes ownership clear.

Move 3: minrpc/src/runtime/rpc/minrpc/

The minrpc mini-RPC implementation belongs logically under the existing
src/runtime/rpc/ subtree. All consumers already live under rpc/ or
reference it as a child of rpc/.

Move 4: Introduce src/runtime/extra/ boundary

disco/ and contrib/ are the sole source directories for
libtvm_runtime_extra. Grouping them under src/runtime/extra/ makes the
libtvm_runtime_extra build boundary visible in the filesystem, matching
the modular runtime split introduced in #19444.

  • src/runtime/disco/src/runtime/extra/disco/
  • src/runtime/contrib/src/runtime/extra/contrib/
  • Public include/tvm/runtime/disco/ is unchanged.

Drive-by fixes

  • apps/android_rpc/…/tvm_runtime.h: Drop stale minrpc_logger.cc include
    (file no longer exists) and fix stale tvm-ffi/src/ffi/extra/testing.cc
    path to tvm-ffi/src/ffi/testing/testing.cc.

Test Plan

  • Full build (ninja -j$(nproc)) — succeeds
  • ./cpptest — 118 tests passed
  • Python smoke: tvm.__version__ + tvm.cuda(0).exist — pass
  • tests/python/all-platform-minimal-test — 37 passed, 105 skipped
  • tests/python/runtime/test_runtime_rpc.py — 2 passed, 21 skipped
  • tests/python/runtime/test_rpc_base.py — 2 passed
  • pre-commit run --all-files — all hooks pass

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 restructures the TVM runtime directory layout by moving several components under new subdirectories. Specifically, it relocates various contrib and disco runtime sources to src/runtime/extra/ and moves the minrpc sources under src/runtime/rpc/minrpc/. CMake build files, C++ source files, and Python scripts have been updated to reflect these new header and source paths. There are no review comments, so I have no additional feedback to provide.

@tqchen tqchen force-pushed the tvm-runtime-structure-reorg branch from 388d38d to a01802e Compare May 27, 2026 19:34
tqchen added 7 commits May 27, 2026 19:41
ThreadMap is a header-only template used exclusively by the Vulkan
backend (vulkan_device.h and vulkan_device_api.h). Keeping it at
the runtime top-level forces every reader of the directory listing to
reason about which backend a file belongs to.

Moving it to src/runtime/vulkan/ makes the single-consumer relationship
visible from the file system. Two relative includes update from
"../thread_map.h" to "thread_map.h". Header guard updated from
TVM_RUNTIME_THREAD_MAP_H_ to TVM_RUNTIME_VULKAN_THREAD_MAP_H_
to reflect the new path. No CMake changes needed (header-only file
not listed explicitly).
texture.h is a header-only utility consumed exclusively by the OpenCL
backend through opencl_common.h. Placing it at the runtime top-level
obscures this single-consumer relationship.

Moving it to src/runtime/opencl/ groups the file with its sole consumer.
One relative include in opencl_common.h updates from "../texture.h" to
"texture.h". Header guard updated from TVM_RUNTIME_TEXTURE_H_ to
TVM_RUNTIME_OPENCL_TEXTURE_H_ to reflect the new path. No CMake
changes needed (header-only).
minrpc implements a minimal RPC protocol that shares rpc_reference.h
with the standard RPC transport in src/runtime/rpc/. Nesting minrpc/
under rpc/ makes that structural relationship explicit on the file
system and removes it from the runtime top-level.

Changes:
- src/runtime/minrpc/ → src/runtime/rpc/minrpc/ (3 files + posix_popen_server/)
- rpc_endpoint.h, rpc_session.h: "../minrpc/rpc_reference.h" → "minrpc/rpc_reference.h"
- disco/protocol.h, process_session.cc, threaded_session.cc:
  "../minrpc/rpc_reference.h" → "../rpc/minrpc/rpc_reference.h"
- hexagon/rpc/{hexagon,simulator}/rpc_server.cc:
  "../../../minrpc/minrpc_server.h" → "../../../rpc/minrpc/minrpc_server.h"
- CMakeLists.txt: RUNTIME_SRCS glob src/runtime/minrpc/*.cc → src/runtime/rpc/minrpc/*.cc
- cmake/modules/Hexagon.cmake: two explicit header list entries updated
- python/tvm/rpc/minrpc.py: path constant for -I flag and server.cc source
  updated from src/runtime/minrpc to src/runtime/rpc/minrpc

Header guards in minrpc_server.h and rpc_reference.h already encode
TVM_RUNTIME_MINRPC_*, which remain correct after the move.
…xtra

The sources that feed the libtvm_runtime_extra build target — disco and
contrib — were scattered at the runtime top level alongside sources that
feed libtvm_runtime. Making them a subdir makes the build-target boundary
visible from the file system.

Moves:
- src/runtime/disco/ → src/runtime/extra/disco/
- src/runtime/contrib/ → src/runtime/extra/contrib/

Public headers under include/tvm/runtime/disco/ are NOT moved — they are
consumed by core runtime (vm/paged_kv_cache.cc) and do not belong in the
extra-private source tree.

All internal relative includes that previously traversed from
src/runtime/{disco,contrib}/<pkg>/ to sibling runtime directories
(cuda/, opencl/, rocm/, memory/, etc.) have had one extra `../` added to
account for the deeper nesting.

CMake updates:
- CMakeLists.txt: all src/runtime/{disco,contrib}/ path strings updated
- cmake/modules/CUDA.cmake, ROCM.cmake: contrib glob paths updated
- cmake/modules/contrib/{AMX,BLAS,CLML,CoreML,CUTLASS,DNNL,ExampleNPU,
  NNAPI,Random,Sort,TensorRT,vllm}.cmake: all paths updated

External references:
- src/relax/backend/contrib/codegen_json/codegen_json.h: two includes of
  runtime/contrib/json/ updated to runtime/extra/contrib/json/
- web/emcc/wasm_runtime.cc: sort.cc amalgamation include updated
Two pre-existing stale includes in apps/android_rpc/app/src/main/jni/tvm_runtime.h:

1. Drop the include of "../src/runtime/minrpc/minrpc_logger.cc". This file
   has not existed in the tree for some time; the include was silently broken.

2. Drop "../3rdparty/tvm-ffi/src/ffi/extra/testing.cc" entirely. The tvm-ffi
   testing translation unit is test-only and not needed by the android runtime
   amalgamation; removing it rather than following the path rename.

3. Update sort.cc and random.cc paths to src/runtime/extra/contrib/ following
   the src/runtime/extra/ reorganization in this series.
Four files outside of src/runtime/opencl/ referenced texture.h via its
old path at src/runtime/texture.h. The move audit (commit 2) only checked
for direct includees of opencl_common.h; these callers include texture.h
directly and were not caught.

Update the include path in all four files to src/runtime/opencl/texture.h:
- src/relax/transform/static_plan_block_memory.cc
- src/s_tir/backend/adreno/inject_texture_alloc.cc
- src/s_tir/backend/adreno/texture_flatten.cc
- src/target/opencl/codegen_opencl.cc
Apply clang-format ordering fixes to include directives changed by the
runtime reorganization commits. All changes are include reorderings only.
@tqchen tqchen force-pushed the tvm-runtime-structure-reorg branch from a01802e to 280852a Compare May 27, 2026 19:52
@tlopex tlopex merged commit 23db01f into apache:main May 27, 2026
10 checks passed
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