-
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] Add line level debug info #13012
Conversation
43c6b08
to
a2fdb8f
Compare
9966735
to
dec0d8a
Compare
9c96a2d
to
d66fe0d
Compare
34e8283
to
d68def3
Compare
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
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 @driazati
@kparzysz-quic can you review the LLVM parts?
include/tvm/ir/expr.h
Outdated
@@ -526,6 +526,7 @@ class IntImm : public PrimExpr { | |||
TVM_DLL IntImm(DataType dtype, int64_t value, Span span = Span()); | |||
|
|||
TVM_DEFINE_OBJECT_REF_METHODS(IntImm, PrimExpr, IntImmNode); | |||
TVM_DEFINE_OBJECT_REF_COW_METHOD(IntImmNode); |
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.
just wondering why you needed this one?
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.
do you mean for TVM_DEFINE_OBJECT_REF_COW_METHOD
or for IntImmNode
in particular? the copy on write is used when creating new nodes so every supported op needs to have it defined, and IntImm
is one of the supported ops in install_debug_spans_ops.h
so it needs it as well
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.
Could you create a separate PR with the COW changes?
include/tvm/ir/expr.h
Outdated
@@ -526,6 +526,7 @@ class IntImm : public PrimExpr { | |||
TVM_DLL IntImm(DataType dtype, int64_t value, Span span = Span()); | |||
|
|||
TVM_DEFINE_OBJECT_REF_METHODS(IntImm, PrimExpr, IntImmNode); | |||
TVM_DEFINE_OBJECT_REF_COW_METHOD(IntImmNode); |
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.
Could you create a separate PR with the COW changes?
|
||
Pass InstallDebugSpans() { | ||
auto pass_func = [](PrimFunc f, IRModule m, PassContext ctx) { | ||
ICHECK(m->functions.size() == 1) |
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'm not sure if it's an error to run it on a module with multiple functions... If multiple functions aren't supported, then maybe just exit without doing anything?
Is this a temporary restriction?
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.
Yeah this is just there for the first pass. Seeing how this pass has to be explicitly enabled I think it makes more sense to keep it strict rather than permissive so errors are surfaced early
This enables copy on write methods for all nodes since some were missing it before (see apache#13012 for more context)
Given that we are moving more towards TVMScript, It would be good to think about how to make it compatible with TVMScript printing and debug info. cc @junrushao @yelite |
This enables copy on write methods for all nodes since some were missing it before (see #13012 for more context) Co-authored-by: driazati <driazati@users.noreply.github.com>
One shortcut this PR takes is to explicitly avoid TVM script (at least for source reporting) and use the TIR text printer so it can be run at any point in the compilation pipeline. I think the eventual plan would be to have true source line numbers from the actual written TVM script rather than the generated TIR |
The new TVMScript printer is able to print IR fragments (not constraining to print IRModule and PrimFunc only). And it's able to record span of an IR node based on printed result (https://github.com/apache/tvm/blob/main/src/script/printer/base_doc_printer.cc#L331, used for diagnostic marker printing) and distinguish the same node in different places (for example, the same VarNode can be found in different places of the IR graph). The implementation of TIR printing is finished. But we need to sort out the detail on how to track ObjectPath in a more ergonomic and readable way before finally upstreaming this part. The plan of migrating to TVMScript printer sounds good to me. If we are interested in tracing back to the TVMScript code of Var or Buffer, we need to be aware of that such nodes can appear multiple times in the graph (which means multiple spans in the TVMScript code), and the 1-1 mapping between node and span in TVM will cause some trouble. |
4a5c1a2
to
bf0e9d6
Compare
Can we merge this? @areusch @kparzysz-quic @tqchen |
@tvm-bot rerun |
* TIR debug info * Fix location emission * Comments 1/N (docs, cleanups) * Remove leaky macro usage * Add unit test * Remove dead code * Add accuracy test Co-authored-by: driazati <driazati@users.noreply.github.com>
This adds a pass
InstallDebugSpans
that uses the printout from the TIR text printer to override the source spans on statements and expressions in anIRModule
. The pass runs a new printer that records statements and their corresponding line number as they are printed. The LLVM CPU codegen then reads these spans to set the debug location onllvm::Instructions
as they are created in the builder.