') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); [TIR Pass] Decouple flatten buffer to lower opaque block and flatten buffer. by FredJia-intellif · Pull Request #12172 · apache/tvm · GitHub
Skip to content

[TIR Pass] Decouple flatten buffer to lower opaque block and flatten buffer. - #12172

Merged
Hzfengsy merged 1 commit into
apache:mainfrom
FredJia-intellif:dev_flatten_buffer
Jul 27, 2022
Merged

[TIR Pass] Decouple flatten buffer to lower opaque block and flatten buffer.#12172
Hzfengsy merged 1 commit into
apache:mainfrom
FredJia-intellif:dev_flatten_buffer

Conversation

@FredJia-intellif

@FredJia-intellifFredJia-intellif commented Jul 25, 2022

Copy link
Copy Markdown
Contributor

This PR intends to decouple flatten buffer pass to lower opaque block and flatten buffer passes. Test cases have been added.

Reasons for the change:

  • Lower opaque block and flatten buffer pass names can express clearly what they do.

  • It's more simply to analyze the buffer shape before flatten buffer with multi-dimension.

@Hzfengsy

Copy link
Copy Markdown
Member

Will review it tomorrow. also cc @spectrometerHBH@Lunderberg

Comment threadsrc/tir/transforms/flatten_buffer.cc
Comment threadinclude/tvm/tir/transform.h Outdated

@HzfengsyHzfengsy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall lgtm

Comment threadtests/python/unittest/test_tir_transform_flatten_buffer.py Outdated
Comment threadtests/python/unittest/test_tir_transform_lower_opaque_block.py Outdated
@FredJia-intellif
FredJia-intellifforce-pushed the dev_flatten_buffer branch 3 times, most recently from f9c7263 to afbc5a8CompareJuly 26, 2022 15:28
@Hzfengsy
Hzfengsy merged commit 5711c35 into apache:mainJul 27, 2022
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Aug 30, 2022
For buffers with more than one physical axis, the `axis_separators`
are required in order to know which groups of logical axes to fuse
into each physical axis. The implementation in `tir.FlattenBuffer`
assumed that all buffers were being flattened to a single physical
axis. Because `tir.LowerOpaqueBlock` replaces the
`BlockNode::alloc_buffers` with `Allocate` nodes, `tir.FlattenBuffer`
no longer has access to the axis separators and performs inconsistent
flattening for `Allocate` as opposed to `BufferLoad`/`BufferStore`.
This was introduced in apache#12172, which
decoupled the lowering/flattening steps.
The commit reorders the `tir.FlattenBuffer` to occur before
`tir.LowerOpaqueBlock`, to make use of the axis separators. Any
`Allocate` nodes that exist at that point (e.g. from hand-written
schedules) are still flattened to 1-d physical buffers, but the
`BlockNode::alloc_buffers` are flattened according to the axis
separators.
wrongtest-intellif pushed a commit that referenced this pull request Sep 8, 2022
* [TIR] Moved tir.FlattenBuffer to occur before tir.LowerOpaqueBlock
For buffers with more than one physical axis, the `axis_separators`
are required in order to know which groups of logical axes to fuse
into each physical axis. The implementation in `tir.FlattenBuffer`
assumed that all buffers were being flattened to a single physical
axis. Because `tir.LowerOpaqueBlock` replaces the
`BlockNode::alloc_buffers` with `Allocate` nodes, `tir.FlattenBuffer`
no longer has access to the axis separators and performs inconsistent
flattening for `Allocate` as opposed to `BufferLoad`/`BufferStore`.
This was introduced in #12172, which
decoupled the lowering/flattening steps.
The commit reorders the `tir.FlattenBuffer` to occur before
`tir.LowerOpaqueBlock`, to make use of the axis separators. Any
`Allocate` nodes that exist at that point (e.g. from hand-written
schedules) are still flattened to 1-d physical buffers, but the
`BlockNode::alloc_buffers` are flattened according to the axis
separators.
* Add unit test to validate non-flat memory after tvm.lower
* Explicitly write T.reads for test on BufferRegion updates
* Update incorrect docstring for test
* Use DeclBuffer information in FlattenBuffer
The DeclBuffer node can be inserted during LowerOpaqueBlock, then
provide the missing Buffer information required to flatten the
allocation.
* Use T.allocate in unit tests
With the insertion of `DeclBuffer` nodes, `LowerOpaqueBlock` no longer
needs to be before `FlattenBuffer`, and has been moved back to its
original position. Revering the tests to use `T.allocate` instead of
`T.alloc_buffer` more closely represents the functions as they are
being lowered.
* Fix usage of T.decl_buffer in updated tests
* Update LowerOpaqueBuffer to expect the DeclBuffer nodes
* Strip DeclBuffer annotation in FlattenBuffer
The DeclBuffer annotations aren't yet supported in all passes. This
restricts them to being introduced in LowerOpaqueBuffer, then
immediately removed in FlattenBuffer.
* Strip out all DeclBuffer nodes in FlattenBuffer
* Update unit tests to remove expectation of DeclBuffer nodes
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
* [TIR] Moved tir.FlattenBuffer to occur before tir.LowerOpaqueBlock
For buffers with more than one physical axis, the `axis_separators`
are required in order to know which groups of logical axes to fuse
into each physical axis. The implementation in `tir.FlattenBuffer`
assumed that all buffers were being flattened to a single physical
axis. Because `tir.LowerOpaqueBlock` replaces the
`BlockNode::alloc_buffers` with `Allocate` nodes, `tir.FlattenBuffer`
no longer has access to the axis separators and performs inconsistent
flattening for `Allocate` as opposed to `BufferLoad`/`BufferStore`.
This was introduced in apache#12172, which
decoupled the lowering/flattening steps.
The commit reorders the `tir.FlattenBuffer` to occur before
`tir.LowerOpaqueBlock`, to make use of the axis separators. Any
`Allocate` nodes that exist at that point (e.g. from hand-written
schedules) are still flattened to 1-d physical buffers, but the
`BlockNode::alloc_buffers` are flattened according to the axis
separators.
* Add unit test to validate non-flat memory after tvm.lower
* Explicitly write T.reads for test on BufferRegion updates
* Update incorrect docstring for test
* Use DeclBuffer information in FlattenBuffer
The DeclBuffer node can be inserted during LowerOpaqueBlock, then
provide the missing Buffer information required to flatten the
allocation.
* Use T.allocate in unit tests
With the insertion of `DeclBuffer` nodes, `LowerOpaqueBlock` no longer
needs to be before `FlattenBuffer`, and has been moved back to its
original position. Revering the tests to use `T.allocate` instead of
`T.alloc_buffer` more closely represents the functions as they are
being lowered.
* Fix usage of T.decl_buffer in updated tests
* Update LowerOpaqueBuffer to expect the DeclBuffer nodes
* Strip DeclBuffer annotation in FlattenBuffer
The DeclBuffer annotations aren't yet supported in all passes. This
restricts them to being introduced in LowerOpaqueBuffer, then
immediately removed in FlattenBuffer.
* Strip out all DeclBuffer nodes in FlattenBuffer
* Update unit tests to remove expectation of DeclBuffer nodes
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@FredJia-intellif@Hzfengsy@wrongtest-intellif