To make runtime.String to work as naturally as possible in the python side,
we make it sub-class the python's str object. Note that however, we cannot
sub-class Object at the same time due to python's type layout constraint.
We introduce a PyNativeObject class to handle this kind of object sub-classing
and updated the FFI to handle PyNativeObject classes.
* Use atexit to remove TempDirectory before interpreter shutdown.
* Can't rely on complex functions from __del__ anyway.
* Fixes warning message on my box:
Exception ignored in: <function TempDirectory.__del__ at 0x12be10680>
Traceback (most recent call last):
File ".../tvm/python/tvm/contrib/util.py", line 55, in __del__
File ".../tvm/python/tvm/contrib/util.py", line 51, in remove
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/shutil.py", line 509, in rmtree
AttributeError: 'NoneType' object has no attribute 'path'
Substitute now takes a std::function to customize more replacing behaviors.
Co-authored-by: Siyuan Feng <hzfengsy@sjtu.edu.cn>
Co-authored-by: Siyuan Feng <hzfengsy@sjtu.edu.cn>
* Restructure imports in tflite frontend.
These python modules are needed for every tflite file parsed.
Factorize out imports of the common most ones.
Now that the import of operator is common, asserts can be commonized.
Loses 473 lines of duplication.
* Only restrict to tflite.Operator
The legacy Simplify/CanonicalSimplify are now a thin wrapper around the Analyzer.
This PR removes these functions and migrated every place that requires
simplification to enforce Analyzer creation.
The new API would encourage more Analyzer sharing and potentially enable
context-aware analyzer-based simplification.
* [TIR][REFACTIR] RewriteForTensorCore -> te/schedule
RewriteForTensor depends on the schedule information, which makes it differ
from a typical pass(which should get all the information from the input TIR).
As a result, we refactor it as a SchedulePostProc step for now.
We should revisit it later as we introduce more support for tensor core patterns in the TIR.
* Fix VTA to fit the new IR Pattern
* [TIR][REFACTOR] Remove te::Tensor dependencies from TIR passes.
te::Tensor is an useful object for tensor expression, but brings
un-necessary reverse dependency in TIR nodes such as Provide and Realize.
This PR is a first step to remove this dependency. We will use Buffer in all the places
where the te::Tensor was used. The rough correspondence are:
- Provide -> BufferStore
- Realize -> BufferRealize
- HalideCall -> BufferLoad.
After this change, we can not use IRModule of PrimFuncs cleanly to represent TIR
at any point of the optimizations. Buffer will serve as the abstraction for the TIR data
models to represent the intermediate storages and their constraints.
We still keep Realize/HalideCall and Provide as TIR nodes for now to make the change minimum.
Right after ScheduleOps, we call SchedulePostProcToPrimFunc to canonicalize the temporary IR
generated by TE(which contains these nodes) to the TIR.
The TIR optimizations are now mostly migrated to to the pass manager.
Followup PRs are needed to migrate the remaining few passes.
* Fix dev tutorial
- Migrate BoundCheckers and Simplify
- Migrate RewriteUnsafeSelect and RemoveNoOp
- Migrate UnrollLoop and StorageRewrite
- Migrate InjectDoubleBuffer and InjectVirtualThread
- Migrate LoopPartition and Vectorize
- Migrate CoProcSync, LiftAttrScope, InjectCopyIntrin
We still keep ir_pass registerations for now.
Need a separate PR to refactor the parts before the StorageFlatten.
* [RELAY][BYOC] Register pattern tables from external codegens
This adds utility functions to support registering
and retrieving pattern tables used by MergeComposite for
external codegens.
Change-Id: I5be165a321440e48b15ff6aff4970e0c67496aaa
* Updated DNNL tests to use pattern table mechanism
* Removed pattern table standalone test
* Change reg to _op
- Changes most of the relay docs to use autosummary.
- Bring relay API docs to the top-level flat view for easier discovery
- Removed a few cases of re-exports.
* [TIR] Remove ProducerConsumer and AllocateNode::new_expr
This PR removes two legacy IR parts in TIR that are deprecated.
ProducerConsumer node only serves as a hint markup and may no longer be
informative after extensive transformations in the pass.
If necessary, we can add related info via AttrStmt.
The new_expr field in the AllocateNode is deprecated since it can just be
replaced by a LetStmt.
- Remove dependencies of passes on ProducerConsumer.
- Remove ProducerConsumer from the IR.
- Remove the deprecated fields (new_expr, free_function) from AllocateNode.
* Fix additional testcases
Previously MakePackedAPI was in the target independent stage,
but never the less requires the device_type information that will be
binded at a later target dependent stage.
The previous implementation was due to the limitation of LoweredFunc
which can not carry buffer_map info(so they have to be lowered right away).
This is no longer the case after the unified IR refactor.
This PR migrates MakePackedAPI to a target dependent stage
and removes the un-necessary BindDevice pass.
* [RUNTIME] Allow non-nullable ObjectRef, introduce Optional<T>.
We use ObjectRef and their sub-classes extensively throughout our codebase.
Each of ObjectRef's sub-classes are nullable, which means they can hold nullptr
as their values.
While in some places we need nullptr as an alternative value. The implicit support
for nullptr in all ObjectRef creates additional burdens for the developer
to explicitly check defined in many places of the codebase.
Moreover, it is unclear from the API's intentional point of view whether
we want a nullable object or not-null version(many cases we want the later).
Borrowing existing wisdoms from languages like Rust. We propose to
introduce non-nullable ObjectRef, and Optional<T> container that
represents a nullable variant.
To keep backward compatiblity, we will start by allowing most ObjectRef to be nullable.
However, we should start to use Optional<T> as the type in places where
we know nullable is a requirement. Gradually, we will move most of the ObjectRef
to be non-nullable and use Optional<T> in the nullable cases.
Such explicitness in typing can help reduce the potential problems
in our codebase overall.
Changes in this PR:
- Introduce _type_is_nullable attribute to ObjectRef
- Introduce Optional<T>
- Change String to be non-nullable.
- Change the API of function->GetAttr to return Optional<T>
* Address review comments
* Upgrade all compiler flags to c++14
* Update as per review comment
* one weird trick.
* Added schedule knob for different workloads.
* Initial conv3d tensorcore working.
* Added conv3d tensorcore strategy.
* Added layout conversion to tensorcore friendly format for conv2d and conv3d.
* Add target name check.
* Fixed bad names and depthwise check.
* Removed duplicated attribute assignment.
* use funcs from prelude, pass around convert_map
* get relay input type from user ishape
* handle tuple unpack
* experimenting with static tensor array
* use prelude concat instead of cons + rev
* minor clean up
* fix layer norm conversion bug, unwrap tensor array
* add infer shape on tensor array
* pass around prelude for now
* compile worked but runtime error
* fix tensor array wrapping
* begin list dynamic test
* is_list_dynamic first version
* finish dynamic list test
* a few fix
* use shape_of function if Any is found
* improve size conversion
* working on adding free vars to loop block
* fixed inlined inner loop issue
* clean up free var handling
* add support for tensor array concat
* adding ta concat on last axis
* fix concat, but got runtime error
* disable concat on axis -1 for now
* add lstm tests
* revert unrelated change
* fix stacked bidir test
* minor fix to test
* relax tol a bit, revert dnnl change to avoid conflict
* simplify infer type, use input tensor shape rather than concat shape
* more shape fix
This PR enables the copy on write optimizations passes:
- Enable COW for IRModule both TIR and relay passes.
- Enabled COW for PrimFunc in TIR passes.
Need more thoughts into whether/how to enable COW
for relay::Function, due to some function passes depend
on the presence of IRModule for context information,
and the std::move of the related function to nullptr
might affect the related behavior.
* [RUNTIME] Introduce RValue reference(move) support to TypedPackedFunc
This PR introduces RValue reference support the PackedFunc calling convention to address the above issue.
Specifically, when an argument is a r-value reference, we will use a assign a different type code(`kObjectRValueRefArg`),
and pass `Object**` (the address to the Object pointer) instead through the values array.
The callee can choose to move out this Object pointer and set the original Object pointer from the caller side to be nullptr.
We also add an experimental move support to the python side(marked as _move so to indicate the dev nature).
This enhancement will enable copy on write optimizations through out the TVM stack.
* Address review comments
* fix compilation