• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- TestConvertGPUKernelToCubin.cpp - Test gpu kernel cubin lowering ---===//
2 //
3 // Part of the LLVM Project, 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 #include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
10 #include "mlir/Pass/Pass.h"
11 #include "mlir/Pass/PassManager.h"
12 #include "mlir/Target/NVVMIR.h"
13 #include "llvm/Support/TargetSelect.h"
14 
15 using namespace mlir;
16 
17 #if MLIR_CUDA_CONVERSIONS_ENABLED
compilePtxToCubinForTesting(const std::string &,Location,StringRef)18 static OwnedBlob compilePtxToCubinForTesting(const std::string &, Location,
19                                              StringRef) {
20   const char data[] = "CUBIN";
21   return std::make_unique<std::vector<char>>(data, data + sizeof(data) - 1);
22 }
23 
24 namespace mlir {
25 namespace test {
registerTestConvertGPUKernelToCubinPass()26 void registerTestConvertGPUKernelToCubinPass() {
27   PassPipelineRegistration<>(
28       "test-kernel-to-cubin",
29       "Convert all kernel functions to CUDA cubin blobs",
30       [](OpPassManager &pm) {
31         // Initialize LLVM NVPTX backend.
32         LLVMInitializeNVPTXTarget();
33         LLVMInitializeNVPTXTargetInfo();
34         LLVMInitializeNVPTXTargetMC();
35         LLVMInitializeNVPTXAsmPrinter();
36 
37         pm.addPass(createConvertGPUKernelToBlobPass(
38             translateModuleToNVVMIR, compilePtxToCubinForTesting,
39             "nvptx64-nvidia-cuda", "sm_35", "+ptx60", "nvvm.cubin"));
40       });
41 }
42 } // namespace test
43 } // namespace mlir
44 #endif
45