1. 28 Mar, 2020 2 commits
    • [NODE][IR] Introduce StructuralHash for the Unified IR. (#5160) · 497d01d3
      * [NODE][IR] Introduce StructuralHash for the Unified IR.
      
      This PR introduces a new way to handle structural hash for the unified IR.
      
      - Each object can now register an optional SEqualHash function, which
        describes how to reduce its structural equality to sequence of hash values.
      - Optionally, the object can choose to allow labeling of vars(e.g. function parameters)
        by calling DefHash
      - We implemented a non-recursive structural hasher that maintains its own stack
        to traverse te IR.
      
      This PR also improves the hash value property from the previous relay's hash utility.
      In particular, the graph node mode hashs a DAG differently from a tree
      by attaching an unique occurence index to each graph node.
      
      In all of the test cases so far, structural_hash is consistent with structural_equal.
      - if structrual(x, y) then structural_hash(x) == structural_hash(y)
      - if structural_hash(x) == structural_hash(y) then highly likely structural_equal(x, y)
        - hash no collison is found in our testcases.
      
      Ideally we should work on automatically generating these functions in the future.
      
      * Fix cases for EnvFunc and Array dims
      
      * fix testcase
      
      * Update src/node/structural_hash.cc
      
      Co-Authored-By: 雾雨魔理沙 <lolisa@marisa.moe>
      
      Co-authored-by: 雾雨魔理沙 <lolisa@marisa.moe>
      Tianqi Chen committed
    • [NODE][IR] Introduce StructuralEqual Infra for the unified IR. (#5154) · 997a14ed
      * [NODE][IR] Introduce StructuralEqual Infra for the Unified IR.
      
      This PR introduces a new way to handle structural equality
      for both TIR and relay nodes in an extensive way.
      
      - Each object can now register an optional SEqualReduce function, which
        describes how to reduce its structural equality to another instance
        into equality of the children.
      - Optionally, the object can choose to allow remapping of vars(e.g. function parameters)
        by calling DefEqual
      - We implemented a non-recursive structural equality checker that
        recursively traverses the objects and does the structural equality checking.
      
      This PR also fixes a few potential problems in previous relay's AlphaEqual.
      
      - In particular, the new structural equality relation will be communicative.
      - It is can be dangerous to use same_as relation to quickly check equality,
        demonstrated by the following case. (%x, %y) are shared vars between two functions.
      
      - function0: fn (%x, %y) { %x + %y }
      - function1: fn (%y, %x) { %x + %y }
      
      The new structural equal is intented to supersede AlphaEqual and AttrsEqual.
      
      Follow-up PRs should be performed to redirect the existing usages, and removes
      the corresponding implementation.
      
      * Update the rule to distinguish between graph node and non-graph nodes.
      
      * Refactor the test cases to use structural equal.
      
      * address comments
      
      * Mark more relay::Expr as graph node, fix a testcase issue(was bug that was not caught by previous alpha equal)
      
      * Remove unrelated comment
      
      * Fix file comment
      
      * Address review comment
      
      * Relax condition to fit flaky case
      Tianqi Chen committed
  2. 24 Mar, 2020 1 commit
  3. 20 Mar, 2020 1 commit
    • [TIR][TARGET] Refactor Target codegen to use IRModule and PrimFunc. (#5107) · 841725cc
      As part of the unified IR refactor.
      This PR refactors the target codegen to use IRModule containing tir::PrimFuncs.
      
      In order to break the refactor into several steps without breaking the codebase,
      we built an conversion pass to convert Array<LoweredFunc> into IRModule.
      
      The follow-up refactors will gradually move the passes covered by IRModule up
      until we cover all the passes. Then we can remove the additional redundant
      concepts such as LoweredFunc.
      Tianqi Chen committed
  4. 15 Mar, 2020 1 commit
  5. 12 Mar, 2020 1 commit
    • [REFACTOR] Streamline Function Attr interface. (#5045) · ec86d7f1
      * [REFACTOR] Streamline Function Attr interface.
      
      There has been quite a few recent changes that depends heavily on
      the function attr interface. This PR streamlines that interface by introducing
      two APIs that covers most of the usages.
      
      - GetAttr which gets a typed object for a given key
        - HasNonzeroAttr is a quick helper that calls GetAttr to quickly check an attribute
      - WithAttr that creates a new function object with the given attr
        - The API comes with copy on write optimization to avoid multiple copies
        - We deliberately pick the prefix With(instead of Set) to indicate this
          function does not mutate the original input.
      
      On the python side:
      - We allow read access via func.attrs (which is a DictAttr)
      - func.with_attrs to create a new instance with updated attrs.
      
      We also get rid of the small wrapper functions and make sure the API centered around
      the GetAttr and HasNonzeroAttr interface.
      
      This PR also changes the function construction to follow the new convention.
      
      * Address review comments
      
      * Address review comments
      
      * Fix doxygen path
      Tianqi Chen committed
  6. 12 Feb, 2020 1 commit
    • [REFACTOR][PY][API-CHANGE] establish tvm.ir, migrate corresponding files (#4862) · a5661611
      * [REFACTOR][PY][API-CHANGE] establish tvm.ir, migrate corresponding relay files.
      
      This PR establishes tvm.ir and migrates the corresponding relay
      files into the new folder.
      
      API Change:
      - relay.Module -> tvm.IRModule
      
      * Update with ADT
      
      * Migrate transform
      
      * address comments
      
      * Migrate module
      
      * Migrate json_compact
      
      * Migrate attrs
      
      * Move LoweredFunc to stmt temporarily
      
      * temp migrate container
      
      * Finish migrate container
      Tianqi Chen committed
  7. 19 Jan, 2020 1 commit
    • [REFACTOR] Establish tir (#4740) · cf59b206
      TIR is the new namespace for low-level IR
      for tensor-level optimizations and loop transformations.
      
      This PR establishes the namespace and files.
      
      - lowered_func.h,buffer.h,data_layout.h -> tir/buffer.h,tir/data_layout.h,tir/lowered_func.h
      - ir.h -> tir/expr.h, tir/stmt.h
      - ir_functor_ext.h -> tir/expr_functor.h, tir/stmt_functor.h
      Tianqi Chen committed
  8. 17 Jan, 2020 2 commits
  9. 15 Jan, 2020 2 commits
    • [REFACTOR][IR] attrs.h -> ir (#4709) · b0b51f25
      This PR moves attrs.h into the ir folder as it
      can serve as a common infra for building ir dats structures.
      
      We also moved common container(FloatImm) into ir/expr.h
      Tianqi Chen committed
    • [REFACTOR][IR] Unify IntImm and UIntImm (#4706) · ce807fe8
      * [REFACTOR][IR] Unify IntImm and UIntImm
      
      This PR unifies UIntImm and IntImm to simplify the codebase.
      Unsigned integer constants will also be stored as IntImm.
      
      For uint constant that does not fit into int64(rare case), we introduced
      an intrinsic tvm_big_uint_imm to construct such intgers by its
      lower and higher 32bits.
      
      * [REFACTOR][IR] Remove UIntImm to use IntImm
      
      * rename big->large
      Tianqi Chen committed
  10. 14 Jan, 2020 1 commit
  11. 11 Jan, 2020 1 commit
    • [REFACTOR][IR] Initialize Unified IR Expr Data Structure (#4673) · 12e51e6c
      This PR moves a few base types from relay and low-level Expr into the ir sub-folder.
      These classes will serve as a common type system across the stack.
      
      Rationale:
      
      - PrimExpr for low-level expressions
      - RelayExpr for advanced features, including Function definition.
      - Introduce BaseFunc to host all functions, including future PrimFunc(low-level expr functions, subject to discussion).
      
      This is a minimum change we can do to unify the classes into a common hierarchy.
      The main data structure that are variant specific will still be kept in the sub-namespaces.
      We only include classes that is needed to allow a common Module class.
      - BaseFunc
      - GlobalVar
      - Type definition part of ADT
      
      We will only need the BaseFunc and their checked_type to decide the calling convention
      across the function variants.
      Tianqi Chen committed