-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[PROTON] Introduce the Proton dialect as a third-party plugin for intra-kernel perf tooling #5119
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d929350
added basic biolerplate code for proton dialect
e769709
integrate proton dialect in the build system
9bde345
fix pre-commit lint
5192af2
remove license and revise based on the feedbacks regarding the dialec…
b7b9319
drop the dependency of llvm dialect. Will revisit this when needed.
5cf2447
Merge branch 'main' into fywkevin/proton_dialect
Jokeren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // RUN: triton-opt --split-input-file %s -cse -canonicalize | FileCheck %s | ||
|
|
||
| module { | ||
| // CHECK-LABEL: proton_record | ||
| tt.func @proton_record() { | ||
| // CHECK: proton.record() {isStart = true, regionId = 1 : i32} | ||
| // CHECK-NEXT: proton.record() {isStart = false, regionId = 1 : i32} | ||
| // CHECK-NEXT: tt.return | ||
| proton.record() {isStart = true, regionId = 1 : i32} | ||
| proton.record() {isStart = false, regionId = 1 : i32} | ||
| tt.return | ||
| } | ||
| } // end module | ||
|
|
||
| // ----- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
| include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) | ||
| add_subdirectory(include) | ||
| add_subdirectory(lib) | ||
| if(TRITON_BUILD_PYTHON_MODULE) | ||
| add_triton_plugin(TritonProton ${CMAKE_CURRENT_SOURCE_DIR}/triton_proton.cc LINK_LIBS ProtonIR) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(Dialect) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(Proton) |
1 change: 1 addition & 0 deletions
1
third_party/proton/dialect/include/Dialect/Proton/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(IR) |
18 changes: 18 additions & 0 deletions
18
third_party/proton/dialect/include/Dialect/Proton/IR/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR}) | ||
|
|
||
| set(LLVM_TARGET_DEFINITIONS ProtonOps.td) | ||
| mlir_tablegen(Dialect.h.inc -gen-dialect-decls -dialect=proton) | ||
| mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs -dialect=proton) | ||
| mlir_tablegen(OpsConversions.inc -gen-llvmir-conversions) | ||
| mlir_tablegen(Ops.h.inc -gen-op-decls) | ||
| mlir_tablegen(Ops.cpp.inc -gen-op-defs) | ||
| mlir_tablegen(OpsEnums.h.inc -gen-enum-decls) | ||
| mlir_tablegen(OpsEnums.cpp.inc -gen-enum-defs) | ||
| add_mlir_doc(ProtonDialect ProtonDialect dialects/ -gen-dialect-doc) | ||
| add_mlir_doc(ProtonOps ProtonOps dialects/ -gen-op-doc) | ||
| add_public_tablegen_target(ProtonTableGen) | ||
|
|
||
| set(LLVM_TARGET_DEFINITIONS ProtonAttrDefs.td) | ||
| mlir_tablegen(ProtonAttrDefs.h.inc -gen-attrdef-decls) | ||
| mlir_tablegen(ProtonAttrDefs.cpp.inc -gen-attrdef-defs) | ||
| add_public_tablegen_target(ProtonAttrDefsIncGen) |
23 changes: 23 additions & 0 deletions
23
third_party/proton/dialect/include/Dialect/Proton/IR/Dialect.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #ifndef TRITON_DIALECT_PROTON_IR_DIALECT_H_ | ||
| #define TRITON_DIALECT_PROTON_IR_DIALECT_H_ | ||
|
|
||
| #include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
| #include "mlir/IR/BuiltinOps.h" | ||
| #include "mlir/IR/Dialect.h" | ||
| #include "mlir/IR/PatternMatch.h" | ||
| #include "proton/dialect/include/Dialect/Proton/IR/Dialect.h.inc" | ||
| #include "proton/dialect/include/Dialect/Proton/IR/OpsEnums.h.inc" | ||
|
|
||
| #define GET_ATTRDEF_CLASSES | ||
| #include "proton/dialect/include/Dialect/Proton/IR/ProtonAttrDefs.h.inc" | ||
|
|
||
| #define GET_OP_CLASSES | ||
| #include "proton/dialect/include/Dialect/Proton/IR/Ops.h.inc" | ||
|
|
||
| namespace mlir { | ||
| namespace triton { | ||
| namespace proton {} // namespace proton | ||
| } // namespace triton | ||
| } // namespace mlir | ||
|
|
||
| #endif // TRITON_DIALECT_PROTON_IR_DIALECT_H_ |
12 changes: 12 additions & 0 deletions
12
third_party/proton/dialect/include/Dialect/Proton/IR/ProtonAttrDefs.td
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef PROTON_ATTRDEFS | ||
| #define PROTON_ATTRDEFS | ||
|
|
||
| include "mlir/IR/AttrTypeBase.td" | ||
| include "ProtonDialect.td" | ||
|
|
||
| class Proton_Attr<string name, list<Trait> traits = [], | ||
| string baseCppClass = "::mlir::Attribute"> | ||
| : AttrDef<Proton_Dialect, name, traits, baseCppClass> { | ||
| } | ||
|
|
||
| #endif // PROTON_ATTRDEFS |
18 changes: 18 additions & 0 deletions
18
third_party/proton/dialect/include/Dialect/Proton/IR/ProtonDialect.td
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #ifndef PROTON_DIALECT | ||
| #define PROTON_DIALECT | ||
|
|
||
| include "mlir/IR/OpBase.td" | ||
|
|
||
| def Proton_Dialect : Dialect { | ||
| let name = "proton"; | ||
| let cppNamespace = "::mlir::triton::proton"; | ||
|
|
||
| let description = [{ | ||
| Proton Dialect provides core ops for building third-party compiler-based | ||
| performance profiling and analysis tools. | ||
| }]; | ||
|
|
||
| let dependentDialects = []; | ||
| } | ||
|
|
||
| #endif |
65 changes: 65 additions & 0 deletions
65
third_party/proton/dialect/include/Dialect/Proton/IR/ProtonOps.td
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #ifndef PROTON_OPS | ||
| #define PROTON_OPS | ||
|
|
||
| include "mlir/IR/OpBase.td" | ||
| include "mlir/IR/EnumAttr.td" | ||
| include "triton/Dialect/Triton/IR/TritonTypes.td" | ||
| include "mlir/Dialect/LLVMIR/LLVMOpBase.td" | ||
| include "mlir/Interfaces/InferTypeOpInterface.td" | ||
| include "mlir/Interfaces/SideEffectInterfaces.td" | ||
| include "triton/Dialect/Triton/IR/TritonInterfaces.td" | ||
| include "ProtonDialect.td" | ||
| include "ProtonAttrDefs.td" | ||
|
|
||
| class TT_Proton_Op<string mnemonic, list<Trait> traits = []> : | ||
| Op<Proton_Dialect, mnemonic, !listconcat(traits, [])> { | ||
| } | ||
|
|
||
| // Proton profiling metric. | ||
| def MetricAttr : I32EnumAttr< | ||
| "Metric", "", | ||
| [ | ||
| I32EnumAttrCase<"CYCLE", 0, "cycle">, | ||
| ]> { | ||
| let cppNamespace = "::mlir::triton::proton"; | ||
| } | ||
|
|
||
| // Proton profiling granularity. | ||
| def GranularityAttr : I32EnumAttr< | ||
| "Granularity", "", | ||
| [ | ||
| I32EnumAttrCase<"WARPGROUP", 0, "warpgroup">, | ||
| I32EnumAttrCase<"WARP", 1, "warp">, | ||
| ]> { | ||
| let cppNamespace = "::mlir::triton::proton"; | ||
| } | ||
|
|
||
| def TT_RecordOp : TT_Proton_Op<"record", [DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> { | ||
| let summary = "Record a GPU hardware event"; | ||
|
|
||
| let description = [{ | ||
| The operator records GPU events from performance counters. | ||
| Currently only cycle counter is supported. | ||
|
|
||
| Example: | ||
|
|
||
| ```mlir | ||
| proton.record() {isStart = true, regionId = 4 : i32} | ||
| ... | ||
| proton.record() {isStart = false, regionId = 4 : i32} | ||
| ... | ||
| proton.record() {isStart = true, regionId = 1 : i32, granularity = 1 : i32} | ||
| ... | ||
| proton.record() {isStart = false, regionId = 1 : i32, granularity = 1 : i32} | ||
| ``` | ||
| }]; | ||
| let arguments = ( | ||
| ins BoolAttr: $isStart, | ||
| ConfinedAttr<I32Attr, [IntNonNegative]>:$regionId, | ||
| DefaultValuedAttr<MetricAttr, "Metric::CYCLE">:$metric, | ||
| DefaultValuedAttr<GranularityAttr, "Granularity::WARPGROUP">:$granularity | ||
| ); | ||
| let assemblyFormat = " `(` operands `)` attr-dict"; | ||
| } | ||
|
|
||
| #endif // PROTON_OPS | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(Dialect) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(Proton) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(IR) |
13 changes: 13 additions & 0 deletions
13
third_party/proton/dialect/lib/Dialect/Proton/IR/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| add_triton_library(ProtonIR | ||
| Dialect.cpp | ||
| Ops.cpp | ||
|
|
||
| DEPENDS | ||
| ProtonTableGen | ||
| ProtonAttrDefsIncGen | ||
|
|
||
| LINK_LIBS PUBLIC | ||
| MLIRLLVMDialect | ||
| TritonIR | ||
| TritonGPUIR | ||
| ) |
25 changes: 25 additions & 0 deletions
25
third_party/proton/dialect/lib/Dialect/Proton/IR/Dialect.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #include "mlir/IR/DialectImplementation.h" | ||
| #include "mlir/IR/OpImplementation.h" | ||
|
|
||
| // clang-format off | ||
| #include "Dialect/Proton/IR/Dialect.h" | ||
| #include "Dialect/Proton/IR/Dialect.cpp.inc" | ||
| // clang-format on | ||
|
|
||
| using namespace mlir; | ||
| using namespace mlir::triton::proton; | ||
|
|
||
| void mlir::triton::proton::ProtonDialect::initialize() { | ||
| addAttributes< | ||
| #define GET_ATTRDEF_LIST | ||
| #include "Dialect/Proton/IR/ProtonAttrDefs.cpp.inc" | ||
| >(); | ||
|
|
||
| addOperations< | ||
| #define GET_OP_LIST | ||
| #include "Dialect/Proton/IR/Ops.cpp.inc" | ||
| >(); | ||
| } | ||
|
|
||
| #define GET_ATTRDEF_CLASSES | ||
| #include "Dialect/Proton/IR/ProtonAttrDefs.cpp.inc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #include "Dialect/Proton/IR/Dialect.h" | ||
| #include "mlir/IR/Builders.h" | ||
| #include "mlir/IR/BuiltinAttributes.h" | ||
| #include "mlir/IR/BuiltinTypes.h" | ||
| #include "mlir/IR/OperationSupport.h" | ||
| #include "mlir/Interfaces/FunctionImplementation.h" | ||
| #include "mlir/Interfaces/FunctionInterfaces.h" | ||
| #include "mlir/Support/LLVM.h" | ||
| #include "triton/Dialect/Triton/IR/Dialect.h" | ||
| #include "triton/Dialect/Triton/IR/Types.h" | ||
| #include "triton/Dialect/Triton/IR/Utility.h" | ||
|
|
||
| #define GET_OP_CLASSES | ||
| #include "Dialect/Proton/IR/Ops.cpp.inc" | ||
| #include "Dialect/Proton/IR/OpsEnums.cpp.inc" | ||
|
|
||
| namespace mlir { | ||
| namespace triton { | ||
| namespace proton { | ||
|
|
||
| // -- RecordOp -- | ||
| void RecordOp::getEffects( | ||
| SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>> | ||
| &effects) { | ||
| effects.emplace_back(MemoryEffects::Write::get(), | ||
| SideEffects::DefaultResource::get()); | ||
| effects.emplace_back(MemoryEffects::Read::get(), | ||
| SideEffects::DefaultResource::get()); | ||
| } | ||
|
|
||
| } // namespace proton | ||
| } // namespace triton | ||
| } // namespace mlir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #include "Dialect/Proton/IR/Dialect.h" | ||
| #include "mlir/Pass/PassManager.h" | ||
| #include "passes.h" | ||
| #include <pybind11/pybind11.h> | ||
| #include <pybind11/stl.h> | ||
| #include <pybind11/stl_bind.h> | ||
|
|
||
| namespace py = pybind11; | ||
|
|
||
| void init_triton_proton(py::module &&m) { | ||
Jokeren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| auto passes = m.def_submodule("passes"); | ||
|
|
||
| // load dialects | ||
| m.def("load_dialects", [](mlir::MLIRContext &context) { | ||
| mlir::DialectRegistry registry; | ||
| registry.insert<mlir::triton::proton::ProtonDialect>(); | ||
| context.appendDialectRegistry(registry); | ||
| context.loadAllAvailableDialects(); | ||
| }); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 region id be a dynamic value in the future?
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.
For the dynamic value thing, I thought about it and I think should have an "version" as an argument, like
record(version:i32){...attr...}. This would be useful for loop iterations that we have multiple instances of therecordOPand we can distinguish them. To make the region_id dynamic, do you have any use cases?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 don't, just curious
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 inclined to add them (including the "version" arg) when we actually try to build the support around it, and keep it simple for now. What do you think?