From 2d96975fafbe1e1ddee373e44bbb2a2e367006d1 Mon Sep 17 00:00:00 2001 From: Ruihang Lai Date: Sat, 13 Sep 2025 23:53:29 -0400 Subject: [PATCH] [C++] Update TVM_FFI_STATIC_INIT_BLOCK to fn style Following apache/tvm#18312, this PR updates the `TVM_FFI_STATIC_INIT_BLOCK` to functional style. --- 3rdparty/tvm | 2 +- cpp/json_ffi/json_ffi_engine.cc | 4 ++-- cpp/multi_gpu/builtin.cc | 4 ++-- cpp/multi_gpu/multi_gpu_loader.cc | 4 ++-- cpp/serve/data.cc | 16 ++++++++-------- cpp/serve/engine.cc | 4 ++-- cpp/serve/event_trace_recorder.cc | 4 ++-- cpp/serve/model.cc | 4 ++-- cpp/serve/radix_tree.cc | 4 ++-- cpp/serve/request.cc | 4 ++-- cpp/serve/threaded_engine.cc | 4 ++-- cpp/tokenizers/streamer.cc | 8 ++++---- cpp/tokenizers/tokenizers.cc | 8 ++++---- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/3rdparty/tvm b/3rdparty/tvm index 424aaa4ba2..10e31c73d5 160000 --- a/3rdparty/tvm +++ b/3rdparty/tvm @@ -1 +1 @@ -Subproject commit 424aaa4ba220a7c37a2b6941c948fc6e3f524451 +Subproject commit 10e31c73d576740c6ab79db4b4903e7c3740522f diff --git a/cpp/json_ffi/json_ffi_engine.cc b/cpp/json_ffi/json_ffi_engine.cc index 703a531428..e4040b6c72 100644 --- a/cpp/json_ffi/json_ffi_engine.cc +++ b/cpp/json_ffi/json_ffi_engine.cc @@ -296,11 +296,11 @@ class JSONFFIEngineImpl : public JSONFFIEngine, public ffi::ModuleObj { } }; -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef().def("mlc.json_ffi.CreateJSONFFIEngine", []() { return ffi::Module(tvm::ffi::make_object()); }); -}); +} } // namespace json_ffi } // namespace llm diff --git a/cpp/multi_gpu/builtin.cc b/cpp/multi_gpu/builtin.cc index 5254cd9519..e60cb99cf2 100644 --- a/cpp/multi_gpu/builtin.cc +++ b/cpp/multi_gpu/builtin.cc @@ -86,12 +86,12 @@ ObjectRef SendFromLastGroupToWorker0(Tensor send, Optional recv, Shape s return recv; } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.multi_gpu.DispatchFunctionByGroup", DispatchFunctionByGroup) .def("mlc.multi_gpu.SendFromLastGroupToWorker0", SendFromLastGroupToWorker0); -}); +} } // namespace multi_gpu } // namespace llm diff --git a/cpp/multi_gpu/multi_gpu_loader.cc b/cpp/multi_gpu/multi_gpu_loader.cc index b029c62c0e..12f03ba7e7 100644 --- a/cpp/multi_gpu/multi_gpu_loader.cc +++ b/cpp/multi_gpu/multi_gpu_loader.cc @@ -312,12 +312,12 @@ Array> LoadMultiGPUPresharded(const std::string& model_path, Mo return params; } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.multi_gpu.LoadMultiGPU", LoadMultiGPU) .def("mlc.multi_gpu.LoadMultiGPUPresharded", LoadMultiGPUPresharded); -}); +} } // namespace multi_gpu } // namespace llm diff --git a/cpp/serve/data.cc b/cpp/serve/data.cc index 125536fd15..90426184f8 100644 --- a/cpp/serve/data.cc +++ b/cpp/serve/data.cc @@ -72,12 +72,12 @@ ObjectRef TextDataNode::GetEmbedding(Model model, ObjectRef* dst, int offset) co "Please tokenize the text and construct a TokenData object."; } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.serve.TextData", [](String text) { return TextData(std::move(text)); }) .def("mlc.serve.TextDataGetTextString", [](TextData data) { return data->text; }); -}); +} /****************** TokenData ******************/ @@ -99,7 +99,7 @@ ObjectRef TokenDataNode::GetEmbedding(Model model, ObjectRef* dst, int offset) c return model->TokenEmbed(token_ids, dst, offset); } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def_packed("mlc.serve.TokenData", @@ -112,7 +112,7 @@ TVM_FFI_STATIC_INIT_BLOCK({ *rv = TokenData(std::move(token_ids)); }) .def("mlc.serve.TokenDataGetTokenIds", [](TokenData data) { return data->token_ids; }); -}); +} /****************** ImageData ******************/ @@ -129,13 +129,13 @@ ObjectRef ImageDataNode::GetEmbedding(Model model, ObjectRef* dst, int offset) c return model->ImageEmbed(image, dst, offset); } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.serve.ImageData", [](Tensor image, int embed_size) { return ImageData(std::move(image), embed_size); }) .def("mlc.serve.ImageDataGetImage", [](ImageData data) { return data->image; }); -}); +} /****************** SampleResult ******************/ @@ -223,7 +223,7 @@ RequestStreamOutput RequestStreamOutput::Usage(String request_id, return RequestStreamOutput(n); } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef().def("mlc.serve.RequestStreamOutputUnpack", [](RequestStreamOutput output) { CHECK(!output->unpacked) << "One RequestStreamOutput can be unpacked for at most once."; @@ -250,7 +250,7 @@ TVM_FFI_STATIC_INIT_BLOCK({ output->unpacked = true; return ret; }); -}); +} } // namespace serve } // namespace llm diff --git a/cpp/serve/engine.cc b/cpp/serve/engine.cc index 605779ef41..bae3785cf7 100644 --- a/cpp/serve/engine.cc +++ b/cpp/serve/engine.cc @@ -1087,10 +1087,10 @@ class EngineModule : public ffi::ModuleObj { GenerationConfig default_generation_config_; }; -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef().def("mlc.serve.create_engine", EngineModule::Create); -}); +} } // namespace serve } // namespace llm diff --git a/cpp/serve/event_trace_recorder.cc b/cpp/serve/event_trace_recorder.cc index efa4ba06e8..2978bd0e84 100644 --- a/cpp/serve/event_trace_recorder.cc +++ b/cpp/serve/event_trace_recorder.cc @@ -147,7 +147,7 @@ EventTraceRecorder EventTraceRecorder::Create() { return EventTraceRecorder(tvm::ffi::make_object()); } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.serve.EventTraceRecorder", []() { return EventTraceRecorder::Create(); }) @@ -155,7 +155,7 @@ TVM_FFI_STATIC_INIT_BLOCK({ [](const EventTraceRecorder& trace_recorder, const String& request_id, const std::string& event) { trace_recorder->AddEvent(request_id, event); }) .def_method("mlc.serve.EventTraceRecorderDumpJSON", &EventTraceRecorderObj::DumpJSON); -}); +} } // namespace serve } // namespace llm diff --git a/cpp/serve/model.cc b/cpp/serve/model.cc index 41d77930ac..568501dd7e 100644 --- a/cpp/serve/model.cc +++ b/cpp/serve/model.cc @@ -1114,7 +1114,7 @@ class ModelImpl : public ModelObj { std::unordered_set prefilled_seq_ids_; }; -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef().def( "mlc.copy_embedding_to_offset", [](Tensor embedding, Tensor dst, int offset) { @@ -1132,7 +1132,7 @@ TVM_FFI_STATIC_INIT_BLOCK({ ((embedding->dtype.bits * embedding->dtype.lanes + 7) / 8); Tensor::CopyFromTo(©_src, ©_dst); }); -}); +} } // namespace serve } // namespace llm diff --git a/cpp/serve/radix_tree.cc b/cpp/serve/radix_tree.cc index 5eb0d6bf4f..3f2e6782e4 100644 --- a/cpp/serve/radix_tree.cc +++ b/cpp/serve/radix_tree.cc @@ -800,7 +800,7 @@ PagedRadixTree PagedRadixTree::Create() { return PagedRadixTree(tvm::ffi::make_object()); } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.serve.PagedRadixTree", []() { return PagedRadixTree::Create(); }) @@ -836,7 +836,7 @@ TVM_FFI_STATIC_INIT_BLOCK({ .def("mlc.serve.PagedRadixTreeFreeCapacity", [](PagedRadixTree paged_radix_tree) { return static_cast(paged_radix_tree->FreeCapacity()); }); -}); +} } // namespace serve } // namespace llm diff --git a/cpp/serve/request.cc b/cpp/serve/request.cc index fc0baeda89..a3344228ee 100644 --- a/cpp/serve/request.cc +++ b/cpp/serve/request.cc @@ -66,14 +66,14 @@ Request Request::FromUntokenized(const Request& request, const Tokenizer& tokeni } } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.serve.RequestGetInputs", [](Request request) { return request->inputs; }) .def("mlc.serve.RequestGetGenerationConfigJSON", [](Request request) { return picojson::value(request->generation_cfg->AsJSON()).serialize(); }); -}); +} } // namespace serve } // namespace llm diff --git a/cpp/serve/threaded_engine.cc b/cpp/serve/threaded_engine.cc index aa35e42702..722df060f2 100644 --- a/cpp/serve/threaded_engine.cc +++ b/cpp/serve/threaded_engine.cc @@ -400,11 +400,11 @@ class ThreadedEngineModule : public ThreadedEngineImpl, public ffi::ModuleObj { TVM_MODULE_VTABLE_END(); }; -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef().def("mlc.serve.create_threaded_engine", []() { return Module(tvm::ffi::make_object()); }); -}); +} std::unique_ptr ThreadedEngine::Create() { std::unique_ptr threaded_engine = std::make_unique(); diff --git a/cpp/tokenizers/streamer.cc b/cpp/tokenizers/streamer.cc index 4f2594cb39..ab583b3f46 100644 --- a/cpp/tokenizers/streamer.cc +++ b/cpp/tokenizers/streamer.cc @@ -138,7 +138,7 @@ std::string TextStreamerObj::Finish() { } } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.tokenizers.TextStreamer", @@ -149,7 +149,7 @@ TVM_FFI_STATIC_INIT_BLOCK({ {delta_tokens->data, delta_tokens->data + delta_tokens->size}); }) .def_method("mlc.tokenizers.TextStreamerFinish", &TextStreamerObj::Finish); -}); +} /****************** StopStrHandler ******************/ @@ -261,7 +261,7 @@ StopStrHandler::StopStrHandler(Array stop_strs, data_ = tvm::ffi::make_object(std::move(stop_strs), token_table); } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.tokenizers.StopStrHandler", @@ -281,7 +281,7 @@ TVM_FFI_STATIC_INIT_BLOCK({ return IntTuple(std::move(remaining_token_ids)); }) .def_method("mlc.tokenizers.StopStrHandlerStopTriggered", &StopStrHandlerObj::StopTriggered); -}); +} } // namespace llm } // namespace mlc diff --git a/cpp/tokenizers/tokenizers.cc b/cpp/tokenizers/tokenizers.cc index 01f44a129c..4d7169d8b8 100644 --- a/cpp/tokenizers/tokenizers.cc +++ b/cpp/tokenizers/tokenizers.cc @@ -453,7 +453,7 @@ const std::vector& TokenizerObj::PostProcessedTokenTable() { return post_processed_token_table_; } -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def("mlc.tokenizers.Tokenizer", [](const String& path) { return Tokenizer::FromPath(path); }) @@ -478,11 +478,11 @@ TVM_FFI_STATIC_INIT_BLOCK({ }) .def("mlc.tokenizers.DetectTokenizerInfo", [](const String& path) { return Tokenizer::DetectTokenizerInfo(path)->AsJSONString(); }); -}); +} #endif -TVM_FFI_STATIC_INIT_BLOCK({ +TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; refl::GlobalDef() .def_packed("mlc.tokenizers.PostProcessTokenTable", @@ -507,7 +507,7 @@ TVM_FFI_STATIC_INIT_BLOCK({ [](const String& token, const String& token_postproc_method) { return PostProcessToken(token, token_postproc_method); }); -}); +} } // namespace llm } // namespace mlc