[flang-commits] [clang-tools-extra] [flang] [llvm] [mlir] [libcxx] [libc] [compiler-rt] [clang] [mlir][gpu] Support dynamic_shared_memory Op with vector dialect (PR #74475)
Guray Ozen via flang-commits
flang-commits at lists.llvm.org
Tue Dec 5 10:59:16 PST 2023
https://github.com/grypp updated https://github.com/llvm/llvm-project/pull/74475
>From 2848c9011cb4db5e91754300eb466927738a363a Mon Sep 17 00:00:00 2001
From: Guray Ozen <guray.ozen at gmail.com>
Date: Tue, 5 Dec 2023 15:16:20 +0100
Subject: [PATCH] [mlir][gpu] Support dynamic_shared_memory Op with vector
dialect
`gpu.dynamic_shared_memory` currently does not get lowered when it is used with vector dialect. The reason is that vector-to-llvm conversion is not included in gpu-to-nvvm. This PR includes that and adds a test.
---
.../GPUToNVVM/LowerGpuOpsToNVVMOps.cpp | 2 ++
.../GPUCommon/lower-memory-space-attrs.mlir | 20 +++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index 4855fd187eb58..0e978ca0a6424 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -21,6 +21,7 @@
#include "mlir/Conversion/LLVMCommon/LoweringOptions.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
+#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
@@ -282,6 +283,7 @@ struct LowerGpuOpsToNVVMOpsPass
populateFinalizeMemRefToLLVMConversionPatterns(converter, llvmPatterns);
populateGpuToNVVMConversionPatterns(converter, llvmPatterns);
populateGpuWMMAToNVVMConversionPatterns(converter, llvmPatterns);
+ populateVectorToLLVMConversionPatterns(converter, llvmPatterns);
if (this->hasRedux)
populateGpuSubgroupReduceOpLoweringPattern(converter, llvmPatterns);
LLVMConversionTarget target(getContext());
diff --git a/mlir/test/Conversion/GPUCommon/lower-memory-space-attrs.mlir b/mlir/test/Conversion/GPUCommon/lower-memory-space-attrs.mlir
index 14f5302ac2002..6d50770f53543 100644
--- a/mlir/test/Conversion/GPUCommon/lower-memory-space-attrs.mlir
+++ b/mlir/test/Conversion/GPUCommon/lower-memory-space-attrs.mlir
@@ -46,3 +46,23 @@ gpu.module @kernel {
// CHECK: [[value:%.+]] = llvm.load
// CHECK-SAME: : !llvm.ptr<1> -> f32
// CHECK: llvm.return [[value]]
+
+// -----
+
+gpu.module @kernel {
+ gpu.func @dynamic_shmem_with_vector(%arg1: memref<1xf32>) {
+ %0 = arith.constant 0 : index
+ %1 = gpu.dynamic_shared_memory : memref<?xi8, #gpu.address_space<workgroup>>
+ %2 = memref.view %1[%0][] : memref<?xi8, #gpu.address_space<workgroup>> to memref<1xf32, #gpu.address_space<workgroup>>
+ %3 = vector.load %2[%0] : memref<1xf32, #gpu.address_space<workgroup>>, vector<1xf32>
+ vector.store %3, %arg1[%0] : memref<1xf32>, vector<1xf32>
+ gpu.return
+ }
+}
+
+// ROCDL: llvm.mlir.global internal @__dynamic_shmem__0() {addr_space = 3 : i32} : !llvm.array<0 x i8>
+// NVVM: llvm.mlir.global internal @__dynamic_shmem__0() {addr_space = 3 : i32, alignment = 16 : i64} : !llvm.array<0 x i8>
+// CHECK-LABEL: llvm.func @dynamic_shmem_with_vector
+// CHECK: llvm.mlir.addressof @__dynamic_shmem__0 : !llvm.ptr<3>
+// CHECK: llvm.load %{{.*}} {alignment = 4 : i64} : !llvm.ptr<3> -> vector<1xf32>
+// CHECK: llvm.store
More information about the flang-commits
mailing list