From e8f5c072f6df444f6baea91a3533509cf4a3779f Mon Sep 17 00:00:00 2001 From: River Riddle Date: Sun, 22 Mar 2020 03:13:40 -0700 Subject: [PATCH] [mlir] Move the testing pass for GpuKernelToCubin to the test/ directory Summary: This removes the static pass registration, and also cleans up some lingering technical debt. Differential Revision: https://reviews.llvm.org/D76554 --- mlir/include/mlir/InitAllPasses.h | 4 --- .../GPUToCUDA/ConvertKernelFuncToCubin.cpp | 17 +--------- mlir/test/lib/Transforms/CMakeLists.txt | 2 ++ .../TestConvertGPUKernelToCubin.cpp | 34 +++++++++++++++++++ mlir/tools/mlir-opt/mlir-opt.cpp | 4 +++ 5 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp diff --git a/mlir/include/mlir/InitAllPasses.h b/mlir/include/mlir/InitAllPasses.h index 711b88412a6d..2de889841849 100644 --- a/mlir/include/mlir/InitAllPasses.h +++ b/mlir/include/mlir/InitAllPasses.h @@ -97,10 +97,6 @@ inline void registerAllPasses() { // 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 index 140026eaf643..1640978b3a18 100644 --- a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp +++ b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp @@ -49,8 +49,7 @@ static constexpr const char *kCubinAnnotation = "nvvm.cubin"; class GpuKernelToCubinPass : public OperationPass { public: - GpuKernelToCubinPass( - CubinGenerator cubinGenerator = compilePtxToCubinForTesting) + GpuKernelToCubinPass(CubinGenerator cubinGenerator) : cubinGenerator(cubinGenerator) {} void runOnOperation() override { @@ -76,9 +75,6 @@ public: } private: - static OwnedCubin compilePtxToCubinForTesting(const std::string &ptx, - Location, StringRef); - std::string translateModuleToPtx(llvm::Module &module, llvm::TargetMachine &target_machine); @@ -112,13 +108,6 @@ std::string GpuKernelToCubinPass::translateModuleToPtx( 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 @@ std::unique_ptr> 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 index e90099203b43..9340e89a3b90 100644 --- a/mlir/test/lib/Transforms/CMakeLists.txt +++ b/mlir/test/lib/Transforms/CMakeLists.txt @@ -2,6 +2,7 @@ add_llvm_library(MLIRTestTransforms TestAllReduceLowering.cpp TestCallGraph.cpp TestConstantFold.cpp + TestConvertGPUKernelToCubin.cpp TestLoopFusion.cpp TestGpuMemoryPromotion.cpp TestGpuParallelLoopMapping.cpp @@ -39,6 +40,7 @@ target_link_libraries(MLIRTestTransforms MLIRAnalysis MLIREDSC MLIRGPU + MLIRGPUtoCUDATransforms MLIRLinalgOps MLIRLinalgTransforms MLIRLoopOps diff --git a/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp b/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp new file mode 100644 index 000000000000..2a2259547b37 --- /dev/null +++ b/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp @@ -0,0 +1,34 @@ +//===- 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 + +#if MLIR_CUDA_CONVERSIONS_ENABLED +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 +#endif diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp index 25650709b1a1..ff0f49f987b6 100644 --- a/mlir/tools/mlir-opt/mlir-opt.cpp +++ b/mlir/tools/mlir-opt/mlir-opt.cpp @@ -41,6 +41,7 @@ void registerTestAffineDataCopyPass(); void registerTestAllReduceLoweringPass(); void registerTestCallGraphPass(); void registerTestConstantFold(); +void registerTestConvertGPUKernelToCubinPass(); void registerTestFunc(); void registerTestGpuMemoryPromotionPass(); void registerTestLinalgTransforms(); @@ -96,6 +97,9 @@ void registerTestPasses() { registerTestAllReduceLoweringPass(); registerTestCallGraphPass(); registerTestConstantFold(); +#if MLIR_CUDA_CONVERSIONS_ENABLED + registerTestConvertGPUKernelToCubinPass(); +#endif registerTestFunc(); registerTestGpuMemoryPromotionPass(); registerTestLinalgTransforms();