diff --git a/mlir/include/mlir/InitAllPasses.h b/mlir/include/mlir/InitAllPasses.h --- a/mlir/include/mlir/InitAllPasses.h +++ b/mlir/include/mlir/InitAllPasses.h @@ -91,10 +91,6 @@ // CUDA createConvertGpuLaunchFuncToCudaCallsPass(); -#if MLIR_CUDA_CONVERSIONS_ENABLED - createConvertGPUKernelToCubinPass( - [](const std::string &, Location, StringRef) { return nullptr; }); -#endif createLowerGpuOpsToNVVMOpsPass(); // Linalg diff --git a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp --- a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp +++ b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp @@ -49,8 +49,7 @@ class GpuKernelToCubinPass : public OperationPass { public: - GpuKernelToCubinPass( - CubinGenerator cubinGenerator = compilePtxToCubinForTesting) + GpuKernelToCubinPass(CubinGenerator cubinGenerator) : cubinGenerator(cubinGenerator) {} void runOnOperation() override { @@ -76,9 +75,6 @@ } private: - static OwnedCubin compilePtxToCubinForTesting(const std::string &ptx, - Location, StringRef); - std::string translateModuleToPtx(llvm::Module &module, llvm::TargetMachine &target_machine); @@ -112,13 +108,6 @@ return ptx; } -OwnedCubin -GpuKernelToCubinPass::compilePtxToCubinForTesting(const std::string &ptx, - Location, StringRef) { - const char data[] = "CUBIN"; - return std::make_unique>(data, data + sizeof(data) - 1); -} - OwnedCubin GpuKernelToCubinPass::convertModuleToCubin(llvm::Module &llvmModule, Location loc, StringRef name) { @@ -158,7 +147,3 @@ mlir::createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator) { return std::make_unique(cubinGenerator); } - -static PassRegistration - pass("test-kernel-to-cubin", - "Convert all kernel functions to CUDA cubin blobs"); diff --git a/mlir/test/lib/Transforms/CMakeLists.txt b/mlir/test/lib/Transforms/CMakeLists.txt --- a/mlir/test/lib/Transforms/CMakeLists.txt +++ b/mlir/test/lib/Transforms/CMakeLists.txt @@ -3,6 +3,7 @@ TestAllReduceLowering.cpp TestCallGraph.cpp TestConstantFold.cpp + TestConvertGPUKernelToCubin.cpp TestLoopFusion.cpp TestGpuMemoryPromotion.cpp TestGpuParallelLoopMapping.cpp diff --git a/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp b/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp new file mode 100644 --- /dev/null +++ b/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp @@ -0,0 +1,32 @@ +//===- TestConvertGPUKernelToCubin.cpp - Test gpu kernel cubin lowering ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h" +#include "mlir/Pass/Pass.h" +#include "mlir/Pass/PassManager.h" + +using namespace mlir; + +namespace { +static OwnedCubin compilePtxToCubinForTesting(const std::string &, Location, + StringRef) { + const char data[] = "CUBIN"; + return std::make_unique>(data, data + sizeof(data) - 1); +} +} // end anonymous namespace + +namespace mlir { +void registerTestConvertGPUKernelToCubinPass() { + PassPipelineRegistration<>("test-kernel-to-cubin", + "Convert all kernel functions to CUDA cubin blobs", + [](OpPassManager &pm) { + pm.addPass(createConvertGPUKernelToCubinPass( + compilePtxToCubinForTesting)); + }); +} +} // namespace mlir diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp --- a/mlir/tools/mlir-opt/mlir-opt.cpp +++ b/mlir/tools/mlir-opt/mlir-opt.cpp @@ -41,6 +41,7 @@ void registerTestAllReduceLoweringPass(); void registerTestCallGraphPass(); void registerTestConstantFold(); +void registerTestConvertGPUKernelToCubinPass(); void registerTestFunc(); void registerTestGpuMemoryPromotionPass(); void registerTestLinalgTransforms(); @@ -96,6 +97,9 @@ registerTestAllReduceLoweringPass(); registerTestCallGraphPass(); registerTestConstantFold(); +#if MLIR_CUDA_CONVERSIONS_ENABLED + registerTestConvertGPUKernelToCubinPass(); +#endif registerTestFunc(); registerTestGpuMemoryPromotionPass(); registerTestLinalgTransforms();