Skip to content

Commit bafe418

Browse files
committed
[mlir] Change test-gpu-to-cubin to derive from SerializeToBlobPass
Clean-up after D98279, remove one call to createConvertGPUKernelToBlobPass(). Depends On D98203 Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D98360
1 parent 68e0133 commit bafe418

File tree

3 files changed

+42
-28
lines changed

3 files changed

+42
-28
lines changed

mlir/test/Conversion/GPUToCUDA/lower-nvvm-kernel-to-cubin.mlir

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: mlir-opt %s --test-kernel-to-cubin -split-input-file | FileCheck %s
1+
// RUN: mlir-opt %s --test-gpu-to-cubin | FileCheck %s
22

3-
// CHECK: attributes {nvvm.cubin = "CUBIN"}
3+
// CHECK: gpu.module @foo attributes {gpu.binary = "CUBIN"}
44
gpu.module @foo {
55
llvm.func @kernel(%arg0 : f32, %arg1 : !llvm.ptr<f32>)
66
// CHECK: attributes {gpu.kernel}
@@ -9,8 +9,7 @@ gpu.module @foo {
99
}
1010
}
1111

12-
// -----
13-
12+
// CHECK: gpu.module @bar attributes {gpu.binary = "CUBIN"}
1413
gpu.module @bar {
1514
// CHECK: func @kernel_a
1615
llvm.func @kernel_a()

mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,63 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
10-
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
9+
#include "mlir/Dialect/GPU/Passes.h"
10+
1111
#include "mlir/Pass/Pass.h"
12-
#include "mlir/Pass/PassManager.h"
13-
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
1412
#include "mlir/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.h"
1513
#include "mlir/Target/LLVMIR/Export.h"
1614
#include "llvm/Support/TargetSelect.h"
1715

1816
using namespace mlir;
1917

2018
#if MLIR_CUDA_CONVERSIONS_ENABLED
21-
static OwnedBlob compilePtxToCubinForTesting(const std::string &, Location,
22-
StringRef) {
23-
const char data[] = "CUBIN";
24-
return std::make_unique<std::vector<char>>(data, data + sizeof(data) - 1);
19+
namespace {
20+
class TestSerializeToCubinPass
21+
: public PassWrapper<TestSerializeToCubinPass, gpu::SerializeToBlobPass> {
22+
public:
23+
TestSerializeToCubinPass();
24+
25+
private:
26+
void getDependentDialects(DialectRegistry &registry) const override;
27+
28+
// Serializes PTX to CUBIN.
29+
std::unique_ptr<std::vector<char>>
30+
serializeISA(const std::string &isa) override;
31+
};
32+
} // namespace
33+
34+
TestSerializeToCubinPass::TestSerializeToCubinPass() {
35+
this->triple = "nvptx64-nvidia-cuda";
36+
this->chip = "sm_35";
37+
this->features = "+ptx60";
38+
}
39+
40+
void TestSerializeToCubinPass::getDependentDialects(
41+
DialectRegistry &registry) const {
42+
registerNVVMDialectTranslation(registry);
43+
gpu::SerializeToBlobPass::getDependentDialects(registry);
2544
}
2645

27-
static std::unique_ptr<llvm::Module>
28-
translateModuleToNVVMIR(Operation *m, llvm::LLVMContext &llvmContext,
29-
StringRef moduleName) {
30-
registerLLVMDialectTranslation(*m->getContext());
31-
registerNVVMDialectTranslation(*m->getContext());
32-
return translateModuleToLLVMIR(m, llvmContext, moduleName);
46+
std::unique_ptr<std::vector<char>>
47+
TestSerializeToCubinPass::serializeISA(const std::string &) {
48+
std::string data = "CUBIN";
49+
return std::make_unique<std::vector<char>>(data.begin(), data.end());
3350
}
3451

3552
namespace mlir {
3653
namespace test {
37-
void registerTestConvertGPUKernelToCubinPass() {
38-
PassPipelineRegistration<>(
39-
"test-kernel-to-cubin",
40-
"Convert all kernel functions to CUDA cubin blobs",
41-
[](OpPassManager &pm) {
54+
// Register test pass to serialize GPU module to a CUBIN binary annotation.
55+
void registerTestGpuSerializeToCubinPass() {
56+
PassRegistration<TestSerializeToCubinPass> registerSerializeToCubin(
57+
"test-gpu-to-cubin",
58+
"Lower GPU kernel function to CUBIN binary annotations", [] {
4259
// Initialize LLVM NVPTX backend.
4360
LLVMInitializeNVPTXTarget();
4461
LLVMInitializeNVPTXTargetInfo();
4562
LLVMInitializeNVPTXTargetMC();
4663
LLVMInitializeNVPTXAsmPrinter();
4764

48-
pm.addPass(createConvertGPUKernelToBlobPass(
49-
translateModuleToNVVMIR, compilePtxToCubinForTesting,
50-
"nvptx64-nvidia-cuda", "sm_35", "+ptx60", "nvvm.cubin"));
65+
return std::make_unique<TestSerializeToCubinPass>();
5166
});
5267
}
5368
} // namespace test

mlir/tools/mlir-opt/mlir-opt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void registerTestAliasAnalysisPass();
6464
void registerTestCallGraphPass();
6565
void registerTestConstantFold();
6666
void registerTestConvVectorization();
67-
void registerTestConvertGPUKernelToCubinPass();
67+
void registerTestGpuSerializeToCubinPass();
6868
void registerTestConvertGPUKernelToHsacoPass();
6969
void registerTestDecomposeCallGraphTypes();
7070
void registerTestDialect(DialectRegistry &);
@@ -136,7 +136,7 @@ void registerTestPasses() {
136136
test::registerTestCallGraphPass();
137137
test::registerTestConstantFold();
138138
#if MLIR_CUDA_CONVERSIONS_ENABLED
139-
test::registerTestConvertGPUKernelToCubinPass();
139+
test::registerTestGpuSerializeToCubinPass();
140140
#endif
141141
#if MLIR_ROCM_CONVERSIONS_ENABLED
142142
test::registerTestConvertGPUKernelToHsacoPass();

0 commit comments

Comments
 (0)