Skip to content

Commit b813731

Browse files
Adding permlanex16 to rocdl mlir dialect
Signed-off-by: Muzammiluddin Syed <[email protected]>
1 parent 34598fd commit b813731

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPU.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ def AMDGPU_DPPPerm : I32EnumAttr<"DPPPerm",
524524
I32EnumAttrCase<"row_mirror", 8>,
525525
I32EnumAttrCase<"row_half_mirror", 9>,
526526
I32EnumAttrCase<"row_bcast_15", 10>,
527-
I32EnumAttrCase<"row_bcast_31", 11>
527+
I32EnumAttrCase<"row_bcast_31", 11>,
528+
I32EnumAttrCase<"row_share", 12>
528529
]> {
529530
let genSpecializedAttr = 0;
530531
let cppNamespace = "::mlir::amdgpu";
@@ -557,6 +558,7 @@ def AMDGPU_DPPOp : AMDGPU_Op<"dpp", [SameTypeOperands, AllTypesMatch<["result",
557558
- Reverse within a half-row (`row_half_mirror`)
558559
- Broadcast the 15th lane of each row to the next row (`row_bcast`)
559560
- Broadcast lane 31 to rows 2 and 3 (`row_bcast`)
561+
- Broadcast a lane [0-15] within row 0 to all lanes of row 0 (`row_share`)
560562
}];
561563
let results = (outs AnyType:$result);
562564
let assemblyFormat = [{

mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,22 @@ def ROCDL_DPPUpdateOp : ROCDL_IntrOp<"update.dpp", [], [0],
668668
}];
669669
}
670670

671+
// PermLaneX16 intrinsic operation
672+
def ROCDL_PermlaneX16Op : ROCDL_IntrOp<"permlanex16", [], [0],
673+
[AllTypesMatch<["res", "old", "src0"]>, AllTypesMatch<["src1", "src2"]>], 1, 0, 0,
674+
[4, 5], ["fi", "boundControl"]>,
675+
Arguments<(ins LLVM_Type:$old, LLVM_Type:$src0, LLVM_Type:$src1, LLVM_Type:$src2,
676+
I1Attr:$fi, I1Attr:$boundControl)> {
677+
let results = (outs LLVM_Type:$res);
678+
let assemblyFormat = [{
679+
attr-dict $old `,` $src0 `,` $src1 `,` $src2 `,` $fi `,` $boundControl `:` type($src0) `,` type($src1)
680+
}];
681+
let description = [{
682+
Performs a `permlanex16` operation with the given operands, applying the
683+
permutation specified by $fi to the provided inputs.
684+
}];
685+
}
686+
671687
def ROCDL_V2I16Type : FixedVectorOfLengthAndType<[2], [I16]>,
672688
BuildableType<"::mlir::VectorType::get("
673689
"{2},$_builder.getI16Type())">;

mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,7 @@ struct AMDGPUDPPLowering : public ConvertOpToLLVMPattern<DPPOp> {
12931293
ROW_HALF_MIRROR = 0x141,
12941294
BCAST15 = 0x142,
12951295
BCAST31 = 0x143,
1296+
ROW_SHARE0 = 0x150
12961297
};
12971298

12981299
auto kind = DppOp.getKind();
@@ -1350,6 +1351,11 @@ struct AMDGPUDPPLowering : public ConvertOpToLLVMPattern<DPPOp> {
13501351
case DPPPerm::row_bcast_31:
13511352
DppCtrl = DppCtrl::BCAST31;
13521353
break;
1354+
case DPPPerm::row_share:
1355+
if (auto intAttr = cast<IntegerAttr>(*permArgument)) {
1356+
DppCtrl = intAttr.getInt() + DppCtrl::ROW_SHARE0;
1357+
}
1358+
break;
13531359
}
13541360

13551361
// Check for row_mask, bank_mask, bound_ctrl if they exist and create

mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,20 @@ LogicalResult DPPOp::verify() {
468468
}
469469
break;
470470
}
471+
472+
case DPPPerm::row_share: {
473+
if (!permArgument) {
474+
return emitOpError("Attribute '" + Twine(stringifyDPPPerm(kind)) +
475+
"' value not specified");
476+
}
477+
if (auto intAttr = dyn_cast<IntegerAttr>(permArgument)) {
478+
uint32_t attrValue = intAttr.getInt();
479+
if (attrValue < 0 || attrValue > 15) {
480+
return emitOpError(
481+
"Attribute value for 'row_share' must be between 0 and 15");
482+
}
483+
}
484+
} break;
471485
}
472486
return success();
473487
}

mlir/test/Conversion/AMDGPUToROCDL/dpp.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,11 @@ func.func @row_bcast_update_dpp_f16(%arg0: f16, %arg1: f16) -> f16 {
137137
%0 = amdgpu.dpp %arg0 %arg1 row_bcast_15 { bound_ctrl = true } : f16
138138
return %0 : f16
139139
}
140+
141+
func.func @dpp_row_share(%arg0: i32, %arg1: i32) -> i32 {
142+
// CHECK-LABEL: func @dpp_row_share
143+
// CHECK: rocdl.update.dpp %arg0, %arg1 with 351, 15, 15, false : i32
144+
// CHECK: return %0 : i32
145+
%0 = amdgpu.dpp %arg0 %arg1 row_share ( 0xf : i32 ) : i32
146+
return %0 : i32
147+
}

0 commit comments

Comments
 (0)