9#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_CUFCOMMON_H_
10#define FORTRAN_OPTIMIZER_TRANSFORMS_CUFCOMMON_H_
12#include "flang/Optimizer/Dialect/FIROps.h"
13#include "mlir/Dialect/Func/IR/FuncOps.h"
14#include "mlir/Dialect/GPU/IR/GPUDialect.h"
15#include "mlir/IR/BuiltinOps.h"
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/ADT/SetVector.h"
18#include "llvm/TargetParser/Triple.h"
20static constexpr llvm::StringRef cudaDeviceModuleName =
"cuda_device_mod";
21static constexpr llvm::StringRef cudaSharedMemSuffix =
"__shared_mem__";
25static constexpr llvm::StringRef cudaDeviceCopySuffix =
".device";
29static constexpr llvm::StringRef cudaSharedTypeInfoSection =
"__nv_type_info";
33static constexpr llvm::StringRef cudaSharedTypeInfoEndPrefix =
34 "__nv_type_info_end_";
37inline int64_t getCudaSharedTypeInfoAlignment(
const llvm::Triple &triple) {
38 if (triple.isAArch64() || triple.isPPC64())
44static constexpr llvm::StringRef cudaSharedTypeDescsAttrName =
45 "cuf.shared_type_descs";
48static constexpr llvm::StringRef cudaHostTypeDescAttrName =
60 mlir::SymbolTable &symTab);
62bool isCUDADeviceContext(mlir::Operation *op);
63bool isCUDADeviceContext(mlir::Region &,
64 bool isDoConcurrentOffloadEnabled =
false);
72bool isRegisteredDeviceGlobal(fir::GlobalOp op);
73bool isRegisteredDeviceAttr(std::optional<cuf::DataAttribute> attr);
107 bool rejectDynamicDispatch =
false);
112 mlir::Operation *root,
113 const llvm::DenseMap<mlir::StringAttr, mlir::FlatSymbolRefAttr> &map);
126int computeElementByteSize(mlir::Location loc, mlir::Type type,
128 bool emitErrorOnFailure =
true);
130mlir::Value computeElementCount(mlir::PatternRewriter &rewriter,
131 mlir::Location loc, mlir::Value shapeOperand,
132 mlir::Type seqType, mlir::Type targetType);
Definition FIRBuilder.h:66
Definition KindMapping.h:48
Definition ConvertVariable.h:28
bool isDeviceProcedure(mlir::func::FuncOp funcOp)
Definition CUFCommon.cpp:212
bool isExecutingOnDevice(mlir::Operation *op)
Definition CUFCommon.cpp:75
void remapProcedureSymbols(mlir::Operation *root, const llvm::DenseMap< mlir::StringAttr, mlir::FlatSymbolRefAttr > &map)
Definition CUFCommon.cpp:300
bool isTypeInfoGlobal(fir::GlobalOp op)
Definition CUFCommon.cpp:105
bool isTypeDescriptorGlobal(fir::GlobalOp op)
Definition CUFCommon.cpp:119
void setDeviceAllocationPolicy(mlir::Operation *func)
Definition CUFCommon.cpp:320
void genPointerSync(mlir::Location loc, const mlir::Value box, fir::FirOpBuilder &builder)
Definition CUFCommon.cpp:132
DeviceCodeSet collectDeviceCode(mlir::ModuleOp mod, mlir::SymbolTable &symTab, bool rejectDynamicDispatch=false)
Definition CUFCommon.cpp:232
mlir::gpu::GPUModuleOp getOrCreateGPUModule(mlir::ModuleOp mod, mlir::SymbolTable &symTab)
Retrieve or create the CUDA Fortran GPU module in the given mod.
Definition CUFCommon.cpp:25
Definition AbstractConverter.h:37
The device code of a module, as gathered by collectDeviceCode.
Definition CUFCommon.h:89
llvm::SetVector< mlir::func::FuncOp > deviceFuncs
Procedures with a device proc attribute (see isDeviceProcedure).
Definition CUFCommon.h:91
llvm::SetVector< mlir::func::FuncOp > calledFromDevice
Definition CUFCommon.h:96
llvm::SetVector< mlir::func::FuncOp > keepInModule
Definition CUFCommon.h:99