You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by tq...@apache.org on 2026/10/15 02:38:59 UTC
(tvm) 07/16: [REFACTOR][Native] Export core declarations and retain parent runtime consumers
This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch tirx/standalone-package-cleanup
in repository https://gitbox.apache.org/repos/asf/tvm.git
commit 19ced11be244dfc775bc12fd253a25b95c80b0d9
Author: Tianqi Chen <tq...@users.noreply.github.com>
AuthorDate: Thu Oct 15 01:37:32 2026 +0000
[REFACTOR][Native] Export core declarations and retain parent runtime consumers
---
apps/android_rpc/app/src/main/jni/Android.mk | 2 +-
apps/android_rpc/app/src/main/jni/tvm_runtime.h | 20 ++++++++++----------
include/tvm/runtime/vm/executable.h | 2 +-
include/tvm/runtime/vm/tensor_cache_support.h | 8 ++++----
src/runtime/extra/contrib/clml/clml_runtime.h | 2 +-
src/runtime/extra/contrib/cublas/cublas.cc | 2 +-
src/runtime/extra/contrib/hipblas/hipblas.cc | 2 +-
src/runtime/extra/contrib/sort/sort.cc | 2 +-
src/runtime/rpc/rpc_socket_impl.cc | 4 ++--
src/runtime/vm/tensor_cache_support.cc | 4 ++--
tirx/include/tvm/codegen/codegen.h | 6 +++---
tirx/include/tvm/codegen/intrin_rule.h | 4 ++--
tirx/include/tvm/runtime/base.h | 19 +++++++++++++------
web/Makefile | 4 ++--
web/emcc/wasm_runtime.cc | 16 ++++++++--------
web/emcc/webgpu_runtime.cc | 2 +-
16 files changed, 53 insertions(+), 46 deletions(-)
diff --git a/apps/android_rpc/app/src/main/jni/Android.mk b/apps/android_rpc/app/src/main/jni/Android.mk
index b7540521c2..f38d54224a 100644
--- a/apps/android_rpc/app/src/main/jni/Android.mk
+++ b/apps/android_rpc/app/src/main/jni/Android.mk
@@ -36,7 +36,7 @@ include $(config)
LOCAL_SRC_FILES := org_apache_tvm_native_c_api.cc
LOCAL_LDFLAGS := -L$(SYSROOT)/usr/lib/ -llog
-LOCAL_C_INCLUDES := $(ROOT_PATH)/include \
+LOCAL_C_INCLUDES := $(ROOT_PATH)/include $(ROOT_PATH)/tirx/include \
$(ROOT_PATH)/3rdparty/tvm-ffi/include \
$(ROOT_PATH)/3rdparty/tvm-ffi/3rdparty/dlpack/include \
$(ROOT_PATH)/3rdparty/OpenCL-Headers
diff --git a/apps/android_rpc/app/src/main/jni/tvm_runtime.h b/apps/android_rpc/app/src/main/jni/tvm_runtime.h
index 40f1b76e56..fa5784e0d7 100644
--- a/apps/android_rpc/app/src/main/jni/tvm_runtime.h
+++ b/apps/android_rpc/app/src/main/jni/tvm_runtime.h
@@ -43,11 +43,11 @@
#include "../3rdparty/tvm-ffi/src/ffi/function.cc"
#include "../3rdparty/tvm-ffi/src/ffi/object.cc"
#include "../3rdparty/tvm-ffi/src/ffi/tensor.cc"
-#include "../src/runtime/cpu_device_api.cc"
-#include "../src/runtime/device_api.cc"
-#include "../src/runtime/logging.cc"
-#include "../src/runtime/memory_scope.cc"
-#include "../src/runtime/metadata.cc"
+#include "../tirx/src/runtime/cpu_device_api.cc"
+#include "../tirx/src/runtime/device_api.cc"
+#include "../tirx/src/runtime/logging.cc"
+#include "../tirx/src/runtime/memory_scope.cc"
+#include "../tirx/src/runtime/metadata.cc"
#include "../src/runtime/registry.cc"
#include "../src/runtime/rpc/rpc_channel.cc"
#include "../src/runtime/rpc/rpc_endpoint.cc"
@@ -57,12 +57,12 @@
#include "../src/runtime/rpc/rpc_server_env.cc"
#include "../src/runtime/rpc/rpc_session.cc"
#include "../src/runtime/rpc/rpc_socket_impl.cc"
-#include "../src/runtime/tensor.cc"
-#include "../src/runtime/thread_pool.cc"
-#include "../src/runtime/threading_backend.cc"
-#include "../src/runtime/timer.cc"
+#include "../tirx/src/runtime/tensor.cc"
+#include "../tirx/src/runtime/thread_pool.cc"
+#include "../tirx/src/runtime/threading_backend.cc"
+#include "../tirx/src/runtime/timer.cc"
#include "../src/runtime/vm/params.cc"
-#include "../src/runtime/workspace_pool.cc"
+#include "../tirx/src/runtime/workspace_pool.cc"
#ifdef TVM_OPENCL_RUNTIME
#include "../src/runtime/opencl/opencl_device_api.cc"
diff --git a/include/tvm/runtime/vm/executable.h b/include/tvm/runtime/vm/executable.h
index 5d4ff4aed3..6b1eecd1f2 100644
--- a/include/tvm/runtime/vm/executable.h
+++ b/include/tvm/runtime/vm/executable.h
@@ -85,7 +85,7 @@ struct VMFuncInfo {
* The executable contains information (e.g. data in different memory regions)
* to run in a virtual machine.
*/
-class TVM_RUNTIME_DLL VMExecutable : public ffi::ModuleObj {
+class TVM_RUNTIME_EXTRA_DLL VMExecutable : public ffi::ModuleObj {
public:
/*! \brief Get the property of the runtime module .*/
int GetPropertyMask() const final { return ffi::Module::kBinarySerializable; };
diff --git a/include/tvm/runtime/vm/tensor_cache_support.h b/include/tvm/runtime/vm/tensor_cache_support.h
index a02532124a..d5b1546e96 100644
--- a/include/tvm/runtime/vm/tensor_cache_support.h
+++ b/include/tvm/runtime/vm/tensor_cache_support.h
@@ -46,7 +46,7 @@ struct TensorCacheMetadata {
* \param staging_buffer The buffer to be used to avoid extra OpenCL copies. Pass in a nullptr
* in other cases
*/
- TVM_RUNTIME_DLL ffi::Tensor Load(Device device, const std::string* raw_data,
+ TVM_RUNTIME_EXTRA_DLL ffi::Tensor Load(Device device, const std::string* raw_data,
ffi::Optional<ffi::Tensor>* staging_buffer = nullptr) const;
/*! \brief Name of the parameter */
@@ -64,7 +64,7 @@ struct TensorCacheMetadata {
};
/*! \brief Load a FileRecord into memory */
- TVM_RUNTIME_DLL ffi::Array<ffi::Tensor> Load(
+ TVM_RUNTIME_EXTRA_DLL ffi::Array<ffi::Tensor> Load(
Device device, //
const std::string& path_prefix, //
std::string* raw_data_buffer, //
@@ -85,9 +85,9 @@ struct TensorCacheMetadata {
std::string path;
/*! \brief Load the metadata from a specific directory */
- TVM_RUNTIME_DLL static TensorCacheMetadata Load(const std::string& path);
+ TVM_RUNTIME_EXTRA_DLL static TensorCacheMetadata Load(const std::string& path);
/*! \brief Load the metadata from a given JSON string */
- TVM_RUNTIME_DLL static TensorCacheMetadata LoadFromStr(const std::string& json_str,
+ TVM_RUNTIME_EXTRA_DLL static TensorCacheMetadata LoadFromStr(const std::string& json_str,
const std::string& path);
};
diff --git a/src/runtime/extra/contrib/clml/clml_runtime.h b/src/runtime/extra/contrib/clml/clml_runtime.h
index df0b19b276..986088aaa0 100644
--- a/src/runtime/extra/contrib/clml/clml_runtime.h
+++ b/src/runtime/extra/contrib/clml/clml_runtime.h
@@ -50,7 +50,7 @@
#ifdef TVM_GRAPH_EXECUTOR_CLML
#include <CL/cl_qcom_ml_ops.h>
-#include "../../../../backend/opencl/runtime/opencl_common.h"
+#include "backend/opencl/runtime/opencl_common.h"
#define CAT_I(a, b) a##b
#define CAT(a, b) CAT_I(a, b)
diff --git a/src/runtime/extra/contrib/cublas/cublas.cc b/src/runtime/extra/contrib/cublas/cublas.cc
index 461bbee1f8..5c293fcd4b 100644
--- a/src/runtime/extra/contrib/cublas/cublas.cc
+++ b/src/runtime/extra/contrib/cublas/cublas.cc
@@ -27,7 +27,7 @@
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include "../../../../../3rdparty/compiler-rt/builtin_fp16.h"
+#include "builtin_fp16.h"
#include "../cblas/gemm_common.h"
#include "cublas_utils.h"
diff --git a/src/runtime/extra/contrib/hipblas/hipblas.cc b/src/runtime/extra/contrib/hipblas/hipblas.cc
index 18e136b0fd..f1e8f890ca 100644
--- a/src/runtime/extra/contrib/hipblas/hipblas.cc
+++ b/src/runtime/extra/contrib/hipblas/hipblas.cc
@@ -26,7 +26,7 @@
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include "../../../../../3rdparty/compiler-rt/builtin_fp16.h"
+#include "builtin_fp16.h"
#include "../cblas/gemm_common.h"
#include "hipblas_utils.h"
diff --git a/src/runtime/extra/contrib/sort/sort.cc b/src/runtime/extra/contrib/sort/sort.cc
index 6e3a99f935..8ef00c51f3 100644
--- a/src/runtime/extra/contrib/sort/sort.cc
+++ b/src/runtime/extra/contrib/sort/sort.cc
@@ -31,7 +31,7 @@
#include <algorithm>
#include <vector>
-#include "../../../../../3rdparty/compiler-rt/builtin_fp16.h"
+#include "builtin_fp16.h"
namespace tvm {
namespace contrib {
diff --git a/src/runtime/rpc/rpc_socket_impl.cc b/src/runtime/rpc/rpc_socket_impl.cc
index 7f7486d26c..cff92a17eb 100644
--- a/src/runtime/rpc/rpc_socket_impl.cc
+++ b/src/runtime/rpc/rpc_socket_impl.cc
@@ -115,8 +115,8 @@ ffi::Module RPCClientConnect(std::string url, int port, std::string key, bool en
return CreateRPCSessionModule(CreateClientSession(endpt));
}
-// TVM_RUNTIME_DLL needed for MSVC
-TVM_RUNTIME_DLL void RPCServerLoop(int sockfd) {
+// TVM_RUNTIME_EXTRA_DLL needed for MSVC
+TVM_RUNTIME_EXTRA_DLL void RPCServerLoop(int sockfd) {
support::TCPSocket sock(static_cast<support::TCPSocket::SockType>(sockfd));
RPCEndpoint::Create(std::make_unique<SockChannel>(sock), "SockServerLoop", "")->ServerLoop();
}
diff --git a/src/runtime/vm/tensor_cache_support.cc b/src/runtime/vm/tensor_cache_support.cc
index d28b68bf7a..0c7559bcd6 100644
--- a/src/runtime/vm/tensor_cache_support.cc
+++ b/src/runtime/vm/tensor_cache_support.cc
@@ -109,7 +109,7 @@ TensorCacheMetadata TensorCacheMetadata::LoadFromStr(const std::string& json_str
return result;
}
-TVM_RUNTIME_DLL TensorCacheMetadata TensorCacheMetadata::Load(const std::string& path) {
+TVM_RUNTIME_EXTRA_DLL TensorCacheMetadata TensorCacheMetadata::Load(const std::string& path) {
std::string json_str = support::ReadBytesFromFile(path + "/tensor-cache.json");
ffi::String err;
json::Value json_info = json::Parse(json_str, &err);
@@ -169,7 +169,7 @@ ffi::Tensor TensorCacheMetadata::FileRecord::ParamRecord::Load(
return arr;
}
-TVM_RUNTIME_DLL ffi::Array<ffi::Tensor> TensorCacheMetadata::FileRecord::Load(
+TVM_RUNTIME_EXTRA_DLL ffi::Array<ffi::Tensor> TensorCacheMetadata::FileRecord::Load(
Device device,
const std::string& path_prefix, //
std::string* raw_data_buffer, //
diff --git a/tirx/include/tvm/codegen/codegen.h b/tirx/include/tvm/codegen/codegen.h
index 2261b18290..6e2925a9cf 100644
--- a/tirx/include/tvm/codegen/codegen.h
+++ b/tirx/include/tvm/codegen/codegen.h
@@ -41,7 +41,7 @@ namespace codegen {
* \param target The target to be built.
* \return The generated module.
*/
-TVM_DLL ffi::Module Build(IRModule mod, Target target);
+TVM_TIRX_DLL ffi::Module Build(IRModule mod, Target target);
/*!
* \brief Pack imported device library to a C file.
@@ -54,7 +54,7 @@ TVM_DLL ffi::Module Build(IRModule mod, Target target);
* \param c_symbol_prefix Optional symbol prefix of the blob symbol.
* \return cstr The C string representation of the file.
*/
-TVM_DLL std::string PackImportsToC(const ffi::Module& m, bool system_lib,
+TVM_TIRX_DLL std::string PackImportsToC(const ffi::Module& m, bool system_lib,
const std::string& c_symbol_prefix = "");
/*!
@@ -69,7 +69,7 @@ TVM_DLL std::string PackImportsToC(const ffi::Module& m, bool system_lib,
* \param file_name Output path; its extension selects the object format.
* \param c_symbol_prefix Optional blob symbol prefix, valid only for system libraries.
*/
-TVM_DLL void PackImportsToObjectFile(const ffi::Module& mod, bool system_lib,
+TVM_TIRX_DLL void PackImportsToObjectFile(const ffi::Module& mod, bool system_lib,
const std::string& llvm_target_string,
const std::string& file_name,
const std::string& c_symbol_prefix = "");
diff --git a/tirx/include/tvm/codegen/intrin_rule.h b/tirx/include/tvm/codegen/intrin_rule.h
index d3d196f7d7..4d0f866d88 100644
--- a/tirx/include/tvm/codegen/intrin_rule.h
+++ b/tirx/include/tvm/codegen/intrin_rule.h
@@ -101,14 +101,14 @@ inline PrimExpr DispatchPureExtern(const PrimExpr& e) {
* The expansion clamps the input to [-4, 4] and evaluates numerator and
* denominator polynomials using the input element width; other types are rejected.
*/
-TVM_DLL PrimExpr DispatchFastErf(const PrimExpr& e);
+TVM_TIRX_DLL PrimExpr DispatchFastErf(const PrimExpr& e);
/*!
* \brief Lower a unary floating-point tanh call using sign-dependent exponential formulas.
* The expansion avoids the large-positive-input overflow of the symmetric formula;
* accuracy follows the floating-point arithmetic and exponential lowering in use.
*/
-TVM_DLL PrimExpr DispatchNumericallyStableTanh(const PrimExpr& e);
+TVM_TIRX_DLL PrimExpr DispatchNumericallyStableTanh(const PrimExpr& e);
} // namespace intrin
} // namespace codegen
diff --git a/tirx/include/tvm/runtime/base.h b/tirx/include/tvm/runtime/base.h
index 09ec0917f5..aa9c527d38 100644
--- a/tirx/include/tvm/runtime/base.h
+++ b/tirx/include/tvm/runtime/base.h
@@ -32,7 +32,7 @@
// passes the setuptools_scm-resolved version through CMake). The literal below is the
// fallback for a bare build with no override.
#ifndef TVM_VERSION
-#define TVM_VERSION "0.28.dev0"
+#define TVM_VERSION "0.1.0a0"
#endif
// The compiler, core runtime and runtime-extra libraries expose independent
@@ -77,12 +77,19 @@
#define TVM_DLL_EXPORT __attribute__((visibility("default")))
#endif
-// Core IR, TIRx and shared compiler infrastructure are currently linked into
-// libtvm_compiler. Keep their ownership explicit while inheriting the compiler
-// export policy, including downstream TVM_DLL overrides. Embedders may override
-// TVM_TIRX_DLL independently.
+// Core IR, TIRx and shared compiler infrastructure live in libtvm_tirx.
#ifndef TVM_TIRX_DLL
-#define TVM_TIRX_DLL TVM_DLL
+#if defined(__EMSCRIPTEN__)
+#define TVM_TIRX_DLL EMSCRIPTEN_KEEPALIVE
+#elif defined(_MSC_VER)
+#ifdef TVM_TIRX_EXPORTS
+#define TVM_TIRX_DLL __declspec(dllexport)
+#else
+#define TVM_TIRX_DLL __declspec(dllimport)
+#endif
+#else
+#define TVM_TIRX_DLL __attribute__((visibility("default")))
+#endif
#endif
// --- TVM_RUNTIME_DLL family (libtvm_runtime) ---
diff --git a/web/Makefile b/web/Makefile
index 7f802b5a21..12ab22f471 100644
--- a/web/Makefile
+++ b/web/Makefile
@@ -17,10 +17,10 @@
TVM_ROOT=$(realpath $(shell dirname $(firstword $(MAKEFILE_LIST))))/../
-INCLUDE_FLAGS = -I$(TVM_ROOT) -I$(TVM_ROOT)/include\
+INCLUDE_FLAGS = -I$(TVM_ROOT) -I$(TVM_ROOT)/include -I$(TVM_ROOT)/tirx/include\
-I$(TVM_ROOT)/3rdparty/tvm-ffi/include\
-I$(TVM_ROOT)/3rdparty/tvm-ffi/3rdparty/dlpack/include\
- -I$(TVM_ROOT)/3rdparty/compiler-rt
+ -I$(TVM_ROOT)/tirx/3rdparty/compiler-rt
.PHONY: clean all rmtypedep preparetest
diff --git a/web/emcc/wasm_runtime.cc b/web/emcc/wasm_runtime.cc
index 07a52235ef..02948f145e 100644
--- a/web/emcc/wasm_runtime.cc
+++ b/web/emcc/wasm_runtime.cc
@@ -35,21 +35,21 @@
#include <cstring>
#include <limits>
-#include "src/runtime/cpu_device_api.cc"
-#include "src/runtime/device_api.cc"
+#include "tirx/src/runtime/cpu_device_api.cc"
+#include "tirx/src/runtime/device_api.cc"
#include "src/runtime/extra/contrib/sort/sort.cc"
-#include "src/runtime/logging.cc"
-#include "src/runtime/metadata.cc"
+#include "tirx/src/runtime/logging.cc"
+#include "tirx/src/runtime/metadata.cc"
#include "src/runtime/rpc/rpc_channel.cc"
#include "src/runtime/rpc/rpc_endpoint.cc"
#include "src/runtime/rpc/rpc_event_impl.cc"
#include "src/runtime/rpc/rpc_local_session.cc"
#include "src/runtime/rpc/rpc_module.cc"
#include "src/runtime/rpc/rpc_session.cc"
-#include "src/runtime/tensor.cc"
-#include "src/runtime/timer.cc"
+#include "tirx/src/runtime/tensor.cc"
+#include "tirx/src/runtime/timer.cc"
#include "src/runtime/vm/params.cc"
-#include "src/runtime/workspace_pool.cc"
+#include "tirx/src/runtime/workspace_pool.cc"
// relax setup
#include "3rdparty/tvm-ffi/src/ffi/backtrace.cc"
#include "3rdparty/tvm-ffi/src/ffi/container.cc"
@@ -69,7 +69,7 @@
#include "3rdparty/tvm-ffi/src/ffi/tensor.cc"
#include "3rdparty/tvm-ffi/src/ffi/testing/testing.cc"
// Enum registration requires the FFI type-attribute registry above.
-#include "src/runtime/memory_scope.cc"
+#include "tirx/src/runtime/memory_scope.cc"
#include "src/runtime/vm/attn_backend.cc"
#include "src/runtime/vm/builtin.cc"
#include "src/runtime/vm/bytecode.cc"
diff --git a/web/emcc/webgpu_runtime.cc b/web/emcc/webgpu_runtime.cc
index 780ac8824e..fb93db920c 100644
--- a/web/emcc/webgpu_runtime.cc
+++ b/web/emcc/webgpu_runtime.cc
@@ -38,7 +38,7 @@
#include <mutex>
#include <string>
-#include "../../src/runtime/metadata.h"
+#include "../../tirx/src/runtime/metadata.h"
namespace tvm {
namespace runtime {