Skip to content

Commit fe36b64

Browse files
committed
[mlir][gpu] Add the OffloadEmbeddingAttr offloading translation attr
This patch adds the offloading translation attribute. This attribute uses LLVM offloading infrastructure to embed GPU binaries in the IR. At the program start, the LLVM offloading mechanism registers kernels and variables with the runtime library: CUDA RT, HIP RT, or LibOMPTarget. The offloading mechanism relies on the runtime library to dispatch the correct kernel based on the registered symbols. This patch is 3/4 on introducing the OffloadEmbeddingAttr GPU translation attribute. Note: Ignore the base commits; those are being reviewed in PRs #78057, #78098, and #78073.
1 parent 90064f0 commit fe36b64

File tree

4 files changed

+498
-59
lines changed

4 files changed

+498
-59
lines changed

mlir/include/mlir/Dialect/GPU/IR/CompilationAttrs.td

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,39 @@ def GPU_SelectObjectAttr : GPU_Attr<"SelectObject", "select_object", [
107107
let genVerifyDecl = 1;
108108
}
109109

110+
//===----------------------------------------------------------------------===//
111+
// GPU LLVM offload attribute.
112+
//===----------------------------------------------------------------------===//
113+
def GPU_OffloadOpenMP : I32EnumAttrCase<"OpenMP", 1, "omp">;
114+
def GPU_OffloadCUDA : I32EnumAttrCase<"CUDA", 2, "cuda">;
115+
def GPU_OffloadHIP : I32EnumAttrCase<"HIP", 3, "hip">;
116+
def GPU_OffloadKindEnum : GPU_I32Enum<
117+
"OffloadKind", "GPU offload kind", [
118+
GPU_OffloadOpenMP,
119+
GPU_OffloadCUDA,
120+
GPU_OffloadHIP
121+
]>;
122+
123+
def GPU_OffloadEmbeddingAttr : GPU_Attr<"OffloadEmbedding", "offload_embedding", [
124+
OffloadingTranslationAttrTrait
125+
]> {
126+
let description = [{
127+
This GPU offloading handler uses LLVM offloading infrastructure to embed GPU
128+
binaries in the IR. At program start, the LLVM offloading mechanism registers
129+
kernels and variables with the runtime library: CUDA RT, HIP RT or
130+
LibOMPTarget.
131+
The offloading mechanism relies on the runtime library to dispatch the
132+
correct kernel based on the registered symbols.
133+
This offload mechanism requires to specify which runtime is being called,
134+
this is done by the `kind` parameter.
135+
Example:
136+
```mlir
137+
gpu.binary @binary <#gpu.offload_embedding<omp>> [...]
138+
gpu.binary @binary <#gpu.offload_embedding<cuda>> [...]
139+
```
140+
}];
141+
let parameters = (ins "gpu::OffloadKind":$kind);
142+
let assemblyFormat = [{ `<` $kind `>` }];
143+
}
144+
110145
#endif // GPU_COMPILATION_ATTRS
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
add_mlir_translation_library(MLIRGPUToLLVMIRTranslation
22
GPUToLLVMIRTranslation.cpp
3-
SelectObjectAttr.cpp
3+
OffloadingTranslationAttrs.cpp
44

55
LINK_COMPONENTS
66
Core
7+
FrontendOffloading
8+
Object
79

810
LINK_LIBS PUBLIC
911
MLIRIR
1012
MLIRGPUDialect
1113
MLIRLLVMDialect
1214
MLIRSupport
15+
MLIRTargetLLVM
1316
MLIRTargetLLVMIRExport
1417
)

0 commit comments

Comments
 (0)