Lunderberg opened a new pull request, #16183:
URL: https://github.com/apache/tvm/pull/16183

   Prior to this commit, `int`, `float`, and `bool` arguments from Python were 
converted to `IntImm`, `FloatImm`, and `Bool`.  These are subtypes of 
`PrimExpr`, and should only be used at compile-time.  By automatically applying 
this conversion as part of the FFI, these types are required to be present 
whenever a primitive is converted to a `tvm::ObjectRef`.
   
   This can become especially fragile for an end-user when storing objects into 
a TVM container.  Because TVM containers require all contents to be `ObjectRef` 
subclasses, an automatic conversion may be applied on storing into a container, 
resulting in an unexpected type being retrieved from the container.  For 
example, this currently occurs in Relax when extracting a `R.Prim` from a 
`R.Tuple`.
   
   This commit introduces a `Box<T>` type for storage of boxed primitives at 
runtime, distinct from the IR types.  This was based on discussion on 
https://github.com/apache/tvm/pull/15983, which would have further cemented the 
`IntImm` type in `libtvm_runtime.so`, rather than starting the process of 
separating it.
   
   * Primitive arguments provided to a PackedFunc that requires an `ObjectRef` 
will be converted to the corresponding boxed type.  (e.g. Passing a Python 
`int` to a C++ function accepting `ObjectRef` produces a `Box<int64_t>`.
   
   * Boxed primitives provided to a PackedFunc that requires an unboxed 
primitive will be converted to the corresponding primitive.
   
   * PackedFunc return values of `ObjectRef` are converted to the corresponding 
primitive, if present.  (e.g. If a `tuple_getitem` with static return type 
`ObjectRef` returns a `Box<int64_t>`, it will be unwrapped to a python `int`.)
   
   Together, these three rules provide backwards compatibility for existing 
PackedFunc definitions, while avoiding exposing the user to any 
container-induced type conversions betweeen primitive types and `ObjectRef`.


-- 
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]

Reply via email to