Skip to content

[flang][openacc] Allow open acc routines from other modules. #136012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 9, 2025
Prev Previous commit
Next Next commit
addressing feedback
  • Loading branch information
akuhlens committed May 6, 2025
commit f518d616ecb7accbe09a02cb78520477420c5e59
5 changes: 4 additions & 1 deletion flang/include/flang/Semantics/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class WithBindName {
// Device type specific OpenACC routine information
class OpenACCRoutineDeviceTypeInfo {
public:
OpenACCRoutineDeviceTypeInfo(Fortran::common::OpenACCDeviceType dType)
explicit OpenACCRoutineDeviceTypeInfo(
Fortran::common::OpenACCDeviceType dType)
: deviceType_{dType} {}
bool isSeq() const { return isSeq_; }
void set_isSeq(bool value = true) { isSeq_ = value; }
Expand Down Expand Up @@ -161,6 +162,8 @@ class OpenACCRoutineDeviceTypeInfo {
bool isWorker_{false};
bool isGang_{false};
unsigned gangDim_{0};
// bind("name") -> std::string
// bind(sym) -> SymbolRef (requires namemangling in lowering)
std::optional<std::variant<std::string, SymbolRef>> bindName_;
Fortran::common::OpenACCDeviceType deviceType_{
Fortran::common::OpenACCDeviceType::None};
Expand Down
60 changes: 36 additions & 24 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,65 +1036,75 @@ void AccAttributeVisitor::AddRoutineInfoToSymbol(
Fortran::semantics::OpenACCRoutineInfo info;
std::vector<OpenACCRoutineDeviceTypeInfo *> currentDevices;
currentDevices.push_back(&info);
const auto &clauses = std::get<Fortran::parser::AccClauseList>(x.t);
const auto &clauses{std::get<Fortran::parser::AccClauseList>(x.t)};
for (const Fortran::parser::AccClause &clause : clauses.v) {
if (const auto *dTypeClause =
std::get_if<Fortran::parser::AccClause::DeviceType>(&clause.u)) {
if (const auto *dTypeClause{
std::get_if<Fortran::parser::AccClause::DeviceType>(&clause.u)}) {
currentDevices.clear();
for (const auto &deviceTypeExpr : dTypeClause->v.v)
for (const auto &deviceTypeExpr : dTypeClause->v.v) {
currentDevices.push_back(&info.add_deviceTypeInfo(deviceTypeExpr.v));
}
} else if (std::get_if<Fortran::parser::AccClause::Nohost>(&clause.u)) {
info.set_isNohost();
} else if (std::get_if<Fortran::parser::AccClause::Seq>(&clause.u)) {
for (auto &device : currentDevices)
for (auto &device : currentDevices) {
device->set_isSeq();
}
} else if (std::get_if<Fortran::parser::AccClause::Vector>(&clause.u)) {
for (auto &device : currentDevices)
for (auto &device : currentDevices) {
device->set_isVector();
}
} else if (std::get_if<Fortran::parser::AccClause::Worker>(&clause.u)) {
for (auto &device : currentDevices)
for (auto &device : currentDevices) {
device->set_isWorker();
} else if (const auto *gangClause =
std::get_if<Fortran::parser::AccClause::Gang>(&clause.u)) {
for (auto &device : currentDevices)
}
} else if (const auto *gangClause{
std::get_if<Fortran::parser::AccClause::Gang>(
&clause.u)}) {
for (auto &device : currentDevices) {
device->set_isGang();
}
if (gangClause->v) {
const Fortran::parser::AccGangArgList &x = *gangClause->v;
int numArgs{0};
for (const Fortran::parser::AccGangArg &gangArg : x.v) {
CHECK(numArgs <= 1 && "expecting 0 or 1 gang dim args");
if (const auto *dim =
std::get_if<Fortran::parser::AccGangArg::Dim>(&gangArg.u)) {
if (const auto *dim{std::get_if<Fortran::parser::AccGangArg::Dim>(
&gangArg.u)}) {
if (const auto v{EvaluateInt64(context_, dim->v)}) {
for (auto &device : currentDevices)
for (auto &device : currentDevices) {
device->set_gangDim(*v);
}
}
}
numArgs++;
}
}
} else if (const auto *bindClause =
std::get_if<Fortran::parser::AccClause::Bind>(&clause.u)) {
if (const auto *name =
std::get_if<Fortran::parser::Name>(&bindClause->v.u)) {
if (Symbol *sym = ResolveFctName(*name)) {
} else if (const auto *bindClause{
std::get_if<Fortran::parser::AccClause::Bind>(
&clause.u)}) {
if (const auto *name{
std::get_if<Fortran::parser::Name>(&bindClause->v.u)}) {
if (Symbol * sym{ResolveFctName(*name)}) {
Symbol &ultimate{sym->GetUltimate()};
for (auto &device : currentDevices)
for (auto &device : currentDevices) {
device->set_bindName(SymbolRef(ultimate));
}
} else {
context_.Say((*name).source,
"No function or subroutine declared for '%s'"_err_en_US,
(*name).source);
}
} else if (const auto charExpr =
} else if (const auto charExpr{
std::get_if<Fortran::parser::ScalarDefaultCharExpr>(
&bindClause->v.u)) {
auto *charConst =
&bindClause->v.u)}) {
auto *charConst{
Fortran::parser::Unwrap<Fortran::parser::CharLiteralConstant>(
*charExpr);
*charExpr)};
std::string str{std::get<std::string>(charConst->t)};
for (auto &device : currentDevices)
for (auto &device : currentDevices) {
device->set_bindName(std::string(str));
}
}
}
}
Expand Down Expand Up @@ -3031,3 +3041,5 @@ void OmpAttributeVisitor::IssueNonConformanceWarning(
warnStrOS.str());
}
} // namespace Fortran::semantics

} // namespace Fortran::semantics