forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding CUFCommon.{h,cpp} for CUF utilities (llvm#113740)
- Loading branch information
Showing
4 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===-- CUFCommon.h -------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_CUFCOMMON_H_ | ||
#define FORTRAN_OPTIMIZER_TRANSFORMS_CUFCOMMON_H_ | ||
|
||
#include "mlir/Dialect/GPU/IR/GPUDialect.h" | ||
#include "mlir/IR/BuiltinOps.h" | ||
|
||
static constexpr llvm::StringRef cudaDeviceModuleName = "cuda_device_mod"; | ||
|
||
namespace cuf { | ||
|
||
/// Retrieve or create the CUDA Fortran GPU module in the given \p mod. | ||
mlir::gpu::GPUModuleOp getOrCreateGPUModule(mlir::ModuleOp mod, | ||
mlir::SymbolTable &symTab); | ||
|
||
} // namespace cuf | ||
|
||
#endif // FORTRAN_OPTIMIZER_TRANSFORMS_CUFCOMMON_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//===-- CUFCommon.cpp - Shared functions between passes ---------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "flang/Optimizer/Transforms/CUFCommon.h" | ||
#include "mlir/Dialect/LLVMIR/NVVMDialect.h" | ||
|
||
/// Retrieve or create the CUDA Fortran GPU module in the give in \p mod. | ||
mlir::gpu::GPUModuleOp cuf::getOrCreateGPUModule(mlir::ModuleOp mod, | ||
mlir::SymbolTable &symTab) { | ||
if (auto gpuMod = symTab.lookup<mlir::gpu::GPUModuleOp>(cudaDeviceModuleName)) | ||
return gpuMod; | ||
|
||
auto *ctx = mod.getContext(); | ||
mod->setAttr(mlir::gpu::GPUDialect::getContainerModuleAttrName(), | ||
mlir::UnitAttr::get(ctx)); | ||
|
||
mlir::OpBuilder builder(ctx); | ||
auto gpuMod = builder.create<mlir::gpu::GPUModuleOp>(mod.getLoc(), | ||
cudaDeviceModuleName); | ||
llvm::SmallVector<mlir::Attribute> targets; | ||
targets.push_back(mlir::NVVM::NVVMTargetAttr::get(ctx)); | ||
gpuMod.setTargetsAttr(builder.getArrayAttr(targets)); | ||
mlir::Block::iterator insertPt(mod.getBodyRegion().front().end()); | ||
symTab.insert(gpuMod, insertPt); | ||
return gpuMod; | ||
} |