This is an automated email from the ASF dual-hosted git repository.

tlopex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 0b0a2fda04 [CMAKE][RUNTIME] Link tvm_rpc with all backend runtime 
libraries (#19617)
0b0a2fda04 is described below

commit 0b0a2fda0405dc78dd7d1986a891a5faafcbd620
Author: Balint Cristian <[email protected]>
AuthorDate: Wed May 27 04:39:36 2026 +0300

    [CMAKE][RUNTIME] Link tvm_rpc with all backend runtime libraries (#19617)
    
    In continuation of https://github.com/apache/tvm/pull/19594 **(DSO
    modularization)**, fixes for```tvm_rpc``` backend pickups
    
    ---
    
    ### Issue
    
    * Errors during remote ```tvm_rpc``` metaschedule sessions:
      ```
    AttributeError: Unable to find function
    "tvm.contrib.random.random_fill_for_measure"
    on the remote RPC server. Please make sure 'USE_RANDOM' is turned ON in
    the config.cmake
      on the RPC server.
      ```
    This error is due to missing ```libtvm_runtime_extra.so``` (home of
    contrib modules, e.g *random*) from ```tvm_rpc```.
    
    ----
    
    ### Fixes
    
    * Before:
    ```
    # readelf -a /usr/bin/tvm_rpc | grep NEED
      [ 7] .gnu.version_r    VERNEED          0000000000403a88  00003a88
     0x0000000000000001 (NEEDED)             Shared library: [libtvm_runtime.so]
     0x0000000000000001 (NEEDED)             Shared library: [libtvm_ffi.so]
     0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
     0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
    ```
    
    * After:
    ```
    # readelf -a /usr/bin/tvm_rpc | grep NEED
      [ 7] .gnu.version_r    VERNEED          0000000000404ed0  00004ed0
     0x0000000000000001 (NEEDED)             Shared library: 
[libtvm_runtime_extra.so]
     0x0000000000000001 (NEEDED)             Shared library: 
[libtvm_runtime_cuda.so]
     0x0000000000000001 (NEEDED)             Shared library: 
[libtvm_runtime_opencl.so]
     0x0000000000000001 (NEEDED)             Shared library: [libtvm_runtime.so]
     0x0000000000000001 (NEEDED)             Shared library: [libtvm_ffi.so]
     0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
     0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
     0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
    ```
    
    Thank you !
---
 CMakeLists.txt              |  2 ++
 apps/cpp_rpc/CMakeLists.txt | 16 ++++++++++++++--
 cmake/modules/CUDA.cmake    |  1 +
 cmake/modules/Hexagon.cmake |  1 +
 cmake/modules/Metal.cmake   |  1 +
 cmake/modules/OpenCL.cmake  |  1 +
 cmake/modules/ROCM.cmake    |  1 +
 cmake/modules/Vulkan.cmake  |  1 +
 8 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 63d05da353..6c35af4b95 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -113,9 +113,11 @@ include_directories(SYSTEM ${COMPILER_RT_PATH})
 # initial variables
 set(TVM_LINKER_LIBS "")
 set(TVM_RUNTIME_LINKER_LIBS "")
+set(TVM_RUNTIME_BACKEND_LIBS "")
 # Early target creation so contrib cmake files can call
 # target_link_libraries(tvm_runtime_extra PRIVATE <object_lib>) directly.
 add_library(tvm_runtime_extra SHARED)
+list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_extra)
 set_target_properties(tvm_runtime_extra PROPERTIES LINKER_LANGUAGE CXX)
 # INTERFACE target carrying compile definitions for OBJECT libs that build
 # into tvm_runtime_extra. On MSVC, TVM_RUNTIME_EXPORTS makes TVM_RUNTIME_DLL
diff --git a/apps/cpp_rpc/CMakeLists.txt b/apps/cpp_rpc/CMakeLists.txt
index b65d66b560..f8e0a05690 100644
--- a/apps/cpp_rpc/CMakeLists.txt
+++ b/apps/cpp_rpc/CMakeLists.txt
@@ -62,9 +62,21 @@ if (BUILD_FOR_ANDROID AND USE_HEXAGON)
 endif()
 
 if(BUILD_STATIC_RUNTIME)
-  list(APPEND TVM_RPC_LINKER_LIBS -Wl,--whole-archive tvm_runtime 
tvm_ffi_static -Wl,--no-whole-archive)
+  foreach(lib ${TVM_RUNTIME_BACKEND_LIBS})
+    if(MSVC)
+      list(APPEND TVM_RPC_LINKER_LIBS "/WHOLEARCHIVE:$<TARGET_FILE:${lib}>")
+    elseif(APPLE)
+      list(APPEND TVM_RPC_LINKER_LIBS "-Wl,-force_load,$<TARGET_FILE:${lib}>")
+    else()
+      list(APPEND TVM_RPC_LINKER_LIBS "-Wl,--whole-archive" "${lib}" 
"-Wl,--no-whole-archive")
+    endif()
+  endforeach()
 else()
