Skip to content

Commit

Permalink
[quick fix] address review comments and sequrity issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Dewei-Wang-sh authored and silee2 committed Nov 15, 2023
1 parent ffcce66 commit 3f5cd3b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/Conversion/XeGPUToSPIRV/XeGPUToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ void lookupOrInsertIntrinsic(ConversionPatternRewriter &rewriter, Operation *op,
}
}

/// @brief
/// convert the tensor descriptor to [2xi64] which is of the format
/// -> [base pointer: i64, offsetX: i32, offsetY: i32] for 2D tensor desc
/// -> [base pointer: i64, unused] for 1D and scattered tensor desc
class CreateNdDescToVCPattern : public OpConversionPattern<CreateNdDescOp> {
public:
using OpConversionPattern<CreateNdDescOp>::OpConversionPattern;
Expand Down Expand Up @@ -494,7 +498,7 @@ class LoadStorePrefetchNdToLsc : public OpConversionPattern<OpType> {
}
};

xegpu::CreateNdDescOp findDescOp(mlir::Value val) {
std::optional<xegpu::CreateNdDescOp> findDescOp(mlir::Value val) {
if (auto op = val.getDefiningOp()) {
if (auto descOp = dyn_cast<xegpu::CreateNdDescOp>(op)) {
return descOp;
Expand All @@ -508,6 +512,7 @@ xegpu::CreateNdDescOp findDescOp(mlir::Value val) {
return findDescOp(init);
} else {
assert(0 && "add more support");
return std::nullopt;
}
}

Expand Down Expand Up @@ -582,7 +587,6 @@ class LoadStorePrefetchNdToRawSend : public OpConversionPattern<OpType> {
// message descriptor
uint32_t rawSendMsg = 0;
if (rank == 2) {
// https://gfxspecs.intel.com/Predator/Home/Index/53680
rawSendMsg |= (isLoad || isPrefetch) ? 3 : 7;
rawSendMsg |= (vnni ? 1 : 0) << 7;
rawSendMsg |= (encodeDataum(elmType) - 1) << 9;
Expand All @@ -592,7 +596,6 @@ class LoadStorePrefetchNdToRawSend : public OpConversionPattern<OpType> {
rawSendMsg |= 1 << 25;
} else {
// rank == 1
// https://gfxspecs.intel.com/Predator/Home/Index/53523
rawSendMsg |= (isLoad || isPrefetch) ? 0 : 4;
rawSendMsg |= 3 << 7;
rawSendMsg |= 3 << 9;
Expand All @@ -604,8 +607,12 @@ class LoadStorePrefetchNdToRawSend : public OpConversionPattern<OpType> {
}
auto msg = createIntConstant(i32Type, rawSendMsg);
// payload
// payload is v8i32 = [base:i64, surfaceWidth:i32, surfaceHeight:i32,
// surefacePitch:i32, offsetX:i32, offsetY:i32, blockInfo:i32]
// the base/surfaceInfo/blockInfo are staticly from the tensor desc
// while the offsetX/Y are dynamicly udpated
auto insertPoint = rewriter.saveInsertionPoint();
CreateNdDescOp createDescOp = findDescOp(op.template getTensorDesc());
CreateNdDescOp createDescOp = *findDescOp(op.template getTensorDesc());
rewriter.setInsertionPointAfter(createDescOp);
auto v8i32 = VectorType::get(8, i32Type);
auto v4i64 = VectorType::get(4, i64Type);
Expand Down Expand Up @@ -1031,7 +1038,6 @@ class CreateNbarrierToVCPattern : public OpConversionPattern<CreateNbarrierOp> {
Value nbarrier_src =
rewriter.create<spirv::ConstantOp>(loc, v8i32Type, constantData);

// payload format https://gfxspecs.intel.com/Predator/Home/Index/72064
Value payload = zext(i32Type, nbarrier_id);

Value payload_nbarrier_role =
Expand Down Expand Up @@ -1071,11 +1077,9 @@ class NbarrierArriveToVCPattern : public OpConversionPattern<NbarrierArriveOp> {
Value exec_size = i8_val(0);
Value predicate = i1_val(1);
Value numsrc1 = i8_val(1); // register nums of payload
Value sfid =
i8_val(3); // https://gfxspecs.intel.com/Predator/Home/Index/47532
Value sfid = i8_val(3);
Value etDesc = i32_val(0);
Value msg_desc = i32_val(
0x2000004); // https://gfxspecs.intel.com/Predator/Home/Index/53524
Value msg_desc = i32_val(0x2000004);

SmallVector<Value> args{modifier, exec_size, predicate, numsrc1,
sfid, etDesc, msg_desc, payload};
Expand Down

0 comments on commit 3f5cd3b

Please sign in to comment.