-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIR][USMP] Added buffer info extraction pass #8468
Conversation
f901bdf
to
a13677d
Compare
a13677d
to
321e30f
Compare
Hey @manupa-arm, thanks for the nice PR! As a main thing I am a little bit worried about, I would love to discuss specifically on the IR-related change, because in the worse case, adding/changing/removing an IR node would result in malfunctioning of many passes. Therefore, we tend to keep the IR stable if possible, and scrutinize any changes to the IR. For example, when @masahi was adding the while node (really awesome work #7425), we discussed very carefully on the implication, and actually updated many passes that are affected by that particular change. As we are adopting the new RFC process, I would love to propose that if the RFC implies any IR modification, the modification should be written explicitly in a section (e.g. which fields are added), and be discussed really carefully on potential alternatives without IR change, and everything that could happen if the IR is changed (e.g. which passes won't work). CC: @jroesch @vinx13 @areusch @comaniac On this particular case, we are seeing a set of IR changes, including this PR, the 🙏 Many thanks! |
Hi @junrushao1994 , Yes, we are working on writing up the allocate_const RFC and hoping to post it soon. For this one's addition of pinned_memory attribute to allocate, happy to write up a RFC but I feel there is an alternative w/o changing the IR if thats preferred using AttrStmt -- let me know what you think. |
Thanks @manupa-arm . I believe @junrushao1994 's comment was mainly about the process. It would be great if we can separate the IR node change RFC/PRs from the feature RFC(USMP). since IR changes would involve more deliberation, and explicitly marking the RFC about the IR node change would help to get the folks involved in these parts without necessarily going to deep into the feature RFC. Back to the pinned memory itself, we might be able to fold some of that info into the PointerType storage_scope field as what @masahi did in some of his recent refactor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manupa-arm i didn't have time to do a full review but here's some early feedback
// We only statically memory plan only allocates with known | ||
// compile time sizes. | ||
auto buffer_info = BufferInfo(op->buffer_var->name_hint, size_bytes); | ||
buffer_info->SetPoolCandidates(ParseCommaSeperatedString(op->pinned_memory)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if pinned_memory is empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explained more and inserted checks
i think the current status of this PR is that it's blocked on apache/tvm-rfcs#22 . @manupa-arm do you agree? |
I think this is blocked on me doing RFC text changes in apache/tvm-rfcs#23 and reflecting that to USMP RFC. This one does not consider tir.allocate_const / tir.constants just yet; We are planning to add that in a seperate PR once apache/tvm-rfcs#22 is resolved and #8509 is landed. Sorry, I ll spend the next cycles on apache/tvm-rfcs#23 --> USMP RFC --> this one after landing this : #8795 which keeps getting conflicted |
bf17872
to
f006178
Compare
This has been updated to reflect the changes as per the discussion on the RFCs. |
03d1ba0
to
8294bcf
Compare
8294bcf
to
1954bde
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@areusch addressed the comments! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manupa-arm thanks, had a look over this. i think it's mostly straightforward and am mainly requesting some more comments for those less familiar.
cc @mbs-octoml @electriclilies @mikepapadim can you have a look?
import tvm | ||
from tvm import tir, script | ||
from tvm.ir import Range | ||
from tvm.script import tir as T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be a bit of too shortened--i think pylint would complain if we ran it on tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is following precedence from the code base, all the tvmscript based tests are like this. Thus, better to be consistent. Moreover, I think tvmscript printer uses this form now.
tests/python/unittest/test_tir_usmp_analysis_extract_bufferinfo.py
Outdated
Show resolved
Hide resolved
3e8a78e
to
de8e4f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @areusch for the review.
PTAL when you have some time.
import tvm | ||
from tvm import tir, script | ||
from tvm.ir import Range | ||
from tvm.script import tir as T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is following precedence from the code base, all the tvmscript based tests are like this. Thus, better to be consistent. Moreover, I think tvmscript printer uses this form now.
tests/python/unittest/test_tir_usmp_analysis_extract_bufferinfo.py
Outdated
Show resolved
Hide resolved
de8e4f1
to
10557aa
Compare
a friendly ping @mbs-octoml ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, finally got to this. LGTM, just some nits and a question about multiple calls to the same PrimFunc with diff buffers.
/*! \brief The pool candidates that this buffer can get pooled to*/ | ||
Array<PoolInfo> pool_candidates; | ||
/*! \brief The byte alignment required within the pool */ | ||
Integer alignment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I guess this has to be the gcm of the alignment constraints imposed by all user's of buffer -- is there any use for an Array to capture that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes -- that has to be captured at the creation of the tir.allocate node though. Therefore, at the point of BufferInfo creation that is already decided.
|
||
void UpdateAliases(const Array<PrimExpr>& args, const PrimFunc& func); | ||
|
||
Map<BufferInfo, tir::Stmt> buffer_info_map_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments for all these fields please
} | ||
|
||
void BufferInfoExtractor::VisitStmt_(const AllocateNode* op) { | ||
const auto& currect_scope_info = scope_stack_.top(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: current
return buffer_vars; | ||
} | ||
|
||
void BufferInfoExtractor::UpdateAliases(const Array<PrimExpr>& args, const PrimFunc& func) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At most one call per function, right? Or at least if there are multiple calls then they all use the same buffers. Am I reading that right? CHECK fail if that assumption fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also assumes the calls are seen after the PrimFunc defns, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this while integrating the USMP :) in my local. Added more code to support per-call analysis that lead sporadic liveness. Also added a test case to show this as well.
Therefore, now this pass could handle multiple calls per PrimFunc.
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
Swap key-value pairs of returned values of the buffer_info extraction pass. Change-Id: Ia4f7289592bc776ef6189a41a7891038751bf31f
Updating the USMP utility tests to include tests that test creation of PoolInfo and PoolAllocation Objects. Change-Id: I5d349d0ffcac6b0160072d832dd9d5418699228e
* Removing the unnecessary header : include/tvm/tir/usmp/analysis.h * Some nits and cleanup Change-Id: Iac3ddd9428c56cd8ef49cf643e797bf6fdf4e97a
* Change the class data members to have a trailing underscore Change-Id: I71809b3c73b0bc0cd133fad1392ae8c17c895ee4
Adding more documentation for data structures and the approach Change-Id: Ide2bfffaeff9add86853b6992017264e5d796299
* Added more documentation * Added functionality to handle multiple calls for the same PrimFunc with a test. Change-Id: Ib7c27b3cf17f415067a224f1e57d8b928f4c7c6f
10557aa
to
c130133
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbs-octoml @areusch I finally got around to address the comments! PTAL when you have some time.
/*! \brief The pool candidates that this buffer can get pooled to*/ | ||
Array<PoolInfo> pool_candidates; | ||
/*! \brief The byte alignment required within the pool */ | ||
Integer alignment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes -- that has to be captured at the creation of the tir.allocate node though. Therefore, at the point of BufferInfo creation that is already decided.
return buffer_vars; | ||
} | ||
|
||
void BufferInfoExtractor::UpdateAliases(const Array<PrimExpr>& args, const PrimFunc& func) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this while integrating the USMP :) in my local. Added more code to support per-call analysis that lead sporadic liveness. Also added a test case to show this as well.
Therefore, now this pass could handle multiple calls per PrimFunc.
* Attaching targets to PrimFuncs in the util test case Change-Id: I82960512659a346f6242b2b5789ec1120f8ea2cf
@areusch a friendly ping! |
alignment, | ||
) | ||
|
||
def set_pool_candidates(self, pool_candidates: list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: looks like this is cruft from a previous incarnation of this PR. TODO(@manupa-arm): remove in a follow-on
* [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
* [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
* [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
* [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
* [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
* [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
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.
There is a subsequent PR depends on this : manupak#1