xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/xla/mlir_hlo/include/mlir-hlo/Transforms/gpu_passes.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef MLIR_HLO_TRANSFORMS_GPU_PASSES_H
17 #define MLIR_HLO_TRANSFORMS_GPU_PASSES_H
18 
19 #include <memory>
20 
21 #include "mlir/Pass/Pass.h"
22 
23 namespace mlir {
24 class ModuleOp;
25 class PassManager;
26 namespace gpu {
27 class GPUModuleOp;
28 }  // namespace gpu
29 
30 // Create a pass which lowers a subset of lmhlo.fusion ops to gpu.launch_func
31 // plus a gpu.module containing the kernel.
32 std::unique_ptr<OperationPass<mlir::ModuleOp>> createGpuFusionRewritePass();
33 
34 // Returns array of bool attributes. The value of each element specifies whether
35 // the corresponding operand is written. This attribute is attached to
36 // 'gpu.launc_func' ops during the fusion rewrite pass above.
37 ArrayAttr getWrittenOperandsAttribute(Operation* op);
38 
39 /// Pass that transforms gpu modules in standard dialect to NNVM.
40 std::unique_ptr<OperationPass<mlir::gpu::GPUModuleOp>>
41 createGpuKernelToNvvmPass();
42 
43 /// Pass that transforms gpu modules in standard dialect to ROCDL.
44 std::unique_ptr<OperationPass<mlir::gpu::GPUModuleOp>>
45 createGpuKernelToRocdlPass();
46 
47 /// Creates a pipeline that converts operations in HLO dialect to GPU kernels
48 /// written in a combination of LLVM and NVVM dialects, and appends the pipeline
49 /// to `pm`. `tileSizes` and `unrollFactors` are used to control loop tiling
50 /// in `createTileLoopsPass`.
51 void createHloToGpuPipeline(OpPassManager& pm, ArrayRef<int64_t> tileSizes,
52                             ArrayRef<int64_t> unrollFactors);
53 
54 }  // namespace mlir
55 
56 #endif  // MLIR_HLO_TRANSFORMS_GPU_PASSES_H
57