Skip to content

[MLIR][XeGPU] XeGPU ops distribution demo #111989

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mlir/include/mlir/Dialect/XeGPU/IR/XeGPUOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ def XeGPU_PrefetchNdOp : XeGPU_Op<"prefetch_nd", []> {
}


def XeGPU_LoadNdOp : XeGPU_Op<"load_nd", [AllElementTypesMatch<["value", "TensorDesc"]>]> {
def XeGPU_LoadNdOp : XeGPU_Op<"load_nd", [AllElementTypesMatch<["value", "TensorDesc"]>,
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
let summary = "loads a n-D block from memory (represented by TensorDesc)"
"to registers (represented by vector)";
let description = [{
Expand Down Expand Up @@ -322,7 +323,7 @@ def XeGPU_LoadNdOp : XeGPU_Op<"load_nd", [AllElementTypesMatch<["value", "Tensor
let hasVerifier = 1;
}

def XeGPU_StoreNdOp : XeGPU_Op<"store_nd", [AllShapesMatch<["value", "TensorDesc"]>,
def XeGPU_StoreNdOp : XeGPU_Op<"store_nd", [
AllElementTypesMatch<["value", "TensorDesc"]>]> {
let summary = "stores a n-D block register region back to memory, currently only supports 2D";

Expand Down
12 changes: 12 additions & 0 deletions mlir/include/mlir/Dialect/XeGPU/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ def XeGPUFoldAliasOps : Pass<"xegpu-fold-alias-ops"> {
];
}

def XeGPUDistributeToWI : Pass<"xegpu-distribute-to-wi", "gpu::GPUModuleOp"> {
let summary = "Distribute SIMD vector ops to SIMT work items";
let dependentDialects = [
"gpu::GPUDialect",
"xegpu::XeGPUDialect",
"vector::VectorDialect",
"arith::ArithDialect",
"func::FuncDialect",
"memref::MemRefDialect"
];
}

#endif // MLIR_DIALECT_XEGPU_TRANSFORMS_PASSES_TD
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/XeGPU/Transforms/Transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace xegpu {

/// Appends patterns for folding aliasing ops into XeGPU ops into `patterns`.
void populateXeGPUFoldAliasOpsPatterns(RewritePatternSet &patterns);
void populateXeGPUDistributeToWIPatterns(RewritePatternSet &patterns);

} // namespace xegpu
} // namespace mlir
Expand Down
27 changes: 22 additions & 5 deletions mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/Dialect/XeGPU/IR/XeGPU.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/TypeRange.h"
#include "mlir/IR/TypeUtilities.h"

#include "llvm/Support/Debug.h"
Expand Down Expand Up @@ -254,14 +255,23 @@ LogicalResult LoadNdOp::verify() {
tdescShape.insert(it, array_len);
}

if (tdescShape != valueShape)
return emitOpError() << "Result shape doesn't match TensorDesc shape."
<< "The expected shape is " << makeString(tdescShape)
<< ". But the given shape is "
<< makeString(valueShape) << ".\n";
// if (tdescShape != valueShape)
// return emitOpError() << "Result shape doesn't match TensorDesc shape."
// << "The expected shape is " <<
// makeString(tdescShape)
// << ". But the given shape is "
// << makeString(valueShape) << ".\n";
return success();
}

void LoadNdOp::getEffects(
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
&effects) {
if (llvm::isa<TensorDescType>(getTensorDescType()))
effects.emplace_back(MemoryEffects::Read::get(), &getTensorDescMutable(),
SideEffects::DefaultResource::get());
}

//===----------------------------------------------------------------------===//
// XeGPU_StoreNdOp
//===----------------------------------------------------------------------===//
Expand All @@ -287,6 +297,13 @@ LogicalResult StoreNdOp::verify() {
if (!isWriteHintOrNone(getL3HintAttr()))
return emitOpError("invlid l3_hint: ") << getL3HintAttr();

auto tdescShape = getShapeOf(dstTy);
auto valueShape = getShapeOf(valTy);
if (!dstTy.getSGMapAttr() && tdescShape != valueShape)
return emitOpError() << "Result shape doesn't match TensorDesc shape."
<< "The expected shape is " << makeString(tdescShape)
<< ". But the given shape is "
<< makeString(valueShape) << ".\n";
return success();
}

Expand Down
4 changes: 4 additions & 0 deletions mlir/lib/Dialect/XeGPU/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_mlir_dialect_library(MLIRXeGPUTransforms
XeGPUFoldAliasOps.cpp
XeGPUDistributeToWI.cpp

ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/XeGPU
Expand All @@ -12,6 +13,9 @@ add_mlir_dialect_library(MLIRXeGPUTransforms
MLIRIR
MLIRMemRefDialect
MLIRXeGPUDialect
MLIRVectorDialect
MLIRArithDialect
MLIRFuncDialect
MLIRPass
MLIRTransforms
)
Loading