You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "mulanxiaodingdang (via GitHub)" <gi...@apache.org> on 2025/07/14 07:54:26 UTC

[I] [Bug] In the latest version of TVM, PackedFunc has been removed. [tvm]

mulanxiaodingdang opened a new issue, #18146:
URL: https://github.com/apache/tvm/issues/18146

   The error message is as follows:
   > 
   (base) hgs@hgs:~/tvm_25_06/tvm/my_example$ g++ -std=c++17 -O2 -fPIC -I/home/hgs/tvm_25_06/tvm/include -I/home/hgs/tvm_25_06/tvm/3rdparty/dmlc-core/include -I/home/hgs/tvm_25_06/tvm/3rdparty/dlpack/include -DDMLC_USE_LOGGING_LIBRARY=\<tvm/runtime/logging.h\> -o lib/compiled_artifact  cc_deploy.cc lib/test_addone_sys.o lib/libtvm_runtime_pack.o -L/home/hgs/tvm_25_06/tvm/tvm_build -ldl -pthread
   cc_deploy.cc:12:21: error: ‘PackedFunc’ has not been declared in ‘tvm::runtime’
      12 | using tvm::runtime::PackedFunc;            // 打包函数接口
         |                     ^~~~~~~~~~
   cc_deploy.cc: In function ‘int main()’:
   cc_deploy.cc:26:5: error: ‘PackedFunc’ was not declared in this scope
      26 |     PackedFunc vm_load_executable = mod.GetFunction("vm_load_executable");
         |     ^~~~~~~~~~
   In file included from /home/hgs/tvm_25_06/tvm/3rdparty/dmlc-core/include/dmlc/./logging.h:132,
                    from /home/hgs/tvm_25_06/tvm/3rdparty/dmlc-core/include/dmlc/io.h:15,
                    from /home/hgs/tvm_25_06/tvm/include/tvm/runtime/module.h:29,
                    from /home/hgs/tvm_25_06/tvm/include/tvm/runtime/relax_vm/executable.h:27,
                    from cc_deploy.cc:3:
   cc_deploy.cc:28:11: error: ‘vm_load_executable’ was not declared in this scope
      28 |     CHECK(vm_load_executable != nullptr)
         |           ^~~~~~~~~~~~~~~~~~
   /home/hgs/tvm_25_06/tvm/include/tvm/runtime/logging.h:574:9: note: in definition of macro ‘CHECK’
     574 |   if (!(x))                                                     \
         |         ^
   cc_deploy.cc:33:12: error: redeclaration of ‘tvm::runtime::Module mod’
      33 |     Module mod = vm_load_executable();  // 执行加载函数创建虚拟机模块
         |            ^~~
   cc_deploy.cc:22:12: note: ‘tvm::runtime::Module mod’ previously declared here
      22 |     Module mod = Module::LoadFromFile(path);  // 加载.so文件创建TVM模块
         |            ^~~
   cc_deploy.cc:33:18: error: ‘vm_load_executable’ was not declared in this scope
      33 |     Module mod = vm_load_executable();  // 执行加载函数创建虚拟机模块
         |                  ^~~~~~~~~~~~~~~~~~
   cc_deploy.cc:36:15: error: expected ‘;’ before ‘vm_initialization’
      36 |     PackedFunc vm_initialization = mod.GetFunction("vm_initialization");
         |               ^~~~~~~~~~~~~~~~~~
         |               ;
   cc_deploy.cc:41:11: error: ‘vm_initialization’ was not declared in this scope
      41 |     CHECK(vm_initialization != nullptr)
         |           ^~~~~~~~~~~~~~~~~
   /home/hgs/tvm_25_06/tvm/include/tvm/runtime/logging.h:574:9: note: in definition of macro ‘CHECK’
     574 |   if (!(x))                                                     \
         |         ^
   cc_deploy.cc:50:5: error: ‘vm_initialization’ was not declared in this scope
      50 |     vm_initialization(static_cast<int>(device.device_type),
         |     ^~~~~~~~~~~~~~~~~
   cc_deploy.cc:57:15: error: expected ‘;’ before ‘main’
      57 |     PackedFunc main = mod.GetFunction("main");
         |               ^~~~~
         |               ;
   cc_deploy.cc:73:40: error: too many arguments to function ‘int main()’
      73 |     tvm::runtime::NDArray output = main(input);  // 运行模型
         |                                    ~~~~^~~~~~~
   cc_deploy.cc:16:5: note: declared here
      16 | int main()
         |     ^~~~
   cc_deploy.cc:73:40: error: conversion from ‘int’ to non-scalar type ‘tvm::runtime::NDArray’ requested
      73 |     tvm::runtime::NDArray output = main(input);  // 运行模型
         |                                    ~~~~^~~~~~~
   The C++ deployment and the code for generating the .so file using TVM Relax compilation come from this link.[https://discuss.tvm.apache.org/t/deploy-relax-ir-using-c-api/17989](url)
   What code should be used now to deploy a .so file compiled by TVM Relax using C++?
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] In the latest version of TVM, PackedFunc has been removed. [tvm]

Posted by "mulanxiaodingdang (via GitHub)" <gi...@apache.org>.
mulanxiaodingdang commented on issue #18146:
URL: https://github.com/apache/tvm/issues/18146#issuecomment-3069378755

   The following code produced this output, and it seems like it should do the job:
   ```
   #include <iostream>
   #include <tvm/runtime/relax_vm/executable.h>
   #include <tvm/runtime/logging.h>
   #include <tvm/runtime/memory/memory_manager.h>
   #include <tvm/runtime/data_type.h>
   #include <tvm/ffi/function.h>
   //#include <tvm/runtime/device_api.h>
   
   using tvm::runtime::relax_vm::VMExecutable;
   using tvm::runtime::Module;
   using tvm::runtime::NDArray;
   using tvm::Device;
   using tvm::runtime::DataType;
   using tvm::runtime::memory::AllocatorType;
   
   int main() {
       using namespace tvm;
       using namespace tvm::runtime;
   
       std::string path = "./compiled_artifact.so";
   
       // Step 1: 加载模块
       Module mod = Module::LoadFromFile(path);
       std::cout << mod << std::endl;
   
       // Step 2: 获取 vm_load_executable 并调用,返回 VM 实例
       tvm::ffi::Function vm_load_executable = mod.GetFunction("vm_load_executable");
       CHECK(vm_load_executable.defined()) << "vm_load_executable not found in module.";
   
       tvm::ffi::Any re = vm_load_executable();
       std::optional<Module> maybe_vm = re.as<Module>();
       if (!maybe_vm.has_value()) {
           std::cerr << "Returned value from vm_load_executable is not a Module" << std::endl;
           return -1;
       }
       Module vm = maybe_vm.value();
   
       // Step 3: 初始化虚拟机(关键步骤)
       Device dev{kDLCPU, 0};
       tvm::ffi::Function vm_init = vm.GetFunction("vm_initialization");
       CHECK(vm_init.defined()) << "vm_initialization not found in VM";
       vm_init(static_cast<int>(dev.device_type), static_cast<int>(dev.device_id),
               static_cast<int>(AllocatorType::kPooled),
               static_cast<int>(dev.device_type), static_cast<int>(dev.device_id),
               static_cast<int>(AllocatorType::kPooled));
   
       // Step 4: 获取 main 函数并运行
       tvm::ffi::Function vm_main = vm.GetFunction("main");
       CHECK(vm_main.defined()) << "main function not found";
   
       NDArray input = NDArray::Empty({3, 3}, DataType::Int(32), dev);
       int* in_data = static_cast<int*>(input->data);
       for (int i = 0; i < 9; ++i) in_data[i] = 42;
   
       tvm::ffi::Any ret = vm_main(input);
       std::optional<NDArray> output_opt = ret.as<NDArray>();
       if (!output_opt.has_value()) {
           std::cerr << "Error: output is not NDArray." << std::endl;
           return -1;
       }
       NDArray output = output_opt.value();
   
       int* out_data = static_cast<int*>(output->data);
       for (int i = 0; i < 9; ++i) std::cout << out_data[i] << " ";
       std::cout << std::endl;
   
       return 0;
   }
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] In the latest version of TVM, PackedFunc has been removed. [tvm]

Posted by "mulanxiaodingdang (via GitHub)" <gi...@apache.org>.
mulanxiaodingdang commented on issue #18146:
URL: https://github.com/apache/tvm/issues/18146#issuecomment-3068882209

   Thanks for your response, though I have some follow-up questions.
   I changed the packedfunc in the code to ffi::Function, but I'm still encountering the following error:
   
   > > (base) hgs@hgs:~/tvm_25_06/tvm/my_example$ g++ -std=c++17 -O2 -fPIC -I/home/hgs/tvm_25_06/tvm/include -I/home/hgs/tvm_25_06/tvm/3rdparty/dmlc-core/include -I/home/hgs/tvm_25_06/tvm/3rdparty/dlpack/include -DDMLC_USE_LOGGING_LIBRARY=\<tvm/runtime/logging.h\> -o lib/compiled_artifact  cc_deploy.cc -L/home/hgs/tvm_25_06/tvm/tvm_build -ldl -pthread -ltvm -ltvm_runtime
   > cc_deploy.cc: In function ‘int main()’:
   > cc_deploy.cc:30:36: error: conversion from ‘tvm::ffi::Any’ to non-scalar type ‘tvm::runtime::Module’ requested
   >    30 |     Module mod = vm_load_executable();
   >       |                  ~~~~~~~~~~~~~~~~~~^~
   > cc_deploy.cc:55:40: error: conversion from ‘tvm::ffi::Any’ to non-scalar type ‘tvm::runtime::NDArray’ requested
   >    55 |     tvm::runtime::NDArray output = main(input);
   >       |                                    ~~~~^~~~~~~
   >
   
   
   The original C++ code is as follows:
   `//https://discuss.tvm.apache.org/t/deploy-relax-ir-using-c-api/17989
   #include <iostream>
   #include <tvm/runtime/relax_vm/executable.h>  // TVM Relax虚拟机可执行文件相关头文件
   #include <tvm/runtime/logging.h>             // TVM日志系统
   #include <tvm/runtime/memory/memory_manager.h> // 内存管理
   #include <tvm/runtime/data_type.h>           // 数据类型定义
   #include <tvm/ffi/function.h>
   
   // 使用声明,简化后续代码
   using tvm::runtime::relax_vm::VMExecutable;  // Relax虚拟机可执行文件类
   using tvm::runtime::Module;                // TVM模块类
   //using tvm::runtime::PackedFunc;            // 打包函数接口
   using tvm::runtime::memory::AllocatorType; // 内存分配器类型
   
   
   int main()
   {
       std::string path = "./compiled_artifact.so";
   
       // Load the shared object into a Module.
       Module m = Module::LoadFromFile(path);
       std::cout << m << std::endl;
   
       tvm::ffi::Function vm_load_executable = m.GetFunction("vm_load_executable");
       CHECK(vm_load_executable != nullptr)
           << "Error: File `" << path
           << "` is not built by RelaxVM, because `vm_load_executable` does not exist";
   
       // Create a VM from the Executable in the Module.
       Module mod = vm_load_executable();
       tvm::ffi::Function vm_initialization = mod.GetFunction("vm_initialization");
       CHECK(vm_initialization != nullptr)
           << "Error: File `" << path
           << "` is not built by RelaxVM, because `vm_initialization` does not exist";
   
       // Initialize the VM
       tvm::Device device{kDLCPU, 0};
       vm_initialization(static_cast<int>(device.device_type), static_cast<int>(device.device_id),
                       static_cast<int>(AllocatorType::kPooled), static_cast<int>(kDLCPU), 0,
                       static_cast<int>(AllocatorType::kPooled));
   
       tvm::ffi::Function main = mod.GetFunction("main");
       CHECK(main != nullptr)
           << "Error: File `" << path
           << "` does not contain the expected entry function, `main`";
   
       // Create and initialize the input array
       auto i32 = tvm::runtime::DataType::Int(32);
       tvm::runtime::NDArray input = tvm::runtime::NDArray::Empty({3, 3}, i32, device);
       int numel = input.Shape()->Product();
       for (int i = 0; i < numel; ++i)
           static_cast<int*>(input->data)[i] = 42;
   
       // Run the main function
       tvm::runtime::NDArray output = main(input);
       for (int i = 0; i < numel; ++i)
           std::cout << static_cast<int*>(output->data)[i] << std::endl;
   
   }`
   
   If it's convenient, could you provide me with the complete deployment code? Thank you.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] In the latest version of TVM, PackedFunc has been removed. [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on issue #18146:
URL: https://github.com/apache/tvm/issues/18146#issuecomment-3073419713

   indeed as suggested, we moved to ffi::Function


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] In the latest version of TVM, PackedFunc has been removed. [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen closed issue #18146: [Bug] In the latest version of TVM, PackedFunc has been removed.
URL: https://github.com/apache/tvm/issues/18146


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] In the latest version of TVM, PackedFunc has been removed. [tvm]

Posted by "w1049 (via GitHub)" <gi...@apache.org>.
w1049 commented on issue #18146:
URL: https://github.com/apache/tvm/issues/18146#issuecomment-3068751246

   `GetFunction` now returns an `ffi::Function`. I think you can simply use "auto".


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org