FLANG
Cuda.h
1//===-- Lower/Cuda.h -- Cuda Fortran 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// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef FORTRAN_LOWER_CUDA_H
14#define FORTRAN_LOWER_CUDA_H
15
16#include "flang/Optimizer/Builder/FIRBuilder.h"
17#include "flang/Optimizer/Dialect/CUF/CUFOps.h"
18#include "flang/Semantics/tools.h"
19#include "mlir/Dialect/Func/IR/FuncOps.h"
20#include "mlir/Dialect/OpenACC/OpenACC.h"
21
22namespace Fortran::lower {
23// Check if the insertion point is currently in a device context. HostDevice
24// subprogram are not considered fully device context so it will return false
25// for it.
26// If the insertion point is inside an OpenACC region op, it is considered
27// device context.
28static bool isCudaDeviceContext(fir::FirOpBuilder &builder) {
29 if (builder.getRegion().getParentOfType<cuf::KernelOp>())
30 return true;
31 if (builder.getRegion()
32 .getParentOfType<mlir::acc::ComputeRegionOpInterface>())
33 return true;
34 if (auto funcOp = builder.getRegion().getParentOfType<mlir::func::FuncOp>()) {
35 if (auto cudaProcAttr =
36 funcOp.getOperation()->getAttrOfType<cuf::ProcAttributeAttr>(
37 cuf::getProcAttrName())) {
38 return cudaProcAttr.getValue() != cuf::ProcAttribute::Host &&
39 cudaProcAttr.getValue() != cuf::ProcAttribute::HostDevice;
40 }
41 }
42 return false;
43}
44} // end namespace Fortran::lower
45
46#endif // FORTRAN_LOWER_CUDA_H
Definition: FIRBuilder.h:55
mlir::Region & getRegion()
Get the current Region of the insertion point.
Definition: FIRBuilder.h:103
Definition: AbstractConverter.h:59