-
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] Get read/write access precisely for opaque access. #11110
[TIR] Get read/write access precisely for opaque access. #11110
Conversation
@@ -185,7 +185,7 @@ def opaque_access_load(a: T.handle, c: T.handle) -> None: | |||
T.writes(C[0:128, 0:128]) | |||
T.evaluate( | |||
T.tvm_access_ptr( | |||
T.type_annotation(dtype="float32"), B.data, 0, 128, "r", dtype="handle" | |||
T.type_annotation(dtype="float32"), B.data, 0, 128, 1, dtype="handle" |
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.
It would be great if we could also handle "r"
and "w"
for better readability
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.
OK, I use access_prt in this case.:
T.evaluate(B.access_ptr("r", extent=128))
f1f152a
to
42dc437
Compare
sch = tir.Schedule(exp_exp_opaque_access_with_tvm_access_ptr, debug_mask="all") | ||
compute = sch.get_block("compute") | ||
sch.compute_inline(compute) | ||
print(sch.mod.script()) |
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.
remove print
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.
removed
bb730de
to
2998158
Compare
include/tvm/tir/buffer.h
Outdated
int content_lanes = 1, | ||
PrimExpr offset = IntImm(DataType::Int(32), 0)) const; | ||
int content_lanes = 1, PrimExpr offset = IntImm(DataType::Int(32), 0), | ||
PrimExpr extent = PrimExpr(ObjectPtr<Object>(nullptr))) const; |
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.
if extent
can be nullptr, please use Optional<PrimExpr>
instead of PrimExpr
.
@@ -181,6 +181,34 @@ void BlockReadWriteDetector::VisitStmt_(const IfThenElseNode* op) { | |||
} | |||
|
|||
void BlockReadWriteDetector::VisitExpr_(const CallNode* op) { | |||
if (op->op.same_as(builtin::tvm_access_ptr())) { |
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.
Please add testcase for BlockReadWriteDetector
directly in tests/python/unittest/test_tir_analysis_get_block_access_region.py
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.
Should I keep the testcase in tests/python/unittest/test_tir_schedule_compute_inline.py?
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.
Of course, the more test cases the better
e92d012
to
3445935
Compare
with T.block("opaque"): | ||
T.reads(A[0:1024], C[0:1024]) | ||
T.writes(B[0:1024], C[0:1024]) | ||
T.evaluate(A.access_ptr("r")) |
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.
Would be great if we can test different start point and different extent
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.
Currently, we use FullRegion of the opaque access with tvm_access_ptr, so the offset and extent does not count. I try to use access_ptr's offset and extent as region, but access_ptr can only express the region as flattened which will be failed when the buffer dims > 1.
cc04d7b
to
756c16c
Compare
When the opaque access is wrapped with tvm_access_ptr, we can get the access_mask from tvm_access_ptr in BlockReadWriteDetector and put this opaque access to read_regions or write_regions according to access_mask.
756c16c
to
4e28131
Compare
* [TIR] Get read/write access precisely for opaque access. When the opaque access is wrapped with tvm_access_ptr, we can get the access_mask from tvm_access_ptr in BlockReadWriteDetector and put this opaque access to read_regions or write_regions according to access_mask. * [TIR] Add parameter extent for access_ptr. Co-authored-by: sqing <qing.siqi@intellif.com>
* [TIR] Get read/write access precisely for opaque access. When the opaque access is wrapped with tvm_access_ptr, we can get the access_mask from tvm_access_ptr in BlockReadWriteDetector and put this opaque access to read_regions or write_regions according to access_mask. * [TIR] Add parameter extent for access_ptr. Co-authored-by: sqing <qing.siqi@intellif.com>
Previously we assume opaque access as both read and write access in compute_inline. Here we present a way to tell the opaque access is whether a read or write access precisely. The opaque access is wrapped with tvm_access_ptr as following:
We can get the access_mask from tvm_access_ptr in BlockReadWriteDetector and put this opaque access to read_regions or write_regions according to access_mask.