Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TIR] tir.transform.StorageFlatten refactor (#9091)
* [TE] Improved flexibility of ArgBinder::BindDLTensor Allowed a compact DLTensor to bind to a Buffer object that defines strides, if the strides defined correspond to a compact layout. * [TIR] Exposed ElemOffset as a member function of BufferNode. * [TE] Pulled shape determination out of StorageFlattener Previously, StorageFlattener would determine the shape of a physical buffer based on the extents of the BufferRealizeNode. Pulled these out into a separate BufferShapeLegalize pass. After this pass, all buffers have a shape that matches the buffer realization extents. * [TE] Refactor stride calculation out of StorageFlattener Previously, StorageFlattener would handle any attr::dim_align annotations. Now, this is pulled out into a separate BufferStrideLegalize pass. * [TE] Refactor thread scope propagation out of StorageFlattener. Previously, StorageFlattener would use the scope in IterVar to assign a scope to allocated buffers, where not otherwise defined. This has been pulled out into a separate ThreadScopePropagate pass. * [TE] Refactor buffer bind mapping out of StorageFlattener. Previously, StorageFlattener would look for `attr::buffer_bind_scope` to determine if a Buffer object is a view into another buffer, and would apply that mapping while making the Allocate/Store/Load nodes. Now, the mapping of buffer binds is pulled out into a separate BufferStrideUnwrapper pass. This also resolves an issue in which BufferLoad/BufferStore nodes that refer to a Buffer defined through `attr::buffer_bind_scope` would generate Load/Store nodes that point to the linked buffer, rather than the actual buffer. * [TIR] Removed checks on buffer->shape.size() Even after BufferShapeLegalize, rank-zero tensors may have an empty shape. * [TIR] Relaxed check on a bufferview's striding. Original refactoring requiring that a bufferview have no explicit striding, and instead take the striding from the buffer that it is viewing. Modified to allow bufferview to specify striding, so long as it is consistent with the viewed buffer's striding. This reproduces the behavior of StorageFlatten before the refactoring. * [TIR] Fixed StorageFlatten test for shape_legalize. AttrStmtNodes that contain rewritten Buffers need to be rewritten as well. * [TIR] Assigned storage scope The earlier stage of the refactor left a buffer's storage scope undefined if it's scope was not determined by the IterVar of a loop containing its allocation. Now, these are explicitly set to StorageScope::kGlobal, to match the previous behavior of StorageFlatten. * Updated ICHECK_EQ to CHECK_EQ for a test that depends on user-provided data. * Added comments in storage_flatten.cc, indicating why buffer_bind_scope needs special handling. * Updated comment with a few examples of where compact buffers are assumed to have no strides defined. * Updated following @csullivan's comments. * Added fuzzy mapping to the BufferShapeLegalize. Maintains earlier behavior of StorageFlatten, which allows buffer views to be mapped to higher dimension buffers, if the view extent is 1 in each extra dimension. * Updated BufferShapeLegalize, asserts need to be inside the buffer_bind_scope. * Pulled all shape-dependent behavior into BufferShapeLegalize. Previously, BufferBindUnwrapper passed fuzzy_match=true to ArgBinder::BindBuffer, which could change the number of dimensions. Now, all buffer dimensions should be updated prior to BufferBindUnwrapper, and it is an error to have mismatched dimensions in BufferBindUnwrapper. * Added another pass to remove verifiable assert statements. ArgBinder::BindBuffer inserts these assert statements if they are not verifiable at the time of substitution. Previously, with one giant substitution, the assertions were verifiable at that time. After the refactor, with substitutions done in multiple stages for shape/stride/buffer_bind_scope, we need to clean up any assertions that are verifiable after all substitutions have occurred. * Minor cleanup - Removed StorageFlattener::BufferEntry::RelIndex, behavior already handled by BufferShapeLegalize. - Improved comments and error messages. - Extracted duplicate behavior in BufferLoad/BufferStore handling in BufferShapeLegalize. * Updated to handle BufferRealizeNode with no defined bounds. * Updated to be less aggressive when checking AssertStmt A true Assert statement can be removed, but a false Assert statement requires CFA to give as a compile-time error. Since we only need the removal of true assert statements, skipping the CFA this time.
- Loading branch information