Commit Graph

55 Commits

Author SHA1 Message Date
Eric Lunderberg 174d09ee2c [TE][TIR] Implement layout transformations, non-flat memory buffers (#9727)
* [TIR] Added BufferLoadNode::LegalizeDtype

When modifying a BufferLoad object, the return dtype must also be
updated.  This exposes the legalization function, so that passes that
use `BufferLoad::CopyOnWrite` to modify the buffer/indices don't need
to repeat the logic to update the dtype returned.

* Replacing Store/Load in Stmt/Expr Visitor/Mutator

* Removing Store/Load from optimization passes

- UpdatePointerStorageScope
- UnrollLoop
- ThreadSync
- LinearAccessPatternFinder
- StoragePlanRewriter
- VectorTypeRewriter
- VectorTypeAccessChecker
- NarrowDataType
- IRConvertSSA
- CompactBufferRegion

* Removing Store/Load from examples

- ConvertAddToSubtract

* Replacing Store/Load in StorageFlatten

Now, outputs BufferLoad/BufferStore with a flattened buffer object.

temp commit, replacing Store/Load, BufferBindUnwrapper

temp commit, replacing Store/Load, StorageFlattener

* Replacing Store/Load in utility passes.

- StmtSimplifier
- IRSubstitute
- BaseInliner
- FeatureVisitor

* Replacing Store/Load in analysis functions

- StorageAccessVisitor
- VarTouchedAnalysis
- MemoryAccessVerifier
- InplaceOpVerifier
- GPUCodeVerifier
- VarTouchVisitor
- LCADetector
- BlockReadWriteDetector
- InstrumentBoundCheckers

* Replacing Store/Load in lowering/legalization passes.

- MakeCrossThreadReduction
- CacheReadRewriter/CacheWriteRewriter
- InjectVirtualThread
- InjectDoubleBuffer
- InjectCopyIntrin
- LowerWarpMemory
- LowerThreadAllreduce
- LowerThreadAllreduce
- LowerCustomDatatypes
- LowerTVMBuiltin
- CoProcSync
- MergeDynamicSharedMemAllocations
- VectorizeLoop
- BF16Legalize

* Replacing Load/Store in codegens.

- Device code generators
  - CodegenC
  - CodegenLLVM
  - CodeGenOpenCL

- Utilities used during codegen
  - ArgBinder
  - MakePackedAPI
  - ReturnRewriter
  - SplitHostDevice

- Execution environments
  - CodeGenStackVM
  - CodeGenHybrid
  - AOTExecutorCodegen

* [UnitTest] Add unit tests to test physical layout remapping.

* Updated tvm::address_of() to hold BufferLoad instead of Load.

* [TIR] Added IndexMap class.

Holds a set of variables representing the input indices and
expressions in terms of those input indices.

TODO:

- Add validation, the index mapping should be invertible.
- Add helper function, apply mapping to a set of indices.
- Add helper function, apply mapping to bounds of input indices.

* Updated Buffer::vstore/vload to return BufferLoad/BufferStore objects.

StorageFlatten/FlattenBuffer passes updated to modify the
buffer/indices directly, rather than using vload/vstore.

- Primary purpose of vstore/vload is to allow IR written in python to
  define vectorized load/store.  This usage is maintained by returning
  a BufferLoad/BufferStore node whose index is a Ramp.

- Previously, vstore/vload was also used to compute the 1-d physical
  index of a location within a N-d tensor.  This usage will no longer
  be allowed, as it would not allow layout transformations to be
  performed after a schedule definition, but any uses of the buffer
  are flattened.

* [TE] Added Stage::transform_layout to the C++ TE implementation.

Adds an `Array<IndexMap>` in the stage to define the transformations
to be applied on the tensor's layout.  As of this commit, this mapping
isn't propagated into the TIR graph yet.

* Replace Store/Load with BufferStore/BufferLoad in ir_builder

* [TE] Added Stage.transform_layout to the Python TE interface.

Allows users to specify `s[A].transform_layout(mapping)`, and
propagate into the TE definitions.

* Added pre_flattened_shape/pre_flattened_stride fields to Buffer.

The shape and stride checks performed in ArgBinder::BindDLTensor
(called from MakePackedAPI) require the tensor shape/strides prior to
index flattening.  Therefore, though it is no longer used by the
low-level code generators, we must maintain that information for use
in MakePackedAPI.

* [UnitTest] Test N-d indices exposed to low-level codegen

When using te.AXIS_SEPARATOR in the call to .transform_layout, this
should define groups of axes, each of which is flattened to a single
axis, then exposed to the low-level codegen.

* [TIR] Added PrimFunc attribute "layout_transform_map", filled from TE.

Propagated the TE definition of the physical layout into the TIR
graph.

* Added pre_flattened_type.

If a boolean tensor is backed by an int8 buffer, the check on the
argument buffer's type should be against the boolean type.

When rebasing this PR, should be placed after the addition of
pre_flatten_shape/pre_flatten_strides.

* [UnitTest] Added tests for loop iteration order.

After transformation, the iteration order should follow the new
transformed axes.  In addition, the loop iteration variables should be
exposed through the TE interface for further manipulation.

* [TIR] Added BufferNode::axis_separators

- Add axis_separators to represent divisions between groups
  of tensor axes, where each group is flattened into a single
  output axis, to be exposed to the low-level code generators.

- Expose axis_separators to the python interface.

- Update existing C++ calls to the Buffer() constructor.

* [TIR] Added ApplyLayoutTransforms as part of StorageFlatten.

For any buffers that have layout transforms defined in the
"layout_transform_map" attribute of a PrimFunc, rewrite access into
the buffer such that they use the updated ordering.

* Update usage of ir_builder where necessary.

* [TE] Implement te::Transform

Similar to Fuse and Split, this represents a modification to the
existing loop iterations.

* [TE] Added Stage::set_axis_separators.

In C++, this is implemented as an `Array<IntImm>`, specifying
pre-flatteneing axes after which a new post-flattening should be
started.  The python interface uses a sentinel value
`te.AXIS_SEPARATOR` in the call to `transform_layout`, which is then
used to define the array of axis separators.

* [TIR] Expose tir.transform.ApplyLayoutTransforms for testing

* [TE] Rewrite loop iteration order

After .transform_layout, rewrite leaf_iter_vars to follow the updated
order.  Use the te::Transform iter_var relationship to track use of
the transformed variable.

* [TE] Fill BufferNode::axis_separators from StageNode

During ScheduleOps and SchedulePostprocToPrimfunc, the axis separators
defined in the stage must be passed through to the TIR BufferNode.

* [TE] Return transformed iteration variables

* Moved Buffer's pre-flatten information to PrimFunc.

Since the pre-flatten information is only used for validating user
inputs, it makes much more sense to store it alongside the buffer_map.

* Updated ethos-u C++ unit tests to remove use of Load/Store.

* Bugfix, layout transformation.

Error occured during conversion from TE to IRModule, when layout
transforms were applied to a reader of a `cache_read`.

* In test directory, replacing all instances of T.load.

* Return buffer object from tvm.tir.script.scope_handler.Allocate

Now that the load/store require buffer objects, allocation should also
return a buffer object to be used.

* Added .astype to tvm.script.tir.node.BufferSlice

Since `buf[i]` returns a `BufferSlice`, this lets the TIR examples
that use `buf[i].astype('out_dtype')` continue functioning.

* Replacing all T.store TIR calls.

* Added LOG(FATAL) in constructor of Store/Load nodes.

* Updated tvmscript parser to report error for Store/Load nodes.

* [TVMScript] Added T.preflattened_buffer stmt

Used to specify `PrimFunc::preflattened_buffer_map`. Takes an argument
of the postflattened buffer, so that it will work for both simple
declarations and `T.match_buffer` statements without needing to
introduce a param handle.  All other arguments are identical to
`T.match_buffer.`

* [TVMScript] Updated TVMscript for BufferLoad/BufferStore

- Use `T.preflattened_buffer` calls in TVMScript to represent
  `PrimFunc::preflattened_buffer_map`.

- Remove `T.buffer_decl` for return value of `T.allocate`, now that
  `T.allocate` returns a buffer.

- For buffer access as a different type, make a `T.buffer_decl` for
  those accesses.

* Updated test_tvmscript_roundtrip.py for BufferLoad/BufferStore.

* Updated TIR reference in USMP pool allocation unit tests.

Using let var handles as the data pointer in buffers, rather than just
as `T.load`/`T.store` arguments, requires annotation as
`T.Ptr[T.primtype]`, rather than as `T.handle`.

* fixup! Return buffer object from tvm.tir.script.scope_handler.Allocate

* fixup! Return buffer object from tvm.tir.script.scope_handler.Allocate

* fixup! Replacing all T.store TIR calls.

* fixup! Replacing all T.store TIR calls.

* fixup! Return buffer object from tvm.tir.script.scope_handler.Allocate

* fixup! In test directory, replacing all instances of T.load.

* tir.ComputeInline, correct variable count.

Previously, this metaschedule primitive relied on `tir::UndefinedVars`
ignoring the data pointer of BufferLoad/BufferStore nodes.  When
`tir::UndefinedVars` was updated to visit the data pointer, similar to
the previous behavior when visiting Load/Store nodes, this caused the
count of undefined variables to be unexpectedly high.

* fixup! Replacing all T.store TIR calls.

* fixup! Updated Buffer::vstore/vload to return BufferLoad/BufferStore objects.

* fixup! In test directory, replacing all instances of T.load.

* fixup! In test directory, replacing all instances of T.load.

* fixup! Replacing all T.store TIR calls.

* Expose Buffer index flattening function to Python.

* Updated test_tir_buffer.py offset tests.

Replacing calls to `Buffer.vload` with `Buffer.offset_of`, when
testing the index calculations.

* fixup! Replacing all T.store TIR calls.

* fixup! Replacing all T.store TIR calls.

* fixup! Updated Buffer::vstore/vload to return BufferLoad/BufferStore objects.

* fixup! Replacing Store/Load in lowering/legalization passes.

* fixup! Replacing all T.store TIR calls.

* fixup! Updated ethos-u C++ unit tests to remove use of Load/Store.

* fixup! Replacing Store/Load in lowering/legalization passes.

Fix linting for inject_double_buffer.cc

* fixup! Updated ethos-u C++ unit tests to remove use of Load/Store.

* fixup! Added .astype to tvm.script.tir.node.BufferSlice

* fixup! In test directory, replacing all instances of T.load.

* fixup! Replacing all T.store TIR calls.

* fixup! Replacing all T.store TIR calls.

* fixup! In test directory, replacing all instances of T.load.

* fixup! Replacing all T.store TIR calls.

* fixup! Replacing Store/Load in lowering/legalization passes.

* [UnitTests] Added T.preflattened_buffer in expected result

* fixup! In test directory, replacing all instances of T.load.

* [UnitTests] Bound checker update, compare against N-d buffer bounds.

* Fixup, bound checker vectorize test.

* fixup! Return buffer object from tvm.tir.script.scope_handler.Allocate

* [UnitTest] Fixed breakage in InjectRollingBuffer test.

Needed a bit more re-writing than usual, because the test was
explicitly calling lowering passes, then calling `tvm.build`.  Fixed
by using the standard lowering flow, with preprocessing steps
inserting with `tir.add_lower_pass`.

* fixup! Return buffer object from tvm.tir.script.scope_handler.Allocate

* [UnitTest] Fixed breakage in flatten buffer unit tests.

- Updated pass to allow BufferStore/BufferLoad nodes to be visited
  before the block's alloc buffer.

- Added `T.preflattened_buffer` annotations.

* fixup! Return buffer object from tvm.tir.script.scope_handler.Allocate

* [UnitTests] Fixed breakage in test_tir_buffer.py

- Updated vload test for new behavior.
- Added test for offset_of, testing behavior no longer in vload.
- Added null check for buffer visitor.

* fixup! Replacing Load/Store in codegens.

* [UnitTest] ComputeInline, opaque access test updates

* [UnitTest] Fixup, allow unit test to use `ib.pointer()[0]`.

* fixup! Replacing Load/Store in codegens.

The updated CodegenLLVM should use the BufferStore/BufferLoad
convention of indexing by `sizeof(dtype)`, rather than
`sizeof(dtype.element_of())`.

* fixup! Replacing Store/Load in lowering/legalization passes.

BF16Legalize should also update the preflattened_buffer_map, since it
is overwriting the `BufferNode::data` stored in the buffer_map.

* fixup! Replacing all T.store TIR calls.

* Fixed failing codegen c host unit tests.

- Generated functions were making `uint8_t*` parameter arguments for
  array handle for return value, rather than the earlier `void*`.

- New parameter type was due to using
  `PointerType(PrimType(DataType::UInt(8)))` as the type annotation, to
  be usable as `BufferNode::data`.

- Changing to `PointerType(PrimType(DataType::Void()))` still allows
  usage as buffer, more appropriately expresses semantics.

- Updated C codegens to allow `void*` types to be generated from
  variables with type annotation, in addition to the previous behavior
  of `DataType::Handle()` variables without type annotation.

* Fixup, StorageFlatten when applied to post-StorageRewrite functions.

Identified in a test that applied `tvm.lower`, then `tvm.build` on the
result.  If the result of an allocate node is used as the backing
buffer for multiple buffers, such as the output of the StorageRewrite
pass, then StorageFlatten would erroneously think that the second
occurrence was an usage without earlier definition.

* fixup, StorageFlatten

When flattening a boolean buffer, the backing buffer should have type
int8, not the preflattened buffer.

* Bugfix, correctly represent void* in LLVM IR.

* Update, replace tir.Load with tir.BufferLoad

* Added TVMScript error check for matching buffer/index dimensionality

Needed for tests/python/unittest/test_tvmscript_error_report.py::test_high_dim_store

* Bugfix, correct return type when lowering custom datatype.

* Bugfix, removed unused primfunc from test_tvmscript_complete.py

* Updated test_meta_schedule_postproc_verify_gpu_code.py TIR

Replaced Load/Store with BufferLoad/BufferStore.

* Allowed ramp nodes with buffer use analysis.

* Updated tests in test_meta_schedule_postproc_verify_gpu_code.py

Needed dummy writes to prevent buffer resizing, in order to trigger
the verification failure due to memory limits.

* Updated TIR examples to be compatible with buffer dimension check.

* Corrected section header in docstring.

* Corrected indices size check in CogeGenC.

* Fixed breakage in LowerThreadAllreduce.

Since the AllocateNode is rewritten, any buffers that refer to those
variables must also be rewritten.

* [UnitTests] Replaced Store/Load in CUDA codegen tests.

* Resolved breakage in C-based codegen for vectorized store/load.

Needed to update to new convention of using the buffer's element type
as the stride.

* Bugfix, incorrect LCA for buffer access in root scope.

This had been present before the BufferLoad/BufferStore changes, but
hadn't triggered on tests using Load/Store nodes.

* Added docstrings for TransformNode member variables.

* Added TODO for future removal of preflattened_buffer_map.

* Fixup, transform layout + cache write tests.

The correct sequence is to first apply any caching as needed, then to
apply layout transformations, and finally to apply thread binds for
the computation step.

* Bugfix, correct element type for scalarized access.

* Bugfix, cuda buffer indexing when declared as different type.

* Cuda codegen, update reference.

* Bugfix, lower allreduce

Loads of the output of the reduction should be replaced for all
buffers sharing a buffer pointer, not just for the buffer object
itself.

* Removed obsolete comment.

* Changed PrimFunc constructor preflattened_buffer_map to Optional

* Removed flatten_buffer argument from T.match_buffer.

* Correct call to VarUseDefAnalysis::VisitBuffer

* Reverted unintentional testing change, lanes=2.

* Updated lower_cross_thread_reduction to use buffer in allreduce

* Updated transform_layout test to disable CSE

* Updated CSE unit tests to use BufferStore

* Replaced Store/Load for vta.transform and unit tests.

* Updated unit tests for lower_cross_thread_reduction.

* Updated arange to use scalar tensors.

The start/stop/step tensors are declared as 0-d scalar tensors, but
were accessed as 1-d tensors.

* Fix breakage in ethosu constant encoding.

Buffers generated by "ethosu_copy" should have their buffer objects
rewritten, but shouldn't have their size updated in ethosu-specific
Call nodes.

* Fix breakage in ethosu call argument checks.

Need to pull out indices from BufferLoad holders, not Load.

* Resolve breakage from mismatched shape/index dimensions

* Split out encoded parameters from preflattened buffer map.

* Updated buffer shape/index dimensions to match in more ethosu tests

* Fixed lint error

* Removed debug code

* Moved arith::Analyzer local variable to class member

* Fixed SSA conversion of allocations.

Can occur if allocation is inside an unrolled loop.  Added unit test
to catch this failure mode.

* Ethos-u index/buffer dimension updates.

* Updated ethosu passes to handle buffer load/store.

* Resolved bug in tvmscript printing of duplicate buffers.

* Fix breakage in ethos-u test_assign_addresses, encode constants

* Apply same changes to T.allocate_const as to T.allocate

Return a buffer when used in TVMScript, allow for aliasing buffers.

* Fix lint errors.

* Further updates for ethos-u tests.

* Updated ethos.u buffer sizes in test.

* Updated tir.BindParams to use BufferLoad instead of Load.

* Updated topi.cuda.scan implementation to follow buffer dimensions.

* Resolved breakage when flattening AllocateConst nodes.

* Resolved breakages from latest merge with main.

* Corrected error in merge.

* Use empty indices for rank-0 tensor.

* Added ir_builder workaround for 1-d indexing.

* Consistent buffer access type in LLVM codegen, to match C codegen

* StorageRewrite, update indices of modified buffers.

* Dynamic relay nodes, access 0-d tensors with 0-d indices.

* BFloat16 legalization, update buffer type.

* Updated meshgrid to use 0-d index for 0-d buffer.

* Corrected boolean handling in Allocate nodes.

* Added workaround to unpack 1-d Tensor indices into N-d buffer indices.

* Resolved a few more failures in relay tests on cuda.

* Resolve linting

* CI bump

* Updated renormalize_split_pattern tests to use BufferLoad/BufferStore

* Fixed cuda codegen checks for BufferStore/Ramp.

* Simplify indices further, needed to avoid cuda register limit.

* fixed dyn onehot shape func accessing 1d buffer with ()

* Fixed codegen indexing for int4 scalar types.

* Temporary workaround for incorrect constant folding.

Need to further investigate vectorized LLVM constants

* s/find_allocate_usage/FindAllocateUsage/g

* Added buffer type consistency TODO.

* Improved comment on address_of Op.

* Rename LegalizeDtype to LegalizeDType, made private.

* fix format and lint errors

* Disable vectorization of AllocateConst buffer in StorageRewrite.

* Pass buffer_map through to the PrimFunc in cmsisnn

* try disabling problematic winograd test case

* try different way of buffer mapping in storage_rewrite

* Removed unnecessary ramp node in ir_builder.


* Updated LLVM codegen for buffer indexing.

TVM data arrays are always densely packed.  If the LLVM type
corresponding to a vectorized TVM datatype contains padding for
alignment, the array location should be computed based on the
primitive element type.


Co-authored-by: Masahiro Masuda <masahi129@gmail.com>
Co-authored-by: adstraw <astraw@octoml.ai>
2022-03-06 21:21:50 -05:00
Hua Jiang 37f7e57a04 Fix plint error. (#10394)
plint complain error in parser.py and test_vm.py just fix it.
2022-02-26 18:08:45 +09:00
Zihao Ye 920654cf91 [Bugfix][TVMScript] Convert BufferSlice to BufferLoad when used as range/loop start and end (#10370)
A quick fix of the parser issue mentioned in #10327 .
Ranges and loops require `start` and `stop` to be PrimExpr, however, `BufferSlice` is not always scalar so it's not a `PrimExpr`.
This PR performs the transformation.
2022-02-25 13:49:05 -08:00
Ruihang Lai 270c1b3219 [TIR] Misc minor updates (#10335) 2022-02-23 15:16:03 +08:00
Dmitriy Smirnov b5f1dabce4 [TIR] Tir constants integration into compilation pipeline (#8509)
* [TIR] Introduce tir.allocate_const to TIR

This PR is adding non-scalar constant representation in TIR. This is used to
express constants (i.e., parameters) in the TIR instead of bypassing the
TIR as it's done until now.

Change-Id: Id3afc4d7197260cb43ecde60f05ccbce3fc42430

Co-authored-by: Giuseppe Rossini <giuseppe.rossini@arm.com>
Change-Id: Id4a09a637c9c1fd7d49989c6c10f474a78569e18

* [TIR] Integrate tir constant nodes in compilation pipeline

This PR integrates tir.allocate_const to the compilation pipeline to support --link-params.

Change-Id: Ic8d0cb75d596299fcae7078b304598afbf0c5494

Co-authored-by: Giuseppe Rossini <giuseppe.rossini@arm.com>
Change-Id: Id98cc682bbfacfe75c4d8b260fd41658f1f196b2

* [TIR] tir.const extraction

This commit tries to implement an amendment to tir.constant RFC
with centralized storage of constant data within the IRModule
Please note that data and irmod_storage_idx are not mutual exclisive
further more the irmod_storage_idx is valid only immediatly after
prim func addition to the mod or after update within the mod.
If prim func is out of the the module scope then the index become
meangless. irmod_storage_idx also is not used in calculation of hash
function of the tir.constant node.

Change-Id: I40742ed580468b0252ea3fec02184cba65e20871

* unit test fixed

Change-Id: Ied2186554d4cbad44b2346216c8be92449e55732

* cmsis-nn codegen fix

Now handled case when params of the functions came as constants

Change-Id: I5874e182e34ef94e23048eaf3c61b01a56d91131

* Fixes for unittests

Change-Id: I5b82ee3f80337155706b5470973f494a301b5d90

* Rebasing tests fixes

Change-Id: I94ac87907081bab53c1dd1ab2db106ae057b4b19

* Linter: added method param description

Change-Id: I2f8c4c8d244b74c794abaa6079c46cc593ffcbdb

* Printing removal fix

This patch removes forgotten print in fuse_ops

Change-Id: I4bb5934f3b4cd5fde19d36a8e3319aae136bce8a

* Bugfix

Fixed concurrent map update bug here

Change-Id: Ifec3bf5030086d9079b9e493096f17dfd82297ec

* Reworked logic for not to introduce empty constant list to modue attrs

Change-Id: I082c85b3b4b70c218f0d714f5613ef6e178bd020

* Added support for tir builtin::tvm_access_ptr

This fixed unit tests for tests/python/integration/test_arm_mprofile_dsp.py

Change-Id: I10919f301ef9ddc3fd87f0e1a8414e9a52fc7938

* Unit test fix

Fixes unit tests in torch frontend

Change-Id: I6c179834f93dd202605d1ce5a7f07d987b9dc469

* Addressed requested changes

Addressed changes requested upstream

Change-Id: I741e52b89eb285732c23b1ac7ff277e757a088c3

* Namespace usage changed to conform earlier C++ standard

Change-Id: I1b29238cfe2a6bedb525f4f823a3a540f631d836

* Bugfix

Change-Id: I57a44b714b307278a243817ec2864e53ad31366b

* updated IRModuleNode::ExtractPrimFuncConstants

Updated IRModuleNode::ExtractPrimFuncConstants as per
request upstream.

Change-Id: I35db0145fb5827efd0445ce665d0c99465274016

* Minor changes

typo fixd
renamed ExtractPrimFuncConstants to ExtractConstants
removed getters/setters from FuseMutator and added parametrized
constructor

Change-Id: Ib2326805781779b88c963a8642ff683c8755956e

* Moved LinkedParam/LinkedParamNode

Moved LinkedParam/LinkedParamNode from tvm::tir namespace to tvm
namespace

Change-Id: Ie3f0303bd4f7890c6d680268c91f2051977bc7f4

* Addressed upstream comments

Changed BindParams argument to Array<NDArray>
Removed 'name' argument from te.const
Switched to in-depth comparision of NDArrays in constant de-duplication
Removed extra final comma from NDArrayToTIR
Changed return type of ConstantAllocationSize to int64_t
Made link_param a tvm.testing.parameter for test_fuse_take and test_fuse_gather_nd

Change-Id: I4285099cc63756aa5ebe91a5bd207d4135499b41

* Removed unnecessary forward declaration

+linter

Change-Id: I2a6c0d1f97773aeb1ae3f458da252a22079ccdb1

* Constant extractor now is a separate pass

Change-Id: Ia4adca9d3315b26fbdc006ef7c115900c081e303

* Added forgotten file + unit test fix

Change-Id: Ice305f4fefd13fe95e97574e6d63ffeb664621df

* Changed to IRModule pass

Refactored ExtractPrimFuncConstants to IRModule pass.
deDup -> DeDup
Refactored logic of Applicator supplementary class

Change-Id: I6c120d175eb6790ba90f176c4f856bde8f0c7c94

* bugfix after rebasing

Change-Id: Ie3ee6ea2479476a30f486baef74f20070f117942

* -v -> -vv to have more debug information

Change-Id: I12c63731663b9c9ea574b9ed5cb17311ba3cf701

Co-authored-by: Giuseppe Rossini <giuseppe.rossini@arm.com>
2022-02-22 23:33:30 +00:00
Ruihang Lai 470a1c7f2e [BugFix][TVMScript] Use operator is when recognizing TIR Module (#10175)
* [BugFix][TVMScript] Use operator `is` when recognizing TIR module

* Test
2022-02-07 23:23:42 -08:00
Eric Lunderberg 455c02a833 [TVMScript] Support T.buffer_decl using data pointer from Let/Allocate (#10099)
* [TVMScript] Added unit tests demonstrating desired functionality

* [TVMScript] Implemented parsing of T.Ptr[...]

These can be generated when exporting to TVMscript, but were not
parsable after being generated.

* [TVMScript] Updated buffer_var printing

LetStmt and AllocateNode can both be used to generate handles that are
used in Buffer objects.  In these cases, the Buffer declarations must
go after the handle declaration, not in the function header.

* Moved printing of var and buffer_decl into separate statements.

* Updated following @shingjan's review comments.
2022-02-03 12:04:37 -08:00
wrongtest f4af81c5f7 [TIRScript] fix parse StringImm value in for loop annotations (#9755)
* fix parse strimm value in for annotations

* flatten buffer allow runtime.String attr value

* remove unused import

* rebase and ensure flattened attr order
2021-12-20 18:47:17 +08:00
Yuanjing Shi 5c2855e698 [TVMScript][FIX] Fix number of arguments for T.Buffer[...] (#9758)
* fix number of arguments

* make test clear

* Update tests/python/unittest/test_tvmscript_syntax_sugar.py

Co-authored-by: Wuwei Lin <vincentl13x@gmail.com>

* only tuple for now

Co-authored-by: Wuwei Lin <vincentl13x@gmail.com>
2021-12-17 21:09:12 +09:00
Wuwei Lin 405fa23bce [TIR][Schedule] Add Annotate/Unannotate primitive (#9742)
Co-authored-by: Siyuan Feng <Hzfengsy@sjtu.edu.cn>
Co-authored-by: Bohan Hou <32121147+spectrometerHBH@users.noreply.github.com>
Co-authored-by: Hongyi Jin <3231950289@qq.com>
Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com>
Co-authored-by: Junru Shao <junrushao1994@gmail.com>
Co-authored-by: Wuwei Lin <wuwei@apache.org>
Co-authored-by: Xiyou Zhou <xiyou@octoml.ai>
2021-12-16 15:29:53 -08:00
driazati f0ae9d3313 Add make docs and doc building instructions (#9534)
* Update doc building instructions and pin dependencies

This pins the dependencies for the docs and adds `pytest` as a
dependency which was missing when I built. Tested out the
requirements.txt with a fresh `ubuntu:focal` Docker image to verify that
the required depedencies work.

* Address comments, add Makefile for docs and add to instructions

* Use Python for running scripts

* Fix lint, add lint command

* Add option for cpu to only run the precheck, address comments

* Fix 'make doc' usage, add some -x's

* Fix bad condition on --cpu, add defaults for envs

* Fix another 'make doc'

* Fix for running on MacOS

Co-authored-by: driazati <driazati@users.noreply.github.com>
2021-12-13 16:33:58 -08:00
Yuanjing Shi 40ecfec1da [TVMScript] Improve printer for TIR syntax sugar (#9680) 2021-12-10 12:19:47 -05:00
Manupa Karunaratne 3ce4fe47ca [TIR][USMP] adding the pass to convert to pool offsets (#9418)
* [TIR][USMP] adding the pass to convert to pool offsets

This commit adds a transform pass that consumes
the planned pool allocations using memory planning algorithm
that convertes them to pool offsets.

* adds two test cases for a linear structure with two pools
* adds test case with a single pool for residual structures

Change-Id: I9d31e854461b5c21df72d1452120d286b96791c0

* [TIR][USMP] adding the pass to convert to pool offsets

* Adding a toggle to produce TIR that is TVMScript printable for unit
testing
* Fixing the unit tests
* Ensure deterministic pool variable ordering.

Change-Id: I317675df03327b0ebbf4ca074255384e63f07cd6

* [TIR][USMP] adding the pass to convert to pool offsets

Fixing the references after changes in the memory planning
algorithm.

Change-Id: Id7c22356fd5de43d10a2b4fc70e978af2c6d599d

* [TIR][USMP] adding the pass to convert to pool offsets

* fixing the lint

Change-Id: I7ff920b92d14a9919c930a4b35a2169c77a57dd1

* [TIR][USMP] adding the pass to convert to pool offsets

* removing unnecessary defitinitions
* remove global var map
* adding explaination for let bindings to pointer type

Change-Id: I31bd1a9f3057ee7f06252263565b0f75c51e6d13

* [TIR][USMP] adding the pass to convert to pool offsets

* rebase changes
* making imports absolute
* fixing typos and removing unnecesary lines

Change-Id: I4c94b9955b001513fecb39ca94f81b1ad99c7bfc

* [TIR][USMP] adding the pass to convert to pool offsets

* fixing typos

Change-Id: I42c557fd394aefdf8c2e825c4e88770eb0732f9b
2021-12-09 14:45:16 +00:00
Yuanjing Shi e8889ae0e3 [TVMScript] Add syntax sugar for T.handle and T.match_buffer (#9492) 2021-12-08 10:30:27 -05:00
Yuanjing Shi c945b24c36 [TVMScript] Add for loop syntax sugar (#9620)
* add for loop syntax sugar

* remove prints

* better doc

* finish thread binding

* fix CI

* fix CI

* address comments

* update sstub

* fix CI

* remove failed test

* update stub

* address comments

* add decorator
2021-12-07 19:19:47 -05:00
Yuanjing Shi 459563d33b [TVMScript] Syntax sugar for reads & writes (#9634)
* add test file

* add syntax sugar support

* add comments

* cleanup

* update stub

* remove failed tests

* update stub with overload

* address comments
2021-12-06 20:00:43 -05:00
Tristan Konolige 7f683dabbe [TVMSCRIPT] Misc error message improvements (#9543)
* [TVMSCRIPT] Misc error message improvements

* only prevent indexing into handles with multiple indexes

* lint
2021-12-03 11:33:38 -08:00
wrongtest 86716a5f7d [TVMScript] support kTarget func attr in tir script (#9594)
* support kTarget func attr in tir script

* fix variable redefine lint error

* use Target::Export()

* fix cr issues
2021-12-01 12:46:48 -08:00
Siyuan Feng e5cbf46cdd [BUG][TVMScript] fix block range error (#9574) 2021-11-24 06:23:21 -08:00
Manupa Karunaratne 18730c45be [TIR][USMP] Added buffer info extraction pass (#8468)
* [TIR][USMP] Added buffer info extraction pass

This commit adds a pass that takes the main (call graph of operators)
TIR PrimFunc and each operators also as TIR PrimFunc. The pass will
traverse through all TIR PrimFunc starting the from main. Thereafter,
it will extract information from tir.allocates. Among the information,
the liveness conflicts are reported.

* Added test for a linear model
* Added test for parallel/serial mixed for loops
* Added test for a substructure of inception-style model.
* Exposed buffer_info creation to python
* Added member functions to update pool info
* Unit tests to cover functionality of buffer_info

Change-Id: I5e163ac3e83c830629a5d34ed4407c9962701c60

* [TIR][USMP] Added buffer info extraction pass

Swap key-value pairs of returned values of the buffer_info
extraction pass.

Change-Id: Ia4f7289592bc776ef6189a41a7891038751bf31f

* [TIR][USMP] Added buffer info extraction pass

Updating the USMP utility tests to include tests
that test creation of PoolInfo and PoolAllocation
Objects.

Change-Id: I5d349d0ffcac6b0160072d832dd9d5418699228e

* [TIR][USMP] Added buffer info extraction pass

* Removing the unnecessary header : include/tvm/tir/usmp/analysis.h
* Some nits and cleanup

Change-Id: Iac3ddd9428c56cd8ef49cf643e797bf6fdf4e97a

* [TIR][USMP] Added buffer info extraction pass

* Change the class data members to have a trailing underscore

Change-Id: I71809b3c73b0bc0cd133fad1392ae8c17c895ee4

* [TIR][USMP] Added buffer info extraction pass

Adding more documentation for data structures
and the approach

Change-Id: Ide2bfffaeff9add86853b6992017264e5d796299

* [TIR][USMP] Added buffer info extraction pass

* Added more documentation
* Added functionality to handle multiple calls
  for the same PrimFunc with a test.

Change-Id: Ib7c27b3cf17f415067a224f1e57d8b928f4c7c6f

* [TIR][USMP] Added buffer info extraction pass

* Attaching targets to PrimFuncs in the util test case

Change-Id: I82960512659a346f6242b2b5789ec1120f8ea2cf
2021-11-23 09:44:44 -08:00
Yuanjing Shi cdca84aa1d [TVMScript][Fix] Add type hints for more uncovered cases (#9505)
* add support for prevously uncovered cases

* remove PrimExpr import

* add exp test and mypy ignore

* disable ling too long

* resolve long line

* nit

* add dtype to unary ops
2021-11-22 18:55:38 -05:00
Siyuan Feng 3f9b72d1f6 [TVMScript] Report error if add attr to implicit root block (#9507)
* fix implict root block attrs

* lint
2021-11-15 13:07:35 -05:00
Yuanjing Shi 00b0a812e7 [TIR] Add type hint for TIR (#9432)
* add init

* get rid of span

* afs header

* update scope_handler

* rm tir/__init__.pyi

* fix linting

* fix lint

* new test case

* add axis module

* address comments

* redefine ty types

* lint

* address comments

* address comments

* fix ci

* add test cases

* fix CI

* address comments

* add types

* mypy --strict

* comments

* update test comments

* linting fix

* address comments

* add pylint for tir type check

* address comments

* move doc string

* comments

* getter setter

* add PrimExpr, IterVar and Var

* add sequence

* change for handle
2021-11-09 07:29:32 -08:00
Siyuan Feng c99f55f0a5 [TVMScript] Use // and % for FloorDiv/FloorMod (#9437) 2021-11-03 13:12:09 -04:00
Ruihang Lai 5e62db54ad [TVMScript] Parser for Lambdas, Parser/Printer for CommReducer (#9358)
* CommReducer Parser/Printer

* update argmax unit test

* update doc

* lint fix

* add unit tests with multiple reducers
2021-10-24 14:24:40 -07:00
Siyuan Feng d23688c3e5 update block syntax (#9286) 2021-10-18 13:59:17 -04:00
Manupa Karunaratne 2dae30372c Adding annotations for tir.allocate (#9168)
* Adding annotation for tir.allocate

This commit is adding annotations for tir.allocate
node to be used as hints for future transformations.

Change-Id: I02a3a875c38c3edd449385da5b741ef4958bb47f

* Adding annotation for tir.allocate

* adding tvmscript support
* adding tir text printing support

Change-Id: Id0b6725b2e79c23f6b8ff192772f1ea4125a27c2
2021-10-07 20:44:59 +08:00
Bohan Hou 47095d765f [Unittest] Fixing unittest (#9180) 2021-10-02 17:49:20 +08:00
Siyuan Feng e7af601636 [TVMScript] Script namespace changes (#9115)
Co-authored-by: Junru Shao <junrushao1994@gmail.com>
Co-authored-by: Zihao Ye <zihaoye.cs@gmail.com>
Co-authored-by: Tristan Konolige <tristan.konolige@gmail.com>
2021-10-01 13:10:25 -07:00
Siyuan Feng e1ae821c7d Add while node support in TVMScript (#9004)
* support while

* update synr version
2021-09-14 13:55:42 -04:00
Siyuan Feng 22dbc3a932 [TVMScript] Enhance printer (#8934) 2021-09-06 14:18:24 -07:00
Siyuan Feng 8e27d6c18f fix error report on Store (#8895) 2021-09-01 17:49:12 -04:00
Siyuan Feng 2a8950b5c0 [TensorIR] Support for match_buffer from subregion (#8585)
Co-authored-by: Junru Shao <junrushao1994@gmail.com>
Co-authored-by: Bohan Hou <32121147+spectrometerHBH@users.noreply.github.com>
Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com>
Co-authored-by: Hongyi Jin <3231950289@qq.com>
Co-authored-by: Wuwei Lin <wuwei@apache.org>
2021-07-30 22:06:38 -07:00
Ruihang Lai 5012462ef8 [TensorIR][M2a] Reduction Factoring (RFactor) (#8544)
Co-authored-by: Junru Shao <junrushao1994@gmail.com>
Co-authored-by: Siyuan Feng <Hzfengsy@sjtu.edu.cn>
Co-authored-by: Bohan Hou <32121147+spectrometerHBH@users.noreply.github.com>
Co-authored-by: Hongyi Jin <3231950289@qq.com>
Co-authored-by: Wuwei Lin <wuwei@apache.org>
2021-07-30 22:04:02 -07:00
masahi bef7bf9b2b [Refactor] Remove AttrStmt with storage_scope key (#8516)
* Remove all attr::storage_scope usage

* pyformat

* fixed VTA tests

* Update TIR text printer to print storage_scope on allocate

* print storage scope in AllocateNode ReprPrinter

* Fixed accidently removed scope tag check

* remove unused function

Co-authored-by: masa <masa@pop-os.localdomain>
2021-07-29 14:29:14 -05:00
Tianqi Chen e664ef0be8 [PRINTER] Fix the repeatitive cast in scripr printing (#8531) 2021-07-24 16:53:00 +09:00
masahi 1a1be09c24 [Refactor] Remove scope attribute from Buffer class (#8463)
Co-authored-by: masa <masa@pop-os.localdomain>
2021-07-20 16:19:46 -04:00
Honghua Cao 44f1baf794 [TVMSCRIPT] Support tir.abs node in tvm script (#8488)
Co-authored-by: honghua.cao <honghua.cao@streamcomputing.com>
2021-07-16 22:13:58 -04:00
masahi 1a26733b8e [Refactor] Enforce attaching storage scope to PointerType (#8366)
* Add storage scope to ProducerRealize, always create a buffer with scope

* update schedule_ops.cc

* update schedule_postproc_to_primfunc.cc

* restore more realize_scope

This reverts commit b66c3baa54feeb8e34016713a1be21802b3296bf.

* make the default scope be "" instead of None in ir builder

* restore realize_scope visit in storage_flatten.cc

* update storage_access.cc

* make sure buffer var is of PointerType in ir builder

This reverts commit e650b6c24cabd52a073064e51c2e4fee816e88fd.

* enforce default storage scope of global

* added remap pass but does not work yet

* fixed all reduce issue

This reverts commit 8e20003c5325085ed22ee57180aca18644b3b5ab.

* simplify

* trying mitigation for aot test

* merge remaining changes from initial branch

* remove use of attr::storage_scope from codegen

* restore a visit to AttrStmt with attr::storage_scope in storage_rewrite

* disable check

* lint fix

* revert default scope to ""

* format

* fix volatile access to shared mem in lower all reduce

* fixed gpu coorporative load/store test

* pass storage scope to PointerType in tvm script parser

This reverts commit 99cfb9d18781dcfdea169d920450f9063ab18b6b.

* fixed tvmscript roundtrip test

* fixed tir flatten buffer test

* fixed test_tir_transform_hoist_if.py

* use storage scope global by default in aot_executor_codegen.cc

* add missing default storage scope in create_primfunc.cc

* restore StorageInfo struct in llvm backend

* UpdateStorageScope -> WithStorageScope

* fixed lower warp memory test

* GetStorageScope -> GetPtrStorageScope

* Enable storage scope invariant check in AttrStmt constructor

* remove GetPtrStorageScope and WithStorageScope from public header

* move RemapStorageScope to its own file

* add more method to RemapStorageScope

* update lower_thread_allreduce to use RemapStorageScope

* RemapStorageScope -> UpdatePointerStorageScope

* remove realize_scope from hybrid script

* removed realize_scope in schedule_ops

* remove realize_scope from schedule_postproc_to_primfunc

* remove remaining realize_scope usage from schedule_ops.cc

* remove realize_scope usage from storage_flatten.cc

* fixed test_tir_transform_lower_warp_memory.py following realize_scope removal

* Add storage scope to ProducerRealize, always create a buffer with scope

* update schedule_ops.cc

* update schedule_postproc_to_primfunc.cc

* restore more realize_scope

This reverts commit b66c3baa54feeb8e34016713a1be21802b3296bf.

* make the default scope be "" instead of None in ir builder

* restore realize_scope visit in storage_flatten.cc

* update storage_access.cc

* make sure buffer var is of PointerType in ir builder

This reverts commit e650b6c24cabd52a073064e51c2e4fee816e88fd.

* enforce default storage scope of global

* added remap pass but does not work yet

* fixed all reduce issue

This reverts commit 8e20003c5325085ed22ee57180aca18644b3b5ab.

* simplify

* trying mitigation for aot test

* merge remaining changes from initial branch

* remove use of attr::storage_scope from codegen

* restore a visit to AttrStmt with attr::storage_scope in storage_rewrite

* disable check

* lint fix

* revert default scope to ""

* format

* fix volatile access to shared mem in lower all reduce

* fixed gpu coorporative load/store test

* pass storage scope to PointerType in tvm script parser

This reverts commit 99cfb9d18781dcfdea169d920450f9063ab18b6b.

* fixed tvmscript roundtrip test

* fixed tir flatten buffer test

* fixed test_tir_transform_hoist_if.py

* use storage scope global by default in aot_executor_codegen.cc

* add missing default storage scope in create_primfunc.cc

* restore StorageInfo struct in llvm backend

* UpdateStorageScope -> WithStorageScope

* fixed lower warp memory test

* GetStorageScope -> GetPtrStorageScope

* Enable storage scope invariant check in AttrStmt constructor

* remove GetPtrStorageScope and WithStorageScope from public header

* move RemapStorageScope to its own file

* add more method to RemapStorageScope

* update lower_thread_allreduce to use RemapStorageScope

* RemapStorageScope -> UpdatePointerStorageScope

* remove realize_scope from hybrid script

* removed realize_scope in schedule_ops

* remove realize_scope from schedule_postproc_to_primfunc

* remove remaining realize_scope usage from schedule_ops.cc

* remove realize_scope usage from storage_flatten.cc

* fixed test_tir_transform_lower_warp_memory.py following realize_scope removal

* Address comments

* Remove blank line diff

Co-authored-by: Masahiro Masuda <masahi@129@gmail.com>
Co-authored-by: masa <masa@pop-os.localdomain>
2021-07-13 15:32:42 -04:00
Honghua Cao 513fcf4bb7 [TVMSCRIPT] TVMScript Parser support BufferSlice indices (#8408)
Co-authored-by: honghua.cao <honghua.cao@streamcomputing.com>
2021-07-09 14:33:23 -04:00
Lunderberg ee65ab7a4a [PyLint] Minor updates to pass pylint locally. (#8424)
With either the ci_lint docker image, or the matched version of
pylint==2.4.4, I got two lint errors running locally that didn't show
up in the CI.  Fixing them.

Co-authored-by: Eric Lunderberg <elunderberg@octoml.ai>
2021-07-09 10:15:19 +08:00
Honghua Cao 35d71b1211 [TVMSCRIPT] add more type support in script function parameter (#8235)
* [TVMSCRIPT] add float type support in script function

* [TVMSCRIPT] add more type support in script function parameter

Co-authored-by: honghua.cao <honghua.cao@streamcomputing.com>
2021-06-23 17:05:05 +08:00
Tristan Konolige 96a7a5811f [TVMSCRIPT] Fix printing of rank 0 buffer access (#8215)
* [TVMSCRIPT] Fix printing of rank 0 buffer access

Also improve error messages and fix min/max/Select.

* fixes

* return fix

* remove print
2021-06-16 10:26:01 -07:00
Honghua Cao 55459e74dd [TVMSCRIPT] Add tir.min node in tvm script (#8219)
Co-authored-by: honghua.cao <honghua.cao@streamcomputing.com>
2021-06-09 09:52:28 -04:00
Mehrdad Hessar a1cd6d51b8 fix py files (#8194) 2021-06-04 23:22:46 +01:00
Siyuan Feng 22c8f8cca5 [TensorIR][Pass][M1c] FlattenBuffer (#7962)
Co-authored-by: Tianqi Chen <tqchen@users.noreply.github.com>
Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com>
2021-05-03 10:28:28 -07:00
Manupa Karunaratne 1fb32b0551 [TIR] An analysis pass to calculate workspace size for primfuncs (#7859)
* Add workspace size calculation for primfuncs

This commit introduces functionality to query the workspace size
as required by a tir primfunc by looking at tir.allocates inside of it

Change-Id: I6f8ca90408b6e35d17ec818998a0f158a268a2a6

* Add workspace size calculation for primfuncs

*change int --> size_t

Change-Id: If7fafec0269937d70184e7696e44386b74116d86

* Add workspace size calculation for primfuncs

* int --> size_t change for analysis.h

Change-Id: I9e5c5e5f8458663390c50cf56f1a11910687928d

* Add workspace size calculation for primfuncs

* lambda scope fix

Change-Id: I0c9b4c529150de8e0a5e170887cc935b7d0f6af2

Co-authored-by: Chenfan <jcf94@outlook.com>
2021-04-18 20:21:32 +08:00
Siyuan Feng 7f567264ae [TensorIR] [Script] adding support for opaque block (#7829)
* change complete tag

* add parsing support for opaque block

* address and add testcase

* address

* address
2021-04-13 14:08:48 -07:00
Siyuan Feng fffed0ff91 [TensorIR] TVMScript Parser/Printer (#7630)
Co-authored-by: Bohan Hou <32121147+spectrometerHBH@users.noreply.github.com>
Co-authored-by: Junru Shao <junrushao1994@gmail.com>
Co-authored-by: Tianqi Chen <tqchen@users.noreply.github.com>
Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com>
Co-authored-by: Hongyi Jin <3231950289@qq.com>
Co-authored-by: Wuwei Lin <wuwei@apache.org>
Co-authored-by: Tristan Konolige <tristan.konolige@gmail.com>
Co-authored-by: Cody Yu <comaniac0422@gmail.com>
2021-03-20 16:22:53 -04:00
Tianqi Chen 7340c02d0e [TIR][REFACTOR] ForNode introduce thread binding and remove legacy field (#7306)
[TIR][REFACTOR] ForNode update

- Remove deprecated device_api.
- Add ThreadBinding for_type.
- Add additional annotations.

More style consistency refactor to make the ForNode
to be consistent with rest of the codebase.

- ForType => ForKind
- Add constant prefix k to enum consts per Google C style
- Introduce ForKind to the python side.
2021-01-18 23:00:11 -08:00