Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft][Unity] Allow dynamic indices to TupleGetItem #16002

Closed

Commits on Nov 29, 2023

  1. [PR-15983][FFI] Allow IntImm arguments to PackedFunc with int parameter

    TVM containers, such as tvm::runtime::Array, require the contained
    objects to inherit from `ObjectRef`.  As a result, the wrapper types
    `IntImm`, `FloatImm`, and `StringImm` are often used to allow native
    types in the TVM containers.  Conversions into these wrapper type may
    be required when using a container, and may be performed automatically
    when passing an object across the FFI.  By also providing conversion
    to an unwrapped type, these automatic conversions are transparent
    become transparent to users.
    
    The trait can be specialized to add type specific conversion logic
    from the TVMArgvalue and TVMRetValue.
    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    85f937f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    acfeb78 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    29e9327 View commit details
    Browse the repository at this point in the history
  4. Added unit tests

    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    aa5dc39 View commit details
    Browse the repository at this point in the history
  5. Passing unit tests

    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    38c0cd1 View commit details
    Browse the repository at this point in the history
  6. Resolve failing unit tests

    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    1f569eb View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    0d9a78a View commit details
    Browse the repository at this point in the history
  8. Correct conversion of python bool to PrimValue

    Because `isinstance(bool_value, int)` returns True, boolean values
    were being converted to `T.int64`, instead of to `T.bool`.
    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    3e19873 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    7be26d5 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    c98041a View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    b4245fa View commit details
    Browse the repository at this point in the history
  12. Rename unit test file

    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    00c4aff View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    b9bf03b View commit details
    Browse the repository at this point in the history
  14. fix lint errors

    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    1dba439 View commit details
    Browse the repository at this point in the history
  15. Revert "[PR-15983][FFI] Allow IntImm arguments to PackedFunc with int…

    … parameter"
    
    This reverts commit 61f6322.
    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    8f43de7 View commit details
    Browse the repository at this point in the history
  16. [Container] Support non-nullable types in Array::Map

    Prior to this commit, the `Array::Map` member function could only be
    applied to nullable object types.  This was due to the internal use of
    `U()` as the default value for initializing the output `ArrayNode`, where
    `U` is the return type of the mapping function.  This default
    constructor is only available for nullable types, and would result in
    a compile-time failure for non-nullable types.
    
    This commit replaces `U()` with `ObjectRef()` in `Array::Map`,
    removing this limitation.  Since all items in the output array are
    overwritten before returning to the calling scope, initializing the
    output array with `ObjectRef()` does not violate type safety.
    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    8d357fb View commit details
    Browse the repository at this point in the history
  17. [FFI] Separate runtime types from IR types for int/float/bool

    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.
    
    * 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`.
    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    e739ba9 View commit details
    Browse the repository at this point in the history
  18. [UnitTest] Update apache/main unit tests for Box<int>

    Mostly, this requires removing `.value` unwrapping that is now applied
    automatically.
    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    d376d76 View commit details
    Browse the repository at this point in the history
  19. [TIR] Update FFI conversion registration

    * Change tir.Call signature accept `Array<Variant<...>>` instead of
      `Array<ObjectRef>`.  This allows the FFI to apply registered
      conversions.
    
    * Update target parsing to expect the default object types.
    
    * Extend conversion into PrimExpr.  Several APIs that check for a
      PrimExpr may now receive a `runtime.String`, `runtime.Box<bool>` or
      `runtime.Box<int64_t>`.  These must be converted to `StringImm`,
      `Bool`, or `IntImm` for use in functions that accept `PrimExpr`.
    Lunderberg committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    45c1133 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    9fc7ebf View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    924c8ff View commit details
    Browse the repository at this point in the history