[RFC] Conversion from std::string to tvm::runtime::String

@tqchen and I have been working on the new TVM object system over the pass few months in an effort to improve both the Python bindings, uniformity of TVM data model, and support for other language frontends.

You can check out my in progress attempt at using zero-cost bindings to TVM in Rust (https://github.com/jroesch/tvm/tree/rust-fe).

The new object system has nearly perfect C ABI compatibility, i.e it is possible for multiple languages to allocate, pass to other languages, modify, and deallocate. One large wrinkle blocking not only exposing the runtime data structures but the ASTs are the use of STL types which can not be easily interoperated with. For more obscure use cases this is OK, but the last primitive type left in TVM is std::string.

I propose that we remove the use of std::string from the IR, and instead use tvm::runtime::String. This container provides for free interoperability with any language which implements the object system, enabling other frontends (i.e., Rust) to directly allocate ASTs and return them to C++.

In my above branch I have already tried one possibility of converting the uses of it in Var, and GlobalVar.

The change should be relatively painless due to tvm::String constructors and conversions for interoperating with C++'s string. One challenge is modifying TVM serialization to correctly support serializing and deserializing in a backwards compatible way.

Look forward to hearing everyone’s thoughts.

4 Likes

I like the idea. Probably we could just use tvm::String instead of tvm::runtime::String to make it easier to use.

1 Like

Like the idea. Removing c++ containers and replacing them with TVM’s ABI compatible ones helps to inter-operate across languages a lot.

Here is a POC with update code for serialization compatibility https://github.com/apache/incubator-tvm/pull/5438

1 Like

Looks like we should proceed with the refactor. I opened https://github.com/apache/incubator-tvm/issues/5490 to track this