Skip to content

Commit 31fd327

Browse files
committed
[mlir] Use intel_reqd_sub_group_size as backup for gpu.known_subgroup_size
In the GPU To LLVM SPV patterns
1 parent aca998e commit 31fd327

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

mlir/lib/Conversion/GPUToLLVMSPV/GPUToLLVMSPV.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,36 @@ struct GPUShuffleConversion final : ConvertOpToLLVMPattern<gpu::ShuffleOp> {
271271
typeMangling.value());
272272
}
273273

274-
/// Get the subgroup size from the target or return a default.
275-
static std::optional<uint32_t> getSubgroupSize(Operation *op) {
276-
// TODO check for intel_reqd_sub_group_size
277-
278-
FunctionOpInterface func = op->getParentOfType<FunctionOpInterface>();
279-
if (!func)
274+
static std::optional<uint32_t>
275+
getIntelReqdSubGroupSize(Operation* func) {
276+
LLVM::LLVMFuncOp llvmFunc = llvm::dyn_cast<LLVM::LLVMFuncOp>(func);
277+
if (!llvmFunc)
280278
return {};
279+
return llvmFunc.getIntelReqdSubGroupSize();
280+
}
281281

282+
static std::optional<uint32_t>
283+
getKnownSubgroupSize(FunctionOpInterface func) {
282284
IntegerAttr knownSubgroupSizeAttr =
283-
mlir::gpu::GPUDialect::KnownSubgroupSizeAttrHelper(op->getContext())
285+
mlir::gpu::GPUDialect::KnownSubgroupSizeAttrHelper(func->getContext())
284286
.getAttr(func);
285287
if (!knownSubgroupSizeAttr)
286288
return {};
289+
287290
return knownSubgroupSizeAttr.getInt();
288291
}
289292

293+
/// Get the subgroup size from the target or return a default.
294+
static std::optional<uint32_t> getSubgroupSize(Operation *op) {
295+
FunctionOpInterface func = op->getParentOfType<FunctionOpInterface>();
296+
if (!func)
297+
return {};
298+
auto knownSubgroupSize = getKnownSubgroupSize(func);
299+
if (knownSubgroupSize)
300+
return knownSubgroupSize;
301+
return getIntelReqdSubGroupSize(func);
302+
}
303+
290304
static bool hasValidWidth(gpu::ShuffleOp op, uint32_t subgroupSize) {
291305
llvm::APInt val;
292306
Value width = op.getWidth();

mlir/test/Conversion/GPUToLLVMSPV/gpu-to-llvm-spv.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ gpu.module @shuffles {
257257

258258
// CHECK-LABEL: gpu_shuffles
259259
// CHECK-SAME: (%[[VAL_0:.*]]: i32, %[[VAL_1:.*]]: i32, %[[VAL_2:.*]]: i64, %[[VAL_3:.*]]: i32, %[[VAL_4:.*]]: f32, %[[VAL_5:.*]]: i32, %[[VAL_6:.*]]: f64, %[[VAL_7:.*]]: i32)
260-
func.func @gpu_shuffles(%val0: i32, %id: i32,
260+
llvm.func @gpu_shuffles(%val0: i32, %id: i32,
261261
%val1: i64, %mask: i32,
262262
%val2: f32, %delta_up: i32,
263-
%val3: f64, %delta_down: i32) attributes {gpu.known_subgroup_size = 32 : i32} {
263+
%val3: f64, %delta_down: i32) attributes { intel_reqd_sub_group_size = 32 : i32 } {
264264
%width = arith.constant 32 : i32
265265
// CHECK: llvm.call spir_funccc @_Z17sub_group_shuffleij(%[[VAL_0]], %[[VAL_1]]) {
266266
// CHECK-SAME-DAG: no_unwind
@@ -294,7 +294,7 @@ gpu.module @shuffles {
294294
%shuffleResult1, %valid1 = gpu.shuffle xor %val1, %mask, %width : i64
295295
%shuffleResult2, %valid2 = gpu.shuffle up %val2, %delta_up, %width : f32
296296
%shuffleResult3, %valid3 = gpu.shuffle down %val3, %delta_down, %width : f64
297-
return
297+
llvm.return
298298
}
299299
}
300300

0 commit comments

Comments
 (0)