Skip to content
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

[flang][OpenMP] Handle multiple ranges in num_teams clause #102535

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions flang/lib/Lower/OpenMP/ClauseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,12 @@ bool ClauseProcessor::processNumTeams(
// TODO Get lower and upper bounds for num_teams when parser is updated to
// accept both.
if (auto *clause = findUniqueClause<omp::clause::NumTeams>()) {
// auto lowerBound = std::get<std::optional<ExprTy>>(clause->t);
auto &upperBound = std::get<ExprTy>(clause->t);
// The num_teams directive accepts a list of team lower/upper bounds.
// This is an extension to support grid specification for ompx_bare.
// Here, only expect a single element in the list.
assert(clause->v.size() == 1);
// auto lowerBound = std::get<std::optional<ExprTy>>(clause->v[0]->t);
auto &upperBound = std::get<ExprTy>(clause->v[0].t);
result.numTeamsUpper =
fir::getBase(converter.genExprValue(upperBound, stmtCtx));
return true;
Expand Down
5 changes: 3 additions & 2 deletions flang/lib/Lower/OpenMP/Clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,9 @@ NumTasks make(const parser::OmpClause::NumTasks &inp,
NumTeams make(const parser::OmpClause::NumTeams &inp,
semantics::SemanticsContext &semaCtx) {
// inp.v -> parser::ScalarIntExpr
return NumTeams{{/*LowerBound=*/std::nullopt,
/*UpperBound=*/makeExpr(inp.v, semaCtx)}};
List<NumTeams::Range> v{{{/*LowerBound=*/std::nullopt,
/*UpperBound=*/makeExpr(inp.v, semaCtx)}}};
return NumTeams{/*List=*/v};
}

NumThreads make(const parser::OmpClause::NumThreads &inp,
Expand Down
14 changes: 12 additions & 2 deletions llvm/include/llvm/Frontend/OpenMP/ClauseT.h
Original file line number Diff line number Diff line change
Expand Up @@ -885,10 +885,20 @@ struct NumTasksT {
// V5.2: [10.2.1] `num_teams` clause
template <typename T, typename I, typename E> //
struct NumTeamsT {
using TupleTrait = std::true_type;
using LowerBound = E;
using UpperBound = E;
std::tuple<OPT(LowerBound), UpperBound> t;

// The name Range is not a spec name.
struct Range {
using TupleTrait = std::true_type;
std::tuple<OPT(LowerBound), UpperBound> t;
};

// The name List is not a spec name. The list is an extension to allow
// specifying a grid with connection with the ompx_bare clause.
using List = ListT<Range>;
using WrapperTrait = std::true_type;
List v;
};

// V5.2: [10.1.2] `num_threads` clause
Expand Down
Loading