Skip to content

Commit baae949

Browse files
silee2akroviakov
andauthored
[MLIR][GPU][XeVM] Add XeVM target and XeVM dialect integration tests. (llvm#148286)
As part of XeVM dialect upsteaming, covers remaining parts required for XeVM dialect integration and testing. It has two high level components - XeVM target and serialization support - XeVM dialect integration tests using level zero runtime Co-Authored-by: Artem Kroviakov <[email protected]>
1 parent 06d2d1e commit baae949

File tree

16 files changed

+1145
-0
lines changed

16 files changed

+1145
-0
lines changed

mlir/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ else()
137137
set(MLIR_ENABLE_ROCM_CONVERSIONS 0)
138138
endif()
139139

140+
# Build the XeVM conversions and run according tests if the SPIRV backend
141+
# is available.
142+
if ("SPIRV" IN_LIST LLVM_TARGETS_TO_BUILD)
143+
set(MLIR_ENABLE_XEVM_CONVERSIONS 1)
144+
else()
145+
set(MLIR_ENABLE_XEVM_CONVERSIONS 0)
146+
endif()
147+
140148
set(MLIR_ENABLE_CUDA_RUNNER 0 CACHE BOOL "Enable building the MLIR CUDA runner")
141149
set(MLIR_ENABLE_ROCM_RUNNER 0 CACHE BOOL "Enable building the MLIR ROCm runner")
142150
set(MLIR_ENABLE_SYCL_RUNNER 0 CACHE BOOL "Enable building the MLIR SYCL runner")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===-- Target.h - MLIR XeVM target registration ----------------*- C++ -*-===//
2+
//
3+
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This provides registration calls for attaching the XeVM target interface.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_TARGET_LLVM_XEVM_TARGET_H
14+
#define MLIR_TARGET_LLVM_XEVM_TARGET_H
15+
16+
namespace mlir {
17+
class DialectRegistry;
18+
class MLIRContext;
19+
namespace xevm {
20+
/// Registers the `TargetAttrInterface` for the `#xevm.target` attribute in
21+
/// the given registry.
22+
void registerXeVMTargetInterfaceExternalModels(mlir::DialectRegistry &registry);
23+
24+
/// Registers the `TargetAttrInterface` for the `#xevm.target` attribute in
25+
/// the registry associated with the given context.
26+
void registerXeVMTargetInterfaceExternalModels(mlir::MLIRContext &context);
27+
} // namespace xevm
28+
} // namespace mlir
29+
30+
#endif // MLIR_TARGET_LLVM_XEVM_TARGET_H
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//===-- Utils.h - MLIR XeVM target utils ------------------------*- C++ -*-===//
2+
//
3+
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This files declares XeVM target related utility classes and functions.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_TARGET_LLVM_XEVM_UTILS_H
14+
#define MLIR_TARGET_LLVM_XEVM_UTILS_H
15+
16+
#include "mlir/Dialect/GPU/IR/CompilationInterfaces.h"
17+
#include "mlir/Dialect/LLVMIR/XeVMDialect.h"
18+
#include "mlir/IR/Attributes.h"
19+
#include "mlir/Target/LLVM/ModuleToObject.h"
20+
21+
namespace mlir {
22+
namespace xevm {
23+
24+
/// Base class for all XeVM serializations from GPU modules into binary strings.
25+
/// By default this class serializes into LLVM bitcode.
26+
class SerializeGPUModuleBase : public LLVM::ModuleToObject {
27+
public:
28+
SerializeGPUModuleBase(Operation &module, XeVMTargetAttr target,
29+
const gpu::TargetOptions &targetOptions = {});
30+
31+
/// Returns the target attribute.
32+
XeVMTargetAttr getTarget() const;
33+
34+
/// Loads the bitcode files in `librariesToLink`.
35+
std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
36+
loadBitcodeFiles(llvm::Module &module) override;
37+
38+
/// Returns the gpu module being serialized.
39+
gpu::GPUModuleOp getGPUModuleOp();
40+
41+
/// Compiles to native code using `ocloc`.
42+
std::optional<SmallVector<char, 0>> compileToBinary(const std::string &asmStr,
43+
StringRef inputFormat);
44+
45+
protected:
46+
/// XeVM Target attribute.
47+
XeVMTargetAttr xeTarget;
48+
/// List of LLVM bitcode to link into after translation to LLVM IR.
49+
/// The attributes can be StringAttr pointing to a file path, or
50+
/// a Resource blob pointing to the LLVM bitcode in-memory.
51+
SmallVector<Attribute> librariesToLink;
52+
53+
/// Returns the path to the tool used for serialization.
54+
std::optional<std::string> findTool(StringRef tool);
55+
56+
/// GPU compilation target options.
57+
gpu::TargetOptions targetOptions;
58+
};
59+
} // namespace xevm
60+
} // namespace mlir
61+
62+
#endif // MLIR_TARGET_LLVM_XEVM_UTILS_H

mlir/lib/Dialect/GPU/Transforms/XeVMAttachTarget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mlir/Dialect/LLVMIR/XeVMDialect.h"
1818
#include "mlir/IR/Builders.h"
1919
#include "mlir/Pass/Pass.h"
20+
#include "mlir/Target/LLVM/XeVM/Target.h"
2021
#include "llvm/Support/Regex.h"
2122

2223
namespace mlir {

mlir/lib/RegisterAllDialects.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
#include "mlir/Interfaces/CastInterfaces.h"
103103
#include "mlir/Target/LLVM/NVVM/Target.h"
104104
#include "mlir/Target/LLVM/ROCDL/Target.h"
105+
#include "mlir/Target/LLVM/XeVM/Target.h"
105106
#include "mlir/Target/SPIRV/Target.h"
106107

107108
/// Add all the MLIR dialects to the provided registry.
@@ -199,6 +200,7 @@ void mlir::registerAllDialects(DialectRegistry &registry) {
199200
NVVM::registerNVVMTargetInterfaceExternalModels(registry);
200201
ROCDL::registerROCDLTargetInterfaceExternalModels(registry);
201202
spirv::registerSPIRVTargetInterfaceExternalModels(registry);
203+
xevm::registerXeVMTargetInterfaceExternalModels(registry);
202204
}
203205

204206
/// Append all the MLIR dialects to the registry contained in the given context.

mlir/lib/RegisterAllExtensions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h"
5959
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
6060
#include "mlir/Target/LLVMIR/Dialect/ROCDL/ROCDLToLLVMIRTranslation.h"
61+
#include "mlir/Target/LLVMIR/Dialect/XeVM/XeVMToLLVMIRTranslation.h"
6162

6263
/// This function may be called to register all MLIR dialect extensions with the
6364
/// provided registry.

mlir/lib/Target/LLVM/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,26 @@ if(MLIR_ENABLE_ROCM_CONVERSIONS)
210210
)
211211
endif()
212212

213+
if ("SPIRV" IN_LIST LLVM_TARGETS_TO_BUILD)
214+
set(SPIRV_LIBS
215+
SPIRVCodeGen
216+
217+
)
218+
endif()
219+
220+
add_mlir_dialect_library(MLIRXeVMTarget
221+
XeVM/Target.cpp
222+
223+
OBJECT
224+
225+
LINK_COMPONENTS
226+
${SPIRV_LIBS}
227+
228+
LINK_LIBS PUBLIC
229+
MLIRIR
230+
MLIRExecutionEngineUtils
231+
MLIRSupport
232+
MLIRGPUDialect
233+
MLIRTargetLLVM
234+
MLIRXeVMToLLVMIRTranslation
235+
)

0 commit comments

Comments
 (0)