From 6c9885ea3540adffa8f714b2e9d63808cc47b14b Mon Sep 17 00:00:00 2001 From: Max Dawkins Date: Thu, 15 May 2025 18:55:52 +0000 Subject: [PATCH 1/2] [mlir] Check for int limits when converting gpu dims Signed-off-by: Max Dawkins --- .../GPUCommon/IndexIntrinsicsOpLowering.h | 4 +++- mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h b/mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h index 1f158b271e5c6..fa16deae7a93a 100644 --- a/mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h +++ b/mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h @@ -116,7 +116,9 @@ struct OpLowering : public ConvertOpToLLVMPattern { if (upperBound && intrType != IntrType::None) { int32_t min = (intrType == IntrType::Dim ? 1 : 0); - int32_t max = *upperBound + (intrType == IntrType::Id ? 0 : 1); + int32_t max = *upperBound == INT_MAX + ? *upperBound + : *upperBound + (intrType == IntrType::Id ? 0 : 1); newOp->setAttr("range", LLVM::ConstantRangeAttr::get( rewriter.getContext(), 32, min, max)); } diff --git a/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir b/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir index d28aa9e34c22a..e57763c037341 100644 --- a/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir +++ b/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir @@ -763,3 +763,16 @@ gpu.module @test_module { gpu.module @test_custom_data_layout attributes {llvm.data_layout = "e"} { } + +// ----- + +gpu.module @test_module { + // CHECK32-LABEL: func @gpu_dim_int_max_upper_bound() + func.func @gpu_dim_int_max_upper_bound() + -> (index) { + + // CHECK32: rocdl.workgroup.dim.x range : i32 + %bDimX = gpu.block_dim x upper_bound 2147483647 + func.return %bDimX : index + } +} From e4d859fed47dd3677301b6ce65690729a553c8c4 Mon Sep 17 00:00:00 2001 From: Max Dawkins Date: Tue, 20 May 2025 19:16:40 +0000 Subject: [PATCH 2/2] address comment Signed-off-by: Max Dawkins --- mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h b/mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h index fa16deae7a93a..aab2409ed6328 100644 --- a/mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h +++ b/mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h @@ -12,6 +12,7 @@ #include "mlir/Dialect/GPU/IR/GPUDialect.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/IR/BuiltinAttributes.h" +#include namespace mlir { namespace gpu { @@ -116,7 +117,7 @@ struct OpLowering : public ConvertOpToLLVMPattern { if (upperBound && intrType != IntrType::None) { int32_t min = (intrType == IntrType::Dim ? 1 : 0); - int32_t max = *upperBound == INT_MAX + int32_t max = *upperBound == std::numeric_limits::max() ? *upperBound : *upperBound + (intrType == IntrType::Id ? 0 : 1); newOp->setAttr("range", LLVM::ConstantRangeAttr::get(