MLIR 24.0.0git
OpenACCUtilsGPU.h
Go to the documentation of this file.
1//===- OpenACCUtilsGPU.h - OpenACC GPU Utilities -----------------*- 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// This file defines utility functions for OpenACC that depend on the GPU
10// dialect.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_DIALECT_OPENACC_OPENACCUTILSGPU_H_
15#define MLIR_DIALECT_OPENACC_OPENACCUTILSGPU_H_
16
18#include "mlir/IR/BuiltinOps.h"
19#include "mlir/IR/Value.h"
20#include "llvm/ADT/DenseMap.h"
21#include <optional>
22
23namespace mlir {
24namespace acc {
25
26/// Default GPU module name used by OpenACC.
27constexpr llvm::StringLiteral kDefaultGPUModuleName = "acc_gpu_module";
28
29/// Get or create a GPU module in the given module.
30///
31/// If a GPU module with the specified name already exists, it is returned.
32/// If `create` is true and no GPU module exists, one is created.
33/// If `create` is false and no GPU module exists, std::nullopt is returned.
34///
35/// \param mod The module to search or create the GPU module in.
36/// \param create If true (default), create the GPU module if it doesn't exist.
37/// \param name The name for the GPU module. If empty, uses
38/// kDefaultGPUModuleName.
39/// \return The GPU module if found or created, std::nullopt otherwise.
40std::optional<gpu::GPUModuleOp>
41getOrCreateGPUModule(ModuleOp mod, bool create = true,
42 llvm::StringRef name = kDefaultGPUModuleName);
43
44/// Return the launch dimension for \p processor from \p launch, or from
45/// \p dimensionOps when \p launch is null.
46Value getGPUSize(gpu::Processor processor, gpu::LaunchOp launch,
47 const llvm::DenseMap<gpu::Processor, Value> &dimensionOps);
48
49/// Return the thread/block index for \p processor from \p launch, or from
50/// \p indexOps when \p launch is null.
51Value getGPUThreadId(gpu::Processor processor, gpu::LaunchOp launch,
53
54} // namespace acc
55} // namespace mlir
56
57#endif // MLIR_DIALECT_OPENACC_OPENACCUTILSGPU_H_
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Value getGPUSize(gpu::Processor processor, gpu::LaunchOp launch, const llvm::DenseMap< gpu::Processor, Value > &dimensionOps)
Return the launch dimension for processor from launch, or from dimensionOps when launch is null.
std::optional< gpu::GPUModuleOp > getOrCreateGPUModule(ModuleOp mod, bool create=true, llvm::StringRef name=kDefaultGPUModuleName)
Get or create a GPU module in the given module.
Value getGPUThreadId(gpu::Processor processor, gpu::LaunchOp launch, const llvm::DenseMap< gpu::Processor, Value > &indexOps)
Return the thread/block index for processor from launch, or from indexOps when launch is null.
constexpr llvm::StringLiteral kDefaultGPUModuleName
Default GPU module name used by OpenACC.
Include the generated interface declarations.