-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][nvgpu] Fix crash when handling 0D memref in OptimizeSharedMemoryPass #124517
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
Conversation
…ryPass This PR adds a check for 0D memref types to prevent a crash.
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-gpu Author: Longsheng Mou (CoTinker) ChangesThis PR adds a check for 0D memref types to prevent a crash. Fixes #119855. Full diff: https://github.com/llvm/llvm-project/pull/124517.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp b/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp
index 31ffacb29256f5..7cef4f60bc011c 100644
--- a/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp
+++ b/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp
@@ -152,6 +152,9 @@ mlir::nvgpu::optimizeSharedMemoryReadsAndWrites(Operation *parentOp,
if (!memRefType || !NVGPUDialect::hasSharedMemoryAddressSpace(memRefType))
return failure();
+ if (memRefType.getRank() == 0)
+ return failure();
+
// Abort if the given value has any sub-views; we do not do any alias
// analysis.
bool hasSubView = false;
diff --git a/mlir/test/Dialect/NVGPU/optimize-shared-memory.mlir b/mlir/test/Dialect/NVGPU/optimize-shared-memory.mlir
index 5a212815ceb2a1..7477e187286771 100644
--- a/mlir/test/Dialect/NVGPU/optimize-shared-memory.mlir
+++ b/mlir/test/Dialect/NVGPU/optimize-shared-memory.mlir
@@ -238,3 +238,13 @@ func.func @abort_if_subview(%arg0: memref<128x128xf16>,
return %mat: vector<1x2xf16>
}
+
+// -----
+
+// Ensure this case not crash
+
+// CHECK-LABEL: func @test_0_d
+func.func @test_0_d() -> memref<i32, #gpu.address_space<workgroup>> {
+ %alloc = memref.alloc() : memref<i32, #gpu.address_space<workgroup>>
+ return %alloc : memref<i32, #gpu.address_space<workgroup>>
+}
|
@llvm/pr-subscribers-mlir-nvgpu Author: Longsheng Mou (CoTinker) ChangesThis PR adds a check for 0D memref types to prevent a crash. Fixes #119855. Full diff: https://github.com/llvm/llvm-project/pull/124517.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp b/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp
index 31ffacb29256f5..7cef4f60bc011c 100644
--- a/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp
+++ b/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp
@@ -152,6 +152,9 @@ mlir::nvgpu::optimizeSharedMemoryReadsAndWrites(Operation *parentOp,
if (!memRefType || !NVGPUDialect::hasSharedMemoryAddressSpace(memRefType))
return failure();
+ if (memRefType.getRank() == 0)
+ return failure();
+
// Abort if the given value has any sub-views; we do not do any alias
// analysis.
bool hasSubView = false;
diff --git a/mlir/test/Dialect/NVGPU/optimize-shared-memory.mlir b/mlir/test/Dialect/NVGPU/optimize-shared-memory.mlir
index 5a212815ceb2a1..7477e187286771 100644
--- a/mlir/test/Dialect/NVGPU/optimize-shared-memory.mlir
+++ b/mlir/test/Dialect/NVGPU/optimize-shared-memory.mlir
@@ -238,3 +238,13 @@ func.func @abort_if_subview(%arg0: memref<128x128xf16>,
return %mat: vector<1x2xf16>
}
+
+// -----
+
+// Ensure this case not crash
+
+// CHECK-LABEL: func @test_0_d
+func.func @test_0_d() -> memref<i32, #gpu.address_space<workgroup>> {
+ %alloc = memref.alloc() : memref<i32, #gpu.address_space<workgroup>>
+ return %alloc : memref<i32, #gpu.address_space<workgroup>>
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for fixing it
This PR adds a check for 0D memref types to prevent a crash. Fixes #119855.