The HAS_DEVICE_ADDR indicates that the object(s) listed exists at an address that is a valid device address. Specifically, `has_device_addr(x)` means that (in C/C++ terms) `&x` is a device address. When entering a target region, `x` does not need to be allocated on the device, or have its contents copied over (in the absence of additional mapping clauses). Passing its address verbatim to the region for use is sufficient, and is the intended goal of the clause. Some Fortran objects use descriptors in their in-memory representation. If `x` had a descriptor, both the descriptor and the contents of `x` would be located in the device memory. However, the descriptors are managed by the compiler, and can be regenerated at various points as needed. The address of the effective descriptor may change, hence it's not safe to pass the address of the descriptor to the target region. Instead, the descriptor itself is always copied, but for objects like `x`, no further mapping takes place (as this keeps the storage pointer in the descriptor unchanged). --------- Co-authored-by: Sergio Afonso <safonsof@amd.com>
51 lines
1.9 KiB
C++
51 lines
1.9 KiB
C++
//===-- lib/Support/OpenMP-utils.cpp ----------------------------*- 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/Support/OpenMP-utils.h"
|
|
|
|
#include "mlir/IR/OpDefinition.h"
|
|
|
|
namespace Fortran::common::openmp {
|
|
mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const EntryBlockArgs &args,
|
|
mlir::Region ®ion) {
|
|
assert(args.isValid() && "invalid args");
|
|
assert(region.empty() && "non-empty region");
|
|
|
|
llvm::SmallVector<mlir::Type> types;
|
|
llvm::SmallVector<mlir::Location> locs;
|
|
unsigned numVars = args.hasDeviceAddr.vars.size() + args.hostEvalVars.size() +
|
|
args.inReduction.vars.size() + args.map.vars.size() +
|
|
args.priv.vars.size() + args.reduction.vars.size() +
|
|
args.taskReduction.vars.size() + args.useDeviceAddr.vars.size() +
|
|
args.useDevicePtr.vars.size();
|
|
types.reserve(numVars);
|
|
locs.reserve(numVars);
|
|
|
|
auto extractTypeLoc = [&types, &locs](llvm::ArrayRef<mlir::Value> vals) {
|
|
llvm::transform(vals, std::back_inserter(types),
|
|
[](mlir::Value v) { return v.getType(); });
|
|
llvm::transform(vals, std::back_inserter(locs),
|
|
[](mlir::Value v) { return v.getLoc(); });
|
|
};
|
|
|
|
// Populate block arguments in clause name alphabetical order to match
|
|
// expected order by the BlockArgOpenMPOpInterface.
|
|
extractTypeLoc(args.hasDeviceAddr.vars);
|
|
extractTypeLoc(args.hostEvalVars);
|
|
extractTypeLoc(args.inReduction.vars);
|
|
extractTypeLoc(args.map.vars);
|
|
extractTypeLoc(args.priv.vars);
|
|
extractTypeLoc(args.reduction.vars);
|
|
extractTypeLoc(args.taskReduction.vars);
|
|
extractTypeLoc(args.useDeviceAddr.vars);
|
|
extractTypeLoc(args.useDevicePtr.vars);
|
|
|
|
return builder.createBlock(®ion, {}, types, locs);
|
|
}
|
|
} // namespace Fortran::common::openmp
|