Relay VM C++ runtime error

I am testing VM runtime with it’s c++ API, it worked with this commit a while ago.

But after I update to the lasted master branch, it breaks(I changed my code a bit due to the recent changes in vm apis.), I got the following error:

terminate called after throwing an instance of ‘dmlc::Error’ what(): [12:25:59] /home/developer/LocalLib/tvm/src/runtime/vm/ Check failed: header == kTVMVMBytecodeMagic: Invalid VM file format in the header section.

Stack trace:
  [bt] (0) /home/developer/LocalLib/tvm_runtime/lib/ [0x7f0129afe4f2]
  [bt] (1) /home/developer/LocalLib/tvm_runtime/lib/*)+0xdf) [0x7f0129afec3f]
  [bt] (2) /home/developer/LocalLib/tvm_runtime/lib/<char, std::char_traits<char>, std::allocator<char> > const&, tvm::runtime::Module)+0x135) [0x7f0129b062a5]

Here is my code to load the bytecode:

std::string vm_bytecode; std::ifstream bytecode_file(bytecode_path, std::ios::binary); vm_bytecode.assign(std::istreambuf_iterator(bytecode_file), std::istreambuf_iterator()); m_exec_mod = tvm::runtime::vm::Executable::Load(vm_bytecode, m_lib);

I guess the error is related to how I read the bytecode file, but I can’t find any examples of the recent changes, anyone know how to fix this?

I managed to use C++ APIs to load the artifacts recently. Can you verify the loaded vm_bytecode is valid? We have a utility function to load it here:

Hi Thanks, it turned out that the bytecode it self is invalid, the bytecode file was written as string which is the root of my issue.

Now the c++ apis works for me, thank you very much. the utile you pointed out is very useful.