[REFACTOR][RUNTIME] Structural reorganization: locality moves for thread_map, texture, minrpc, disco, contrib#19628
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
388d38d to
a01802e
Compare
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.
a01802e to
280852a
Compare
tlopex
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 asingle 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.h→src/runtime/vulkan/ThreadMapis only used by Vulkan device API headers. Moving it undersrc/runtime/vulkan/reflects this exclusive ownership.Move 2:
texture.h→src/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/ orreference it as a child of rpc/.
Move 4: Introduce
src/runtime/extra/boundarydisco/andcontrib/are the sole source directories forlibtvm_runtime_extra. Grouping them undersrc/runtime/extra/makes thelibtvm_runtime_extrabuild boundary visible in the filesystem, matchingthe modular runtime split introduced in #19444.
src/runtime/disco/→src/runtime/extra/disco/src/runtime/contrib/→src/runtime/extra/contrib/include/tvm/runtime/disco/is unchanged.Drive-by fixes
apps/android_rpc/…/tvm_runtime.h: Drop staleminrpc_logger.ccinclude(file no longer exists) and fix stale
tvm-ffi/src/ffi/extra/testing.ccpath to
tvm-ffi/src/ffi/testing/testing.cc.Test Plan
ninja -j$(nproc)) — succeeds./cpptest— 118 tests passedtvm.__version__+tvm.cuda(0).exist— passtests/python/all-platform-minimal-test— 37 passed, 105 skippedtests/python/runtime/test_runtime_rpc.py— 2 passed, 21 skippedtests/python/runtime/test_rpc_base.py— 2 passedpre-commit run --all-files— all hooks pass