-
Notifications
You must be signed in to change notification settings - Fork 28
[FEAT-DSL] Update FlyToROCDL Conversion to support full dsl types #273
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
8 commits
Select commit
Hold shift + click to select a range
6838cbf
Add BufferFatPtr class and update rocdl conversion
sjfeng1999 927bd8c
Add DecompositionOp and support swizzle as the mapping of crd2idx
sjfeng1999 8d6ee97
minor fix
sjfeng1999 58eafcb
remove redundant getResult()
sjfeng1999 fb9de4c
fix MFMA 32x32 layoutC
sjfeng1999 1ac9971
add missing get_dyn_shared
sjfeng1999 a226da8
fix gemm and moe run
coderfeli 74aa17a
Merge branch 'main' into pr/yodate-to-rocdl-conversion
coderfeli 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,98 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright (c) 2025 FlyDSL Project Contributors | ||
|
|
||
| #ifndef FLYDSL_LIB_CONVERSION_FLYTOROCDL_BUFFERFATPTR_H | ||
| #define FLYDSL_LIB_CONVERSION_FLYTOROCDL_BUFFERFATPTR_H | ||
|
|
||
| #include "mlir/Dialect/Arith/IR/Arith.h" | ||
| #include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
| #include "mlir/IR/Builders.h" | ||
| #include "mlir/IR/BuiltinTypes.h" | ||
|
|
||
| #include "flydsl/Dialect/Fly/IR/FlyDialect.h" | ||
|
|
||
| namespace mlir::fly { | ||
|
|
||
| class BufferFatPtr { | ||
| static constexpr unsigned kRsrcAddrSpace = 8; // BufferDesc | ||
| static constexpr unsigned kOffsetBitWidth = 32; // constrained by BufferCopy instruction | ||
|
|
||
| fly::PointerType ptrTy; | ||
| Value fatPtr; | ||
|
|
||
| public: | ||
| BufferFatPtr(fly::PointerType ptrTy, Value v) : ptrTy(ptrTy), fatPtr(v) { | ||
| assert(ptrTy.getAddressSpace().getValue() == AddressSpace::BufferDesc); | ||
| } | ||
|
|
||
| static LLVM::LLVMStructType getType(MLIRContext *ctx) { | ||
| return LLVM::LLVMStructType::getLiteral(ctx, {LLVM::LLVMPointerType::get(ctx, kRsrcAddrSpace), | ||
| IntegerType::get(ctx, kOffsetBitWidth)}); | ||
| } | ||
| static Value pack(OpBuilder &b, Location loc, Value bufferRsrc, Value valOffset = nullptr) { | ||
| auto structTy = getType(b.getContext()); | ||
| Value undef = LLVM::UndefOp::create(b, loc, structTy); | ||
| if (!valOffset) { | ||
| valOffset = arith::ConstantIntOp::create(b, loc, 0, kOffsetBitWidth); | ||
| } | ||
| Value withRsrc = LLVM::InsertValueOp::create(b, loc, undef, bufferRsrc, ArrayRef<int64_t>{0}); | ||
| return LLVM::InsertValueOp::create(b, loc, withRsrc, valOffset, ArrayRef<int64_t>{1}); | ||
sjfeng1999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| Value bufferRsrc(OpBuilder &b, Location loc) const { | ||
| return LLVM::ExtractValueOp::create(b, loc, fatPtr, ArrayRef<int64_t>{0}); | ||
| } | ||
|
|
||
| Value valOffset(OpBuilder &b, Location loc) const { | ||
| return LLVM::ExtractValueOp::create(b, loc, fatPtr, ArrayRef<int64_t>{1}); | ||
| } | ||
|
|
||
| Value byteOffset(OpBuilder &b, Location loc) const { | ||
| int64_t bits = ptrTy.getElemTy().getIntOrFloatBitWidth(); | ||
| Value off = valOffset(b, loc); | ||
| if (bits == 8) | ||
| return off; | ||
| if (bits > 8 && bits % 8 == 0) { | ||
| int64_t elemBytes = bits / 8; | ||
| Value scale = arith::ConstantIntOp::create(b, loc, elemBytes, kOffsetBitWidth); | ||
| return arith::MulIOp::create(b, loc, off, scale); | ||
| } | ||
| Value scale = arith::ConstantIntOp::create(b, loc, bits, kOffsetBitWidth); | ||
| off = arith::MulIOp::create(b, loc, off, scale); | ||
| Value const8 = arith::ConstantIntOp::create(b, loc, 8, kOffsetBitWidth); | ||
| return arith::DivUIOp::create(b, loc, off, const8); | ||
sjfeng1999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| Value swizzleByteOffset(OpBuilder &b, Location loc) const { | ||
| Value off = byteOffset(b, loc); | ||
| SwizzleAttr swizzle = ptrTy.getSwizzle(); | ||
| if (swizzle.isTrivialSwizzle()) | ||
| return off; | ||
| auto offsetTy = IntegerType::get(b.getContext(), kOffsetBitWidth); | ||
| int64_t bitMaskValue = ((int64_t{1} << swizzle.getMask()) - 1) | ||
| << (swizzle.getBase() + swizzle.getShift()); | ||
| Value bitMask = arith::ConstantIntOp::create(b, loc, offsetTy, bitMaskValue); | ||
| Value shiftAmt = arith::ConstantIntOp::create(b, loc, offsetTy, swizzle.getShift()); | ||
| Value masked = arith::AndIOp::create(b, loc, off, bitMask); | ||
| Value shifted = arith::ShRUIOp::create(b, loc, masked, shiftAmt); | ||
| return arith::XOrIOp::create(b, loc, off, shifted); | ||
sjfeng1999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| Value addOffset(OpBuilder &b, Location loc, Value delta) const { | ||
| Type offTy = IntegerType::get(b.getContext(), kOffsetBitWidth); | ||
| if (delta.getType() != offTy) { | ||
| if (delta.getType().isIndex()) | ||
| delta = arith::IndexCastOp::create(b, loc, offTy, delta); | ||
| else if (delta.getType().getIntOrFloatBitWidth() < kOffsetBitWidth) | ||
| delta = arith::ExtSIOp::create(b, loc, offTy, delta); | ||
| else | ||
| delta = arith::TruncIOp::create(b, loc, offTy, delta); | ||
| } | ||
| Value newOff = arith::AddIOp::create(b, loc, valOffset(b, loc), delta); | ||
| return pack(b, loc, bufferRsrc(b, loc), newOff); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace mlir::fly | ||
|
|
||
| #endif // FLYDSL_LIB_CONVERSION_FLYTOROCDL_BUFFERFATPTR_H | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.