|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 |
| -#include "mlir/Conversion/GPUCommon/GPUCommonPass.h" |
10 |
| -#include "mlir/Dialect/LLVMIR/NVVMDialect.h" |
| 9 | +#include "mlir/Dialect/GPU/Passes.h" |
| 10 | + |
11 | 11 | #include "mlir/Pass/Pass.h"
|
12 |
| -#include "mlir/Pass/PassManager.h" |
13 |
| -#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" |
14 | 12 | #include "mlir/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.h"
|
15 | 13 | #include "mlir/Target/LLVMIR/Export.h"
|
16 | 14 | #include "llvm/Support/TargetSelect.h"
|
17 | 15 |
|
18 | 16 | using namespace mlir;
|
19 | 17 |
|
20 | 18 | #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 ®istry) 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 ®istry) const { |
| 42 | + registerNVVMDialectTranslation(registry); |
| 43 | + gpu::SerializeToBlobPass::getDependentDialects(registry); |
25 | 44 | }
|
26 | 45 |
|
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()); |
33 | 50 | }
|
34 | 51 |
|
35 | 52 | namespace mlir {
|
36 | 53 | 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", [] { |
42 | 59 | // Initialize LLVM NVPTX backend.
|
43 | 60 | LLVMInitializeNVPTXTarget();
|
44 | 61 | LLVMInitializeNVPTXTargetInfo();
|
45 | 62 | LLVMInitializeNVPTXTargetMC();
|
46 | 63 | LLVMInitializeNVPTXAsmPrinter();
|
47 | 64 |
|
48 |
| - pm.addPass(createConvertGPUKernelToBlobPass( |
49 |
| - translateModuleToNVVMIR, compilePtxToCubinForTesting, |
50 |
| - "nvptx64-nvidia-cuda", "sm_35", "+ptx60", "nvvm.cubin")); |
| 65 | + return std::make_unique<TestSerializeToCubinPass>(); |
51 | 66 | });
|
52 | 67 | }
|
53 | 68 | } // namespace test
|
|
0 commit comments