This commit is a further incremental step toward moving the whole mlir-vulkan-runner MLIR pass pipeline into mlir-opt (see #73457). The previous step was b225b3adf7b78387c9fcb97a3ff0e0a1e26eafe2, which moved all device passes prior to SPIR-V serialization into a new mlir-opt test pass, `-test-vulkan-runner-pipeline`. This commit changes how SPIR-V serialization is accomplished for Vulkan runner tests. Until now, this was done by the Vulkan-specific ConvertGpuLaunchFuncToVulkanLaunchFunc pass. With this commit, this responsibility is removed from that pass, and is instead done with the existing generic GpuModuleToBinaryPass. In addition, the SPIR-V serialization step is no longer done inside mlir-vulkan-runner, but rather inside mlir-opt (in the `-test-vulkan-runner-pipeline` pass). Both of these changes represent a greater alignment between mlir-vulkan-runner and the other GPU integration tests. Notably, the IR shapes produced by the mlir-opt pipelines for the Vulkan and SYCL runners are now much more similar, with both using a gpu.binary op for the serialized SPIR-V kernel. In order to enable this, this commit includes these supporting changes: - ConvertToSPIRVPass is enhanced to support producing the IR shape where a spirv.module is nested inside a gpu.module, since this is what GpuModuleToBinaryPass expects. - ConvertGPULaunchFuncToVulkanLaunchFunc is changed to remove its SPIR-V serialization functionality, and instead now extracts the SPIR-V from a gpu.binary operation (as produced by ConvertToSPIRVPass). - `-test-vulkan-runner-pipeline` now attaches SPIR-V target information required by GpuModuleToBinaryPass. - The WebGPU pass option, which had been removed from mlir-vulkan-runner in the previous commit in this series, is restored as an option to `-test-vulkan-runner-pipeline` instead, so that the WebGPU pass continues being inserted into the pipeline just before SPIR-V serialization.
72 lines
2.7 KiB
C++
72 lines
2.7 KiB
C++
//===------------------ TestVulkanRunnerPipeline.cpp --------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Implements a pipeline for use by mlir-vulkan-runner tests.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Conversion/ConvertToSPIRV/ConvertToSPIRVPass.h"
|
|
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
|
|
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
|
|
#include "mlir/Dialect/GPU/Transforms/Passes.h"
|
|
#include "mlir/Dialect/MemRef/Transforms/Passes.h"
|
|
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
|
|
#include "mlir/Dialect/SPIRV/Transforms/Passes.h"
|
|
#include "mlir/Pass/PassManager.h"
|
|
#include "mlir/Pass/PassOptions.h"
|
|
|
|
using namespace mlir;
|
|
|
|
namespace {
|
|
|
|
struct VulkanRunnerPipelineOptions
|
|
: PassPipelineOptions<VulkanRunnerPipelineOptions> {
|
|
Option<bool> spirvWebGPUPrepare{
|
|
*this, "spirv-webgpu-prepare",
|
|
llvm::cl::desc("Run MLIR transforms used when targetting WebGPU")};
|
|
};
|
|
|
|
void buildTestVulkanRunnerPipeline(OpPassManager &passManager,
|
|
const VulkanRunnerPipelineOptions &options) {
|
|
passManager.addPass(createGpuKernelOutliningPass());
|
|
passManager.addPass(memref::createFoldMemRefAliasOpsPass());
|
|
|
|
GpuSPIRVAttachTargetOptions attachTargetOptions{};
|
|
attachTargetOptions.spirvVersion = "v1.0";
|
|
attachTargetOptions.spirvCapabilities.push_back("Shader");
|
|
attachTargetOptions.spirvExtensions.push_back(
|
|
"SPV_KHR_storage_buffer_storage_class");
|
|
passManager.addPass(createGpuSPIRVAttachTarget(attachTargetOptions));
|
|
|
|
ConvertToSPIRVPassOptions convertToSPIRVOptions{};
|
|
convertToSPIRVOptions.convertGPUModules = true;
|
|
convertToSPIRVOptions.nestInGPUModule = true;
|
|
passManager.addPass(createConvertToSPIRVPass(convertToSPIRVOptions));
|
|
|
|
OpPassManager &spirvModulePM =
|
|
passManager.nest<gpu::GPUModuleOp>().nest<spirv::ModuleOp>();
|
|
spirvModulePM.addPass(spirv::createSPIRVLowerABIAttributesPass());
|
|
spirvModulePM.addPass(spirv::createSPIRVUpdateVCEPass());
|
|
if (options.spirvWebGPUPrepare)
|
|
spirvModulePM.addPass(spirv::createSPIRVWebGPUPreparePass());
|
|
|
|
passManager.addPass(createGpuModuleToBinaryPass());
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace mlir::test {
|
|
void registerTestVulkanRunnerPipeline() {
|
|
PassPipelineRegistration<VulkanRunnerPipelineOptions>(
|
|
"test-vulkan-runner-pipeline",
|
|
"Runs a series of passes for lowering GPU-dialect MLIR to "
|
|
"SPIR-V-dialect MLIR intended for mlir-vulkan-runner.",
|
|
buildTestVulkanRunnerPipeline);
|
|
}
|
|
} // namespace mlir::test
|