-
Notifications
You must be signed in to change notification settings - Fork 18
iluvatar c++ decouple #105
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
Draft
toudefu
wants to merge
14
commits into
iluvatar_python_decoupling_20250801
Choose a base branch
from
iluvatar_c++_decouple
base: iluvatar_python_decoupling_20250801
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e3db017
iluvatar c++ decouple
toudefu dc70c1d
[Decoupling] decouple iluvatar C++
zhzhcookie 44c9b73
[Decoupling] decouple iluvatar C++
zhzhcookie ea0ea17
[Decoupling] decouple iluvatar C++
zhzhcookie 904d453
[Decoupling] decouple iluvatar C++
zhzhcookie 0359ed0
c++ decoupling
toudefu 8b6a9d2
Axisinfo decoupling
toudefu c031abd
membar decoupling
toudefu e063f17
utility decoupling
toudefu 05efddd
utility multiRootGetSlice decoupling
toudefu 913a93b
fix: head name
toudefu 7ea98fc
conversion tritonGPUToLLVM elementwiseOpToLLVMBase decoupling
toudefu ffc374c
conversion tritonGPUToLLVM TargetInfoBase decoupling
toudefu 7e0dae7
fix: head flagtree_spec.h
toudefu 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
3 changes: 3 additions & 0 deletions
3
third_party/iluvatar/backend/flagtree_backend_specialization/include/flagtree_spec.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,3 @@ | ||
| #include "triton/Analysis/iluvatar_AxisInfo.h" | ||
| #include "triton/Analysis/iluvatar_Membar.h" | ||
| #include "triton/Analysis/iluvatar_Utility.h" |
7 changes: 7 additions & 0 deletions
7
...vatar/backend/flagtree_backend_specialization/include/triton/Analysis/iluvatar_AxisInfo.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,7 @@ | ||
| #ifndef ILUVATAR_TRITON_ANALYSIS_AXISINFO_H | ||
| #define ILUVATAR_TRITON_ANALYSIS_AXISINFO_H | ||
|
|
||
| #define FLAGTREE_SPEC_AxisInfo_CorexFlag | ||
| #define FLAGTREE_SPEC_AxisInfo_initPessimisticStateFromFunc_ARG AxisInfo::DimVectorT * | ||
|
|
||
| #endif |
6 changes: 6 additions & 0 deletions
6
...luvatar/backend/flagtree_backend_specialization/include/triton/Analysis/iluvatar_Membar.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,6 @@ | ||
| #ifndef ILUVATAR_TRITON_ANALYSIS_MEMBAR_H | ||
| #define ILUVATAR_TRITON_ANALYSIS_MEMBAR_H | ||
|
|
||
| #define FLAGTREE_SPEC_BlockInfo_Function | ||
|
|
||
| #endif // ILUVATAR_TRITON_ANALYSIS_MEMBAR_H |
7 changes: 7 additions & 0 deletions
7
...uvatar/backend/flagtree_backend_specialization/include/triton/Analysis/iluvatar_Utility.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,7 @@ | ||
| #ifndef ILUVATAR_TRITON_ANALYSIS_UTILITY_H | ||
| #define ILUVATAR_TRITON_ANALYSIS_UTILITY_H | ||
|
|
||
| #define FLAGTREE_SPEC_Utility_Function | ||
| #define FLAGTREE_SPEC_Utility_multiRootGetSlice_ARG bool | ||
|
|
||
| #endif // TRITON_ANALYSIS_UTILITY_H | ||
43 changes: 43 additions & 0 deletions
43
third_party/iluvatar/backend/flagtree_backend_specialization/lib/Analysis/AxisInfo.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,43 @@ | ||
| #include "triton/Analysis/AxisInfo.h" | ||
|
|
||
| #include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
|
|
||
| namespace mlir::triton { | ||
|
|
||
| template <class T> | ||
| void AxisInfo::initPessimisticStateFromFunc(int argNumber, T funcOp, | ||
| DimVectorT *contiguity, | ||
| DimVectorT *divisibility, | ||
| DimVectorT *constancy, | ||
| DimVectorT *corexFlag) { | ||
| // liast of attributes that we care about | ||
| SmallVector<std::pair<DimVectorT *, std::string>> retVecs; | ||
| retVecs.push_back({contiguity, "tt.contiguity"}); | ||
| retVecs.push_back({divisibility, "tt.divisibility"}); | ||
| retVecs.push_back({constancy, "tt.constancy"}); | ||
| retVecs.push_back({corexFlag, "tt.corex_stride"}); | ||
|
|
||
| // initialize attributes one by one | ||
| for (auto [vec, attrName] : retVecs) { | ||
| Attribute attr = funcOp.getArgAttr(argNumber, attrName); | ||
| if (auto int_attr = dyn_cast_or_null<IntegerAttr>(attr)) | ||
| *vec = DimVectorT(contiguity->size(), int_attr.getValue().getZExtValue()); | ||
| if (auto dense_attr = dyn_cast_or_null<DenseElementsAttr>(attr)) { | ||
| auto vals = dense_attr.getValues<int>(); | ||
| *vec = DimVectorT(vals.begin(), vals.end()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| template void AxisInfo::initPessimisticStateFromFunc<mlir::FunctionOpInterface>( | ||
| int argNumber, mlir::FunctionOpInterface funcOp, AxisInfo::DimVectorT *contiguity, | ||
| AxisInfo::DimVectorT *divisibility, AxisInfo::DimVectorT *constancy, | ||
| FLAGTREE_SPEC_AxisInfo_initPessimisticStateFromFunc_ARG spec_arg); | ||
|
|
||
| template void AxisInfo::initPessimisticStateFromFunc<mlir::LLVM::LLVMFuncOp>( | ||
| int argNumber, mlir::LLVM::LLVMFuncOp funcOp, AxisInfo::DimVectorT *contiguity, | ||
| AxisInfo::DimVectorT *divisibility, AxisInfo::DimVectorT *constancy, | ||
| FLAGTREE_SPEC_AxisInfo_initPessimisticStateFromFunc_ARG spec_arg); | ||
|
|
||
| } | ||
|
|
9 changes: 9 additions & 0 deletions
9
third_party/iluvatar/backend/flagtree_backend_specialization/lib/Analysis/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,9 @@ | ||
| add_triton_library(FlagTree_iluvatar_TritonAnalysis | ||
| AxisInfo.cpp | ||
| Membar.cpp | ||
| Utility.cpp | ||
|
|
||
| DEPENDS | ||
| TritonTableGen | ||
| TritonGPUAttrDefsIncGen | ||
| ) |
35 changes: 35 additions & 0 deletions
35
third_party/iluvatar/backend/flagtree_backend_specialization/lib/Analysis/Membar.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,35 @@ | ||
| #include "triton/Analysis/Membar.h" | ||
|
|
||
| namespace mlir { | ||
|
|
||
| // type: 0 all | 1 del W from other R |2 del R from other W | ||
| void BlockInfo::erase(BlockInfo &other, int type) { | ||
| if (type == 0) { | ||
| for (auto &sri : other.syncReadIntervals) | ||
| syncReadIntervals.erase(sri); | ||
| for (auto &swi : other.syncWriteIntervals) | ||
| syncWriteIntervals.erase(swi); | ||
| } else if (type == 1) { | ||
| for (auto &sri : other.syncReadIntervals) | ||
| syncWriteIntervals.erase(sri); | ||
| } else if (type == 2) { | ||
| for (auto &swi : other.syncWriteIntervals) | ||
| syncReadIntervals.erase(swi); | ||
| } | ||
| } | ||
|
|
||
| // for debug | ||
| void BlockInfo::printIntervals() { | ||
| if (syncReadIntervals.size() > 0 || syncWriteIntervals.size() > 0) { | ||
| std::cout << " syncReadIntervals"; | ||
| for (auto &lhs : syncReadIntervals) | ||
| std::cout << " [" << lhs.start() << ", " << lhs.end() << "] "; | ||
| std::cout << "" << std::endl; | ||
| std::cout << " syncWriteIntervals"; | ||
| for (auto &lhs : syncWriteIntervals) | ||
| std::cout << " [" << lhs.start() << ", " << lhs.end() << "] "; | ||
| std::cout << "" << std::endl; | ||
| } | ||
| } | ||
|
|
||
| } |
108 changes: 108 additions & 0 deletions
108
third_party/iluvatar/backend/flagtree_backend_specialization/lib/Analysis/Utility.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,108 @@ | ||
| #include "triton/Analysis/Utility.h" | ||
|
|
||
| namespace mlir { | ||
|
|
||
| bool isMmaToDotSlowShortcut(RankedTensorType &srcTy, RankedTensorType &dstTy) { | ||
|
|
||
| auto srcLayout = srcTy.getEncoding(); | ||
| auto dstLayout = dstTy.getEncoding(); | ||
| if (!srcLayout.isa<triton::gpu::IluvatarMmaEncodingAttr>()) | ||
| return false; | ||
| auto mmaLayout = srcLayout.cast<triton::gpu::IluvatarMmaEncodingAttr>(); | ||
| if (!dstLayout.isa<triton::gpu::DotOperandEncodingAttr>()) | ||
| return false; | ||
| auto dotOperandLayout = dstLayout.cast<triton::gpu::DotOperandEncodingAttr>(); | ||
| auto dstParLayout = dotOperandLayout.getParent(); | ||
| if (!dstParLayout.isa<triton::gpu::IluvatarMmaEncodingAttr>()) | ||
| return false; | ||
| auto dstMmaLayout = | ||
| dstParLayout.dyn_cast<triton::gpu::IluvatarMmaEncodingAttr>(); | ||
| return !isMmaToDotShortcut(srcTy, dstTy) && | ||
| mmaLayout.getVersionMajor() == 1 && | ||
| dstMmaLayout.getVersionMajor() == 1 && | ||
| mmaLayout.getWarpsPerCTA()[0] == dstMmaLayout.getWarpsPerCTA()[0] && | ||
| dotOperandLayout.getOpIdx() == 0 && !srcTy.getElementType().isF32(); | ||
| } | ||
|
|
||
| void getBackwardSliceImplCorex(Operation *op, | ||
| SetVector<Operation *> *backwardSlice, | ||
| TransitiveFilter filter, | ||
| bool omitBlockArguments) { | ||
| if (!op || op->hasTrait<OpTrait::IsIsolatedFromAbove>()) | ||
| return; | ||
|
|
||
| // Evaluate whether we should keep this def. | ||
| // This is useful in particular to implement scoping; i.e. return the | ||
| // transitive backwardSlice in the current scope. | ||
| if (filter && !filter(op)) | ||
| return; | ||
|
|
||
| for (const auto &en : llvm::enumerate(op->getOperands())) { | ||
| auto operand = en.value(); | ||
| if (auto *definingOp = operand.getDefiningOp()) { | ||
| if (backwardSlice->count(definingOp) == 0) | ||
| getBackwardSliceImplCorex(definingOp, backwardSlice, filter, | ||
| omitBlockArguments); | ||
| } else if (auto blockArg = operand.dyn_cast<BlockArgument>()) { | ||
| if (omitBlockArguments) | ||
| continue; | ||
|
|
||
| Block *block = blockArg.getOwner(); | ||
| Operation *parentOp = block->getParentOp(); | ||
| // TODO: determine whether we want to recurse backward into the other | ||
| // blocks of parentOp, which are not technically backward unless they flow | ||
| // into us. For now, just bail. | ||
| if (parentOp && backwardSlice->count(parentOp) == 0) { | ||
| // assert(parentOp->getNumRegions() == 1 && | ||
| // parentOp->getRegion(0).getBlocks().size() == 1); | ||
| getBackwardSliceImplCorex(parentOp, backwardSlice, filter, | ||
| omitBlockArguments); | ||
| } | ||
| } else { | ||
| llvm_unreachable("No definingOp and not a block argument."); | ||
| } | ||
| } | ||
|
|
||
| backwardSlice->insert(op); | ||
| } | ||
|
|
||
| void getBackwardSliceCorex(Operation *op, SetVector<Operation *> *backwardSlice, | ||
| TransitiveFilter filter, bool omitBlockArguments) { | ||
| getBackwardSliceImplCorex(op, backwardSlice, filter, omitBlockArguments); | ||
|
|
||
| // Don't insert the top level operation, we just queried on it and don't | ||
| // want it in the results. | ||
| backwardSlice->remove(op); | ||
| } | ||
|
|
||
| SetVector<Operation *> multiRootGetSlice(Operation *op, | ||
| TransitiveFilter backwardFilter, | ||
| TransitiveFilter forwardFilter, | ||
| bool omitBlockArguments) { | ||
| SetVector<Operation *> slice; | ||
| slice.insert(op); | ||
|
|
||
| unsigned currentIndex = 0; | ||
| SetVector<Operation *> backwardSlice; | ||
| SetVector<Operation *> forwardSlice; | ||
| while (currentIndex != slice.size()) { | ||
| auto *currentOp = (slice)[currentIndex]; | ||
| // Compute and insert the backwardSlice starting from currentOp. | ||
| backwardSlice.clear(); | ||
| BackwardSliceOptions opt; | ||
| opt.omitBlockArguments = true; | ||
| opt.filter = backwardFilter; | ||
| getBackwardSliceCorex(currentOp, &backwardSlice, opt.filter, | ||
| opt.omitBlockArguments); | ||
| slice.insert(backwardSlice.begin(), backwardSlice.end()); | ||
|
|
||
| // Compute and insert the forwardSlice starting from currentOp. | ||
| forwardSlice.clear(); | ||
| getForwardSlice(currentOp, &forwardSlice, forwardFilter); | ||
| slice.insert(forwardSlice.begin(), forwardSlice.end()); | ||
| ++currentIndex; | ||
| } | ||
| return multiRootTopologicalSort(slice); | ||
| } | ||
|
|
||
| } |
1 change: 1 addition & 0 deletions
1
third_party/iluvatar/backend/flagtree_backend_specialization/lib/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(Analysis) |
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 |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| add_subdirectory(triton) | ||
|
|
||
| set(ILUVATAR_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../backend/flagtree_backend_specialization/include/triton") | ||
| include_directories("${ILUVATAR_INCLUDE_DIR}") |
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
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.
// ILUVATAR_TRITON_ANALYSIS_UTILITY_H
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