Lunderberg commented on issue #15716: URL: https://github.com/apache/tvm/issues/15716#issuecomment-1745032376
It looks like it's a distinction between a `tvm.tir.StringImm` and a `tvm.runtime.String`. The `tvm.tir.StringImm` is only used in a few rare cases in the IR where a string must be used as a `tir.PrimExpr`, such as string literals that are used as external function arguments. The `tvm.runtime.String` is used in the majority of cases, and is the `String` class accepted by most TVM APIs. When passing a `tvm.runtime.String` through the FFI, there is special handling to ensure that a Python `str` or a Python `tvm.runtime.String` can be converted to either a C++ `tvm::runtime::String` or a C++ `std::string`. (See [here](https://github.com/apache/tvm/blob/main/python/tvm/_ffi/_ctypes/packed_func.py#L164) (python), [here](https://github.com/apache/tvm/blob/main/include/tvm/runtime/packed_func.h#L675) (C++) and [here](https://github.com/apache/tvm/blob/main/include/tvm/runtime/packed_func.h#L2032) (C++) for where this this implemented.) There is no such handling for `tvm.tir.StringImm`, and so it is handled through the default `ObjectRef` FFI interface, and can only be passed to APIs that explicitly expect a `tvm.tir.StringImm`. Since the `tir.Var` constructor accepts a `tvm::runtime::String` as its first argument, the Python API can call it with a `str` or a `tvm.runtime.String`, but not with a `tvm.tir.StringImm`. If I change your example to the following, then it can produce the `tir.Var` instance. ```python import tvm a = tvm.runtime.String("global") b = tir.Var(a, "int32") ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
