Skip to content

Commit f03fcd7

Browse files
[PATCH][mlir][spirv] Added mapping for the gpu memory space
1 parent f217947 commit f03fcd7

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
From e448e3107788b55b7af4de8de111b0b983f57af1 Mon Sep 17 00:00:00 2001
2+
From: Andrey Pavlenko <[email protected]>
3+
Date: Sat, 31 Aug 2024 20:56:31 +0200
4+
Subject: [PATCH][mlir][spirv] Added mapping for the gpu memory space
5+
6+
---
7+
.../MapMemRefStorageClassPass.cpp | 19 ++++++++++++++++++-
8+
1 file changed, 18 insertions(+), 1 deletion(-)
9+
10+
diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp
11+
index 4cbc3dfdae22..ac278c908fc5 100644
12+
--- a/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp
13+
+++ b/mlir/lib/Conversion/MemRefToSPIRV/MapMemRefStorageClassPass.cpp
14+
@@ -27,6 +27,7 @@
15+
#include "llvm/ADT/SmallVectorExtras.h"
16+
#include "llvm/ADT/StringExtras.h"
17+
#include "llvm/Support/Debug.h"
18+
+#include <mlir/Dialect/GPU/IR/GPUDialect.h>
19+
#include <optional>
20+
21+
namespace mlir {
22+
@@ -121,6 +122,21 @@ spirv::mapMemorySpaceToOpenCLStorageClass(Attribute memorySpaceAttr) {
23+
if (!memorySpaceAttr)
24+
return spirv::StorageClass::CrossWorkgroup;
25+
26+
+ if (auto gpuSpace = dyn_cast<mlir::gpu::AddressSpaceAttr>(memorySpaceAttr)) {
27+
+ switch (gpuSpace.getValue()) {
28+
+ case mlir::gpu::AddressSpace::Global:
29+
+ return spirv::StorageClass::CrossWorkgroup;
30+
+ case mlir::gpu::AddressSpace::Workgroup:
31+
+ return spirv::StorageClass::Workgroup;
32+
+ case mlir::gpu::AddressSpace::Private:
33+
+ return spirv::StorageClass::Private;
34+
+ default:
35+
+ LLVM_DEBUG(llvm::dbgs() << "cannot convert " << memorySpaceAttr
36+
+ << " due to unknown memory space value\n");
37+
+ return std::nullopt;
38+
+ }
39+
+ }
40+
+
41+
// Unknown dialect custom attributes are not supported by default.
42+
// Downstream callers should plug in more specialized ones.
43+
auto intAttr = dyn_cast<IntegerAttr>(memorySpaceAttr);
44+
@@ -207,7 +223,8 @@ spirv::MemorySpaceToStorageClassConverter::MemorySpaceToStorageClassConverter(
45+
static bool isLegalType(Type type) {
46+
if (auto memRefType = dyn_cast<BaseMemRefType>(type)) {
47+
Attribute spaceAttr = memRefType.getMemorySpace();
48+
- return isa_and_nonnull<spirv::StorageClassAttr>(spaceAttr);
49+
+ return isa_and_nonnull<spirv::StorageClassAttr>(spaceAttr) ||
50+
+ isa_and_nonnull<mlir::gpu::AddressSpaceAttr>(spaceAttr);
51+
}
52+
return true;
53+
}
54+
--
55+
2.43.0

0 commit comments

Comments
 (0)