From 74ffe8dc590c29f1895e7b9cabf13944ffef16cb Mon Sep 17 00:00:00 2001 From: Christian Sigg Date: Fri, 19 Mar 2021 09:27:55 +0100 Subject: [PATCH] [mlir] Remove ConvertKernelFuncToBlob All users have been converted to gpu::SerializeToBlobPass. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D98928 --- .../mlir/Conversion/GPUCommon/GPUCommonPass.h | 31 -------- mlir/lib/Conversion/GPUCommon/CMakeLists.txt | 1 - .../GPUCommon/ConvertKernelFuncToBlob.cpp | 93 ---------------------- 3 files changed, 125 deletions(-) delete mode 100644 mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp diff --git a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h index fb5e820..173d8fe 100644 --- a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h +++ b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h @@ -60,37 +60,6 @@ createGpuToLLVMConversionPass(StringRef gpuBinaryAnnotation = {}); void populateGpuToLLVMConversionPatterns(LLVMTypeConverter &converter, OwningRewritePatternList &patterns, StringRef gpuBinaryAnnotation = {}); - -/// Creates a pass to convert kernel functions into GPU target object blobs. -/// -/// This transformation takes the body of each function that is annotated with -/// the 'gpu.kernel' attribute, copies it to a new LLVM module, compiles the -/// module with help of the GPU backend to target object and then invokes -/// the provided blobGenerator to produce a binary blob. Such blob is then -/// attached as a string attribute to the kernel function. -/// -/// Following callbacks are to be provided by user: -/// - loweringCallback : lower the module to an LLVM module. -/// - blobGenerator : build a blob executable on target GPU. -/// -/// Information wrt LLVM backend are to be supplied by user: -/// - triple : target triple to be used. -/// - targetChip : mcpu to be used. -/// - features : target-specific features to be used. -/// -/// Information about result attribute is to be specified by user: -/// - gpuBinaryAnnotation : the name of the attribute which contains the blob. -/// -/// After the transformation, the body of the kernel function is removed (i.e., -/// it is turned into a declaration). -/// -/// A non-empty gpuBinaryAnnotation overrides the pass' command line option. -std::unique_ptr> -createConvertGPUKernelToBlobPass(LoweringCallback loweringCallback, - BlobGenerator blobGenerator, StringRef triple, - StringRef targetChip, StringRef features, - StringRef gpuBinaryAnnotation = {}); - } // namespace mlir #endif // MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_ diff --git a/mlir/lib/Conversion/GPUCommon/CMakeLists.txt b/mlir/lib/Conversion/GPUCommon/CMakeLists.txt index d9f6867..04ff2a9 100644 --- a/mlir/lib/Conversion/GPUCommon/CMakeLists.txt +++ b/mlir/lib/Conversion/GPUCommon/CMakeLists.txt @@ -16,7 +16,6 @@ endif() add_mlir_conversion_library(MLIRGPUToGPURuntimeTransforms ConvertLaunchFuncToRuntimeCalls.cpp - ConvertKernelFuncToBlob.cpp GPUOpsLowering.cpp DEPENDS diff --git a/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp b/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp deleted file mode 100644 index e8f9a7a..0000000 --- a/mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp +++ /dev/null @@ -1,93 +0,0 @@ -//===- ConvertKernelFuncToBlob.cpp - MLIR GPU lowering passes -------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// -// -// This file implements a pass to convert gpu kernel functions into a -// corresponding binary blob that can be executed on a GPU. Currently -// only translates the function itself but no dependencies. -// -//===----------------------------------------------------------------------===// - -#include "mlir/Conversion/GPUCommon/GPUCommonPass.h" - -#include "mlir/Dialect/GPU/GPUDialect.h" -#include "mlir/Dialect/GPU/Passes.h" -#include "mlir/Dialect/LLVMIR/LLVMDialect.h" -#include "mlir/IR/Attributes.h" -#include "mlir/IR/Builders.h" -#include "mlir/IR/BuiltinOps.h" -#include "mlir/Pass/Pass.h" -#include "mlir/Pass/PassRegistry.h" -#include "mlir/Support/LogicalResult.h" - -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/Twine.h" -#include "llvm/Support/Error.h" -#include "llvm/Support/Mutex.h" -#include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/TargetSelect.h" - -using namespace mlir; - -namespace { - -/// A pass converting tagged kernel modules to a blob with target instructions. -/// -/// If tagged as a kernel module, each contained function is translated to -/// user-specified IR. A user provided BlobGenerator then compiles the IR to -/// GPU binary code, which is then attached as an attribute to the function. -/// The function body is erased. -class GpuKernelToBlobPass - : public PassWrapper { -public: - GpuKernelToBlobPass(LoweringCallback loweringCallback, - BlobGenerator blobGenerator, StringRef triple, - StringRef targetChip, StringRef features, - StringRef gpuBinaryAnnotation) - : loweringCallback(loweringCallback), blobGenerator(blobGenerator) { - if (!triple.empty()) - this->triple = triple.str(); - if (!targetChip.empty()) - this->chip = targetChip.str(); - if (!features.empty()) - this->features = features.str(); - if (!gpuBinaryAnnotation.empty()) - this->gpuBinaryAnnotation = gpuBinaryAnnotation.str(); - } - -private: - // Translates the 'getOperation()' result to an LLVM module. - // Note: when this class is removed, this function no longer needs to be - // virtual. - std::unique_ptr - translateToLLVMIR(llvm::LLVMContext &llvmContext) override { - return loweringCallback(getOperation(), llvmContext, "LLVMDialectModule"); - } - - // Serializes the target ISA to binary form. - std::unique_ptr> - serializeISA(const std::string &isa) override { - return blobGenerator(isa, getOperation().getLoc(), - getOperation().getName()); - } - - LoweringCallback loweringCallback; - BlobGenerator blobGenerator; -}; - -} // anonymous namespace - -std::unique_ptr> -mlir::createConvertGPUKernelToBlobPass(LoweringCallback loweringCallback, - BlobGenerator blobGenerator, - StringRef triple, StringRef targetChip, - StringRef features, - StringRef gpuBinaryAnnotation) { - return std::make_unique(loweringCallback, blobGenerator, - triple, targetChip, features, - gpuBinaryAnnotation); -} -- 2.7.4