1 //===- GPUCommonPass.h - MLIR GPU runtime support -------------------------===// 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 #ifndef MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_ 9 #define MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_ 10 11 #include "mlir/Support/LLVM.h" 12 #include "llvm/ADT/StringRef.h" 13 #include <functional> 14 #include <vector> 15 16 namespace llvm { 17 class LLVMContext; 18 class Module; 19 } // namespace llvm 20 21 namespace mlir { 22 23 class LLVMTypeConverter; 24 class Location; 25 struct LogicalResult; 26 class ModuleOp; 27 class Operation; 28 class RewritePatternSet; 29 30 template <typename T> 31 class OperationPass; 32 33 namespace gpu { 34 class GPUModuleOp; 35 } // namespace gpu 36 37 namespace LLVM { 38 class LLVMDialect; 39 } // namespace LLVM 40 41 using OwnedBlob = std::unique_ptr<std::vector<char>>; 42 using BlobGenerator = 43 std::function<OwnedBlob(const std::string &, Location, StringRef)>; 44 using LoweringCallback = std::function<std::unique_ptr<llvm::Module>( 45 Operation *, llvm::LLVMContext &, StringRef)>; 46 47 /// Creates a pass to convert a GPU operations into a sequence of GPU runtime 48 /// calls. 49 /// 50 /// This pass does not generate code to call GPU runtime APIs directly but 51 /// instead uses a small wrapper library that exports a stable and conveniently 52 /// typed ABI on top of GPU runtimes such as CUDA or ROCm (HIP). 53 std::unique_ptr<OperationPass<ModuleOp>> createGpuToLLVMConversionPass(); 54 55 /// Collect a set of patterns to convert from the GPU dialect to LLVM and 56 /// populate converter for gpu types. 57 void populateGpuToLLVMConversionPatterns(LLVMTypeConverter &converter, 58 RewritePatternSet &patterns, 59 StringRef gpuBinaryAnnotation = {}); 60 61 } // namespace mlir 62 63 #endif // MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_ 64