-  list(APPEND TVM_RPC_LINKER_LIBS tvm_runtime)
+  if(NOT MSVC AND NOT APPLE)
+    list(APPEND TVM_RPC_LINKER_LIBS tvm_runtime "-Wl,--no-as-needed" 
${TVM_RUNTIME_BACKEND_LIBS} "-Wl,--as-needed")
+  else()
+    list(APPEND TVM_RPC_LINKER_LIBS tvm_runtime ${TVM_RUNTIME_BACKEND_LIBS})
+  endif()
 endif()
 
 target_link_libraries(tvm_rpc PRIVATE ${TVM_RPC_LINKER_LIBS})
diff --git a/cmake/modules/CUDA.cmake b/cmake/modules/CUDA.cmake
index e56396c1a6..4492cef900 100644
--- a/cmake/modules/CUDA.cmake
+++ b/cmake/modules/CUDA.cmake
@@ -72,6 +72,7 @@ if(USE_CUDA)
     target_compile_options(tvm_runtime_cuda_objs PRIVATE 
"${TVM_VISIBILITY_FLAG}")
   endif()
   add_library(tvm_runtime_cuda SHARED $<TARGET_OBJECTS:tvm_runtime_cuda_objs>)
+  list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_cuda)
   target_link_libraries(tvm_runtime_cuda PUBLIC tvm_runtime 
${CUDA_CUDART_LIBRARY} ${CUDA_CUDA_LIBRARY})
   set_target_properties(tvm_runtime_cuda PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
diff --git a/cmake/modules/Hexagon.cmake b/cmake/modules/Hexagon.cmake
index 370d968e62..9ddd677a66 100644
--- a/cmake/modules/Hexagon.cmake
+++ b/cmake/modules/Hexagon.cmake
@@ -344,6 +344,7 @@ elseif(USE_HEXAGON)
     target_compile_options(tvm_runtime_hexagon_objs PRIVATE 
"${TVM_VISIBILITY_FLAG}")
   endif()
   add_library(tvm_runtime_hexagon SHARED 
$<TARGET_OBJECTS:tvm_runtime_hexagon_objs>)
+  list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_hexagon)
   target_link_libraries(tvm_runtime_hexagon PUBLIC tvm_runtime)
   set_target_properties(tvm_runtime_hexagon PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
diff --git a/cmake/modules/Metal.cmake b/cmake/modules/Metal.cmake
index 73ba1f5d6a..72e7585534 100644
--- a/cmake/modules/Metal.cmake
+++ b/cmake/modules/Metal.cmake
@@ -28,6 +28,7 @@ if(USE_METAL)
     target_compile_options(tvm_runtime_metal_objs PRIVATE 
"${TVM_VISIBILITY_FLAG}")
   endif()
   add_library(tvm_runtime_metal SHARED 
$<TARGET_OBJECTS:tvm_runtime_metal_objs>)
+  list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_metal)
   target_link_libraries(tvm_runtime_metal PUBLIC tvm_runtime ${METAL_LIB} 
${FOUNDATION_LIB})
   set_target_properties(tvm_runtime_metal PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
diff --git a/cmake/modules/OpenCL.cmake b/cmake/modules/OpenCL.cmake
index a90e9cfe14..9a1c20a5a5 100644
--- a/cmake/modules/OpenCL.cmake
+++ b/cmake/modules/OpenCL.cmake
@@ -44,6 +44,7 @@ if(USE_OPENCL)
     target_compile_options(tvm_runtime_opencl_objs PRIVATE 
"${TVM_VISIBILITY_FLAG}")
   endif()
   add_library(tvm_runtime_opencl SHARED 
$<TARGET_OBJECTS:tvm_runtime_opencl_objs>)
+  list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_opencl)
   target_link_libraries(tvm_runtime_opencl PUBLIC tvm_runtime ${_opencl_libs})
   set_target_properties(tvm_runtime_opencl PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
diff --git a/cmake/modules/ROCM.cmake b/cmake/modules/ROCM.cmake
index bc0159377b..d502484cc7 100644
--- a/cmake/modules/ROCM.cmake
+++ b/cmake/modules/ROCM.cmake
@@ -46,6 +46,7 @@ if(USE_ROCM)
     target_compile_options(tvm_runtime_rocm_objs PRIVATE 
"${TVM_VISIBILITY_FLAG}")
   endif()
   add_library(tvm_runtime_rocm SHARED $<TARGET_OBJECTS:tvm_runtime_rocm_objs>)
+  list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_rocm)
   target_link_libraries(tvm_runtime_rocm PUBLIC tvm_runtime ${_rocm_libs})
   set_target_properties(tvm_runtime_rocm PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
diff --git a/cmake/modules/Vulkan.cmake b/cmake/modules/Vulkan.cmake
index c64e5581c9..6821b4419b 100644
--- a/cmake/modules/Vulkan.cmake
+++ b/cmake/modules/Vulkan.cmake
@@ -53,6 +53,7 @@ if(USE_VULKAN)
     target_compile_options(tvm_runtime_vulkan_objs PRIVATE 
"${TVM_VISIBILITY_FLAG}")
   endif()
   add_library(tvm_runtime_vulkan SHARED 
$<TARGET_OBJECTS:tvm_runtime_vulkan_objs>)
+  list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_vulkan)
   target_link_libraries(tvm_runtime_vulkan PUBLIC tvm_runtime 
${Vulkan_LIBRARY})
   set_target_properties(tvm_runtime_vulkan PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"

Reply via email to