Skip to content

Commit 98d5d34

Browse files
authored
[MLIR][GPU-LLVM] Define -convert-gpu-to-llvm-spv pass (#90972)
Define pass for GPU to LLVM conversion for SPIR-V backend tool ingest. Supported operations: - `gpu.block_id` - `gpu.global_id` - `gpu.block_dim` - `gpu.thread_id` - `gpu.grid_dim` - `gpu.barrier` - `gpu.shuffle` --------- Signed-off-by: Victor Perez <[email protected]>
1 parent 85ea1aa commit 98d5d34

File tree

7 files changed

+597
-0
lines changed

7 files changed

+597
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===- GPUToLLVMSPVPass.h - Convert GPU kernel to LLVM operations *- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_CONVERSION_GPUTOLLVMSPV_GPUTOLLVMSPVPASS_H_
10+
#define MLIR_CONVERSION_GPUTOLLVMSPV_GPUTOLLVMSPVPASS_H_
11+
12+
#include <memory>
13+
14+
namespace mlir {
15+
class DialectRegistry;
16+
class LLVMTypeConverter;
17+
class RewritePatternSet;
18+
class Pass;
19+
20+
#define GEN_PASS_DECL_CONVERTGPUOPSTOLLVMSPVOPS
21+
#include "mlir/Conversion/Passes.h.inc"
22+
23+
void populateGpuToLLVMSPVConversionPatterns(LLVMTypeConverter &converter,
24+
RewritePatternSet &patterns);
25+
} // namespace mlir
26+
27+
#endif // MLIR_CONVERSION_GPUTOLLVMSPV_GPUTOLLVMSPVPASS_H_

mlir/include/mlir/Conversion/Passes.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h"
3535
#include "mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h"
3636
#include "mlir/Conversion/GPUCommon/GPUCommonPass.h"
37+
#include "mlir/Conversion/GPUToLLVMSPV/GPUToLLVMSPVPass.h"
3738
#include "mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h"
3839
#include "mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h"
3940
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"

mlir/include/mlir/Conversion/Passes.td

+18
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,24 @@ def LowerHostCodeToLLVMPass : Pass<"lower-host-to-llvm", "ModuleOp"> {
508508
let dependentDialects = ["LLVM::LLVMDialect"];
509509
}
510510

511+
//===----------------------------------------------------------------------===//
512+
// GPUToLLVMSPV
513+
//===----------------------------------------------------------------------===//
514+
515+
def ConvertGpuOpsToLLVMSPVOps : Pass<"convert-gpu-to-llvm-spv", "gpu::GPUModuleOp"> {
516+
let summary =
517+
"Generate LLVM operations to be ingested by a SPIR-V backend for gpu operations";
518+
let dependentDialects = [
519+
"LLVM::LLVMDialect",
520+
"spirv::SPIRVDialect",
521+
];
522+
let options = [
523+
Option<"indexBitwidth", "index-bitwidth", "unsigned",
524+
/*default=kDeriveIndexBitwidthFromDataLayout*/"0",
525+
"Bitwidth of the index type, 0 to use size of machine word">,
526+
];
527+
}
528+
511529
//===----------------------------------------------------------------------===//
512530
// GPUToNVVM
513531
//===----------------------------------------------------------------------===//

mlir/lib/Conversion/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ add_subdirectory(FuncToEmitC)
2323
add_subdirectory(FuncToLLVM)
2424
add_subdirectory(FuncToSPIRV)
2525
add_subdirectory(GPUCommon)
26+
add_subdirectory(GPUToLLVMSPV)
2627
add_subdirectory(GPUToNVVM)
2728
add_subdirectory(GPUToROCDL)
2829
add_subdirectory(GPUToSPIRV)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
add_mlir_conversion_library(MLIRGPUToLLVMSPV
2+
GPUToLLVMSPV.cpp
3+
4+
DEPENDS
5+
MLIRConversionPassIncGen
6+
7+
LINK_LIBS PUBLIC
8+
MLIRGPUDialect
9+
MLIRLLVMCommonConversion
10+
MLIRLLVMDialect
11+
MLIRSPIRVDialect
12+
)

0 commit comments

Comments
 (0)