Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRVPass.cpp
Show All 27 Lines | |||||
/// inside gpu.module ops. i.e., the function that are referenced in | /// inside gpu.module ops. i.e., the function that are referenced in | ||||
/// gpu.launch_func ops. For each such function | /// gpu.launch_func ops. For each such function | ||||
/// | /// | ||||
/// 1) Create a spirv::ModuleOp, and clone the function into spirv::ModuleOp | /// 1) Create a spirv::ModuleOp, and clone the function into spirv::ModuleOp | ||||
/// (the original function is still needed by the gpu::LaunchKernelOp, so cannot | /// (the original function is still needed by the gpu::LaunchKernelOp, so cannot | ||||
/// replace it). | /// replace it). | ||||
/// | /// | ||||
/// 2) Lower the body of the spirv::ModuleOp. | /// 2) Lower the body of the spirv::ModuleOp. | ||||
struct GPUToSPIRVPass : public ModulePass<GPUToSPIRVPass> { | struct GPUToSPIRVPass : public OperationPass<GPUToSPIRVPass, ModuleOp> { | ||||
/// Include the generated pass utilities. | /// Include the generated pass utilities. | ||||
#define GEN_PASS_ConvertGpuToSPIRV | #define GEN_PASS_ConvertGpuToSPIRV | ||||
#include "mlir/Conversion/Passes.h.inc" | #include "mlir/Conversion/Passes.h.inc" | ||||
void runOnModule() override; | void runOnOperation() override; | ||||
}; | }; | ||||
} // namespace | } // namespace | ||||
void GPUToSPIRVPass::runOnModule() { | void GPUToSPIRVPass::runOnOperation() { | ||||
MLIRContext *context = &getContext(); | MLIRContext *context = &getContext(); | ||||
ModuleOp module = getModule(); | ModuleOp module = getOperation(); | ||||
SmallVector<Operation *, 1> kernelModules; | SmallVector<Operation *, 1> kernelModules; | ||||
OpBuilder builder(context); | OpBuilder builder(context); | ||||
module.walk([&builder, &kernelModules](gpu::GPUModuleOp moduleOp) { | module.walk([&builder, &kernelModules](gpu::GPUModuleOp moduleOp) { | ||||
// For each kernel module (should be only 1 for now, but that is not a | // For each kernel module (should be only 1 for now, but that is not a | ||||
// requirement here), clone the module for conversion because the | // requirement here), clone the module for conversion because the | ||||
// gpu.launch function still needs the kernel module. | // gpu.launch function still needs the kernel module. | ||||
builder.setInsertionPoint(moduleOp.getOperation()); | builder.setInsertionPoint(moduleOp.getOperation()); | ||||
Show All 21 Lines |