Adds a new mlir-opt test-only pass, -test-vulkan-runner-pipeline, which runs a set of passes needed for mlir-vulkan-runner, and removes them from the runner. The tests are changed to invoke mlir-opt with this flag before invoking the runner. The passes moved are ones concerned with lowering of the device code prior to serialization to SPIR-V. This is an incremental step towards moving the entire pipeline to mlir-opt, to align with other runners (see #73457).
85 lines
3.6 KiB
C++
85 lines
3.6 KiB
C++
//===- mlir-vulkan-runner.cpp - MLIR Vulkan Execution Driver --------------===//
|
|
//
|
|
// 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 is a command line utility that executes an MLIR file on the Vulkan by
|
|
// translating MLIR GPU module to SPIR-V and host part to LLVM IR before
|
|
// JIT-compiling and executing the latter.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
|
|
#include "mlir/Conversion/GPUToVulkan/ConvertGPUToVulkanPass.h"
|
|
#include "mlir/Conversion/LLVMCommon/LoweringOptions.h"
|
|
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
|
|
#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h"
|
|
#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h"
|
|
#include "mlir/Dialect/Arith/IR/Arith.h"
|
|
#include "mlir/Dialect/Func/IR/FuncOps.h"
|
|
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
|
|
#include "mlir/Dialect/GPU/Transforms/Passes.h"
|
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
|
#include "mlir/Dialect/LLVMIR/Transforms/RequestCWrappers.h"
|
|
#include "mlir/Dialect/MemRef/IR/MemRef.h"
|
|
#include "mlir/Dialect/MemRef/Transforms/Passes.h"
|
|
#include "mlir/Dialect/SCF/IR/SCF.h"
|
|
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
|
|
#include "mlir/Dialect/Vector/IR/VectorOps.h"
|
|
#include "mlir/ExecutionEngine/JitRunner.h"
|
|
#include "mlir/Pass/Pass.h"
|
|
#include "mlir/Pass/PassManager.h"
|
|
#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h"
|
|
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
|
|
#include "llvm/Support/InitLLVM.h"
|
|
#include "llvm/Support/TargetSelect.h"
|
|
|
|
using namespace mlir;
|
|
|
|
static LogicalResult runMLIRPasses(Operation *op, JitRunnerOptions &) {
|
|
auto module = dyn_cast<ModuleOp>(op);
|
|
if (!module)
|
|
return op->emitOpError("expected a 'builtin.module' op");
|
|
PassManager passManager(module.getContext());
|
|
if (failed(applyPassManagerCLOptions(passManager)))
|
|
return failure();
|
|
|
|
passManager.addPass(createConvertGpuLaunchFuncToVulkanLaunchFuncPass());
|
|
passManager.addPass(createFinalizeMemRefToLLVMConversionPass());
|
|
passManager.addPass(createConvertVectorToLLVMPass());
|
|
passManager.nest<func::FuncOp>().addPass(LLVM::createRequestCWrappersPass());
|
|
ConvertFuncToLLVMPassOptions funcToLLVMOptions{};
|
|
funcToLLVMOptions.indexBitwidth =
|
|
DataLayout(module).getTypeSizeInBits(IndexType::get(module.getContext()));
|
|
passManager.addPass(createConvertFuncToLLVMPass(funcToLLVMOptions));
|
|
passManager.addPass(createReconcileUnrealizedCastsPass());
|
|
passManager.addPass(createConvertVulkanLaunchFuncToVulkanCallsPass());
|
|
|
|
return passManager.run(module);
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
llvm::llvm_shutdown_obj x;
|
|
registerPassManagerCLOptions();
|
|
|
|
llvm::InitLLVM y(argc, argv);
|
|
llvm::InitializeNativeTarget();
|
|
llvm::InitializeNativeTargetAsmPrinter();
|
|
|
|
mlir::JitRunnerConfig jitRunnerConfig;
|
|
jitRunnerConfig.mlirTransformer = runMLIRPasses;
|
|
|
|
mlir::DialectRegistry registry;
|
|
registry.insert<mlir::arith::ArithDialect, mlir::LLVM::LLVMDialect,
|
|
mlir::gpu::GPUDialect, mlir::spirv::SPIRVDialect,
|
|
mlir::scf::SCFDialect, mlir::func::FuncDialect,
|
|
mlir::memref::MemRefDialect, mlir::vector::VectorDialect>();
|
|
mlir::registerBuiltinDialectTranslation(registry);
|
|
mlir::registerLLVMDialectTranslation(registry);
|
|
|
|
return mlir::JitRunnerMain(argc, argv, registry, jitRunnerConfig);
|
|
}
|