[WIP][Performance Remarks] Support MLIR_ENABLE_REMARK for command line tools#5250
[WIP][Performance Remarks] Support MLIR_ENABLE_REMARK for command line tools#5250sfzhu93 wants to merge 1 commit intotriton-lang:mainfrom
MLIR_ENABLE_REMARK for command line tools#5250Conversation
ThomasRaoux
left a comment
There was a problem hiding this comment.
I wonder why we can't handle this by setting the right checks in SourceMgrErrorDiagnosticHandler maybe @Mogball has an idea.
| class DiagnosticEmitter { | ||
| // singleton pattern | ||
| private: | ||
| inline static DiagnosticEmitter *instance{nullptr}; | ||
| bool shouldEmitPerfWarning; | ||
| DiagnosticEmitter() : shouldEmitPerfWarning(false){}; | ||
| ~DiagnosticEmitter() = default; | ||
|
|
||
| public: | ||
| DiagnosticEmitter(const DiagnosticEmitter &) = delete; | ||
| DiagnosticEmitter &operator=(const DiagnosticEmitter &) = delete; | ||
|
|
||
| static DiagnosticEmitter *getInstance() { | ||
| if (!instance) { | ||
| instance = new DiagnosticEmitter(); | ||
| if (tools::getBoolEnv("MLIR_ENABLE_REMARK")) { | ||
| instance->shouldEmitPerfWarning = true; | ||
| } | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| static void setShouldEmitPerfWarning(bool shouldEmit) { | ||
| DiagnosticEmitter::getInstance()->shouldEmitPerfWarning = shouldEmit; | ||
| } | ||
|
|
||
| static std::optional<InFlightDiagnostic> | ||
| getPerfWarningStream(const OpState &op) { | ||
| if (DiagnosticEmitter::getInstance()->shouldEmitPerfWarning) { | ||
| return op->emitRemark(); | ||
| } else { | ||
| return std::nullopt; | ||
| } | ||
| } |
There was a problem hiding this comment.
This is not going to be thread safe. We should stay away from globals or singleton
| #define EMIT_PERF_WARNING(op, message) \ | ||
| if (auto out = mlir::triton::DiagnosticEmitter::getPerfWarningStream(op)) { \ | ||
| *out << message; \ | ||
| } |
There was a problem hiding this comment.
why does it need to be a macro?
There was a problem hiding this comment.
was trying to make an API supporting emitPerfWarn(op) << "foo" << "bar" but find it difficult to make it print nothing when the switch is off. Making an empty InFlightDiagnostic triggers an assertion in MLIR when it attempts to attach notes.
We did so in the I can move on customizing the main function for |
|
If this is just meant for CLI tools driven by IMO a macro is quite awkward and it's easy to forget to use the macro instead of the normal MLIR API. Forking MlirOptMain.cpp is also an option -- most of the code in there probably isn't useful for Triton. |
|
@Mogball Thanks for the suggestion! I'll look into making an update to MLIR upstream to address this.
Could you elaborate on what you mean by forking |
Yeah, a partial copy. If you have an upstream PR, please share the link here and I'll TAL |
|
llvm/llvm-project#117669 @Mogball |
This PR adds a command line argument `--mlir-disable-diagnostic` for disabling diagnostic information for mlir-opt. When debugging with mlir-opt, some developers would like to disable the diagnostic information and focus specifically on the dumped IR. For example, triton-lang/triton#5250
|
Closing this PR, as llvm/llvm-project#117669 is merging. After that, we should be able to update the upstream LLVM commit hash to address the problem. |
This PR enhances Triton's command-line tools, such as
triton-opt, by adding support for theMLIR_ENABLE_REMARKoption. It introduces a singleton class to manage the emission of performance warnings, leveraging the MLIR infrastructure for diagnostic information (e.g.,op->emitWarning()andop->emitRemark()). This approach replaces the previous approach in #3922 and #4350 by using a macro based on the new wrapper class instead of directly emitting remarks.Initially, we considered introducing a switch to disable
emitRemarkin MLIR. However, similar implementations, like the-Rpassand-Wswitches in Clang, directly control information from specific passes. Therefore, we opted to create a wrapper class for the MLIR APIs rather than modifying upstream MLIR to support disabling certain diagnostic information.This PR is still ongoing. 1. We may need to update related Python code to utilize this new wrapper class. This work is still in progress. 2. Also, unit test is necessary to check if warnings are really disabled.
New contributor declaration
I am not making a trivial change, such as fixing a typo in a comment.
I have written a PR description following these
rules.
I have run
pre-commit run --from-ref origin/main --to-ref HEAD.Select one of the following.
/testforlittests/unittestfor C++ tests/python/testfor end-to-end testsFILL THIS IN.Select one of the following.
littests.littests I have added follow these best practices,including the "tests should be minimal" section. (Usually running Python code
and using the instructions it generates is not minimal.)