Skip to content

[mlir][amdgpu] Add amdgpu.swizzle_bitmode op #135513

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 35 additions & 8 deletions mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPU.td
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def AMDGPU_Dialect : Dialect {
let useDefaultAttributePrinterParser = 1;
}

def AnyIntegerOrFloat : AnyTypeOf<[AnySignlessInteger, AnyFloat], "Integer or Float">;

def AnyIntegerOrFloatOr1DVector :
AnyTypeOf<[AnyIntegerOrFloat, VectorOfRankAndType<[1], [AnyIntegerOrFloat]>]>;

//===----------------------------------------------------------------------===//
// AMDGPU general attribute definitions
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -533,14 +538,15 @@ def AMDGPU_DPPPerm : I32EnumAttr<"DPPPerm",
def AMDGPU_DPPPermAttr : EnumAttr<AMDGPU_Dialect, AMDGPU_DPPPerm,
"dpp_perm">;

def AMDGPU_DPPOp : AMDGPU_Op<"dpp", [SameTypeOperands, AllTypesMatch<["result", "old", "src"]>]>,
def AMDGPU_DPPOp : AMDGPU_Op<"dpp",
[Pure, SameTypeOperands, AllTypesMatch<["result", "old", "src"]>]>,
Arguments<(ins AnyType:$old,
AnyType:$src,
AMDGPU_DPPPermAttr:$kind,
OptionalAttr<AnyAttrOf<[I32Attr, ArrayAttr, UnitAttr]>>:$permArgument,
DefaultValuedAttr<I32Attr, "0xf">:$row_mask,
DefaultValuedAttr<I32Attr, "0xf">:$bank_mask,
DefaultValuedAttr<BoolAttr, "false">:$bound_ctrl)> {
AnyType:$src,
AMDGPU_DPPPermAttr:$kind,
OptionalAttr<AnyAttrOf<[I32Attr, ArrayAttr, UnitAttr]>>:$permArgument,
DefaultValuedAttr<I32Attr, "0xf">:$row_mask,
DefaultValuedAttr<I32Attr, "0xf">:$bank_mask,
DefaultValuedAttr<BoolAttr, "false">:$bound_ctrl)> {
let summary = "AMDGPU DPP operation";
let description = [{
This operation represents DPP functionality in a GPU program.
Expand All @@ -565,6 +571,27 @@ def AMDGPU_DPPOp : AMDGPU_Op<"dpp", [SameTypeOperands, AllTypesMatch<["result",
let hasVerifier = 1;
}

def AMDGPU_SwizzleBitModeOp : AMDGPU_Op<"swizzle_bitmode",
[Pure, AllTypesMatch<["result", "src"]>]>,
Arguments<(ins AnyIntegerOrFloatOr1DVector:$src,
I32Attr:$and_mask,
I32Attr:$or_mask,
I32Attr:$xor_mask
)> {
let summary = "AMDGPU ds_swizzle op, bitmode variant";
let description = [{
High-level wrapper on bitmode `rocdl.ds_swizzle` op, masks are represented
as separate fields so user won't need to do manual bitpacking.

Supports arbitrary int/float/vector types, which will be repacked to i32 and
one or more `rocdl.ds_swizzle` ops during lowering.
}];
let results = (outs AnyIntegerOrFloatOr1DVector:$result);
let assemblyFormat = [{
$src $and_mask $or_mask $xor_mask attr-dict `:` type($result)
}];
}

def AMDGPU_LDSBarrierOp : AMDGPU_Op<"lds_barrier"> {
let summary = "Barrier that includes a wait for LDS memory operations.";
let description = [{
Expand Down Expand Up @@ -794,7 +821,7 @@ def AMDGPU_GatherToLDSOp :

The `$dst`, along with its indices, points to the memory location the subgroup of this thread
will write to.

Note: only enabled for gfx942 and later.
}];
let assemblyFormat = [{
Expand Down
7 changes: 7 additions & 0 deletions mlir/test/Dialect/AMDGPU/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,10 @@ func.func @wmma(%arg0 : vector<16xf16>, %arg1 : vector<8xf16>) -> vector<8xf16>
%0 = amdgpu.wmma %arg0 * %arg0 + %arg1 : vector<16xf16>, vector<16xf16>, vector<8xf16>
func.return %0 : vector<8xf16>
}

// CHECK-LABEL: func @swizzle_bitmode
func.func @swizzle_bitmode(%arg0 : f32) -> f32 {
// CHECK: amdgpu.swizzle_bitmode
%0 = amdgpu.swizzle_bitmode %arg0 1 2 4 : f32
Comment on lines +163 to +164
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some negative tests for unsupported data types?

func.return %0 : f32
}