Page MenuHomePhabricator

[OpenMP] Creating the `omp_target_num_teams` and `omp_target_thread_limit` attributes to outlined functions

Authored by josemonsalve2 on Jul 19 2021, 12:05 PM.



The device runtime contains several calls to kmpc_get_hardware_num_threads_in_block
kmpc_get_hardware_num_blocks. If the thread_limit and the num_teams are constant,
these calls can be folded to the constant value.

In commit D106033 we have the optimization phase. This commit adds the attributes to
the outlined function for the grid size. the two attributes are omp_target_num_teams and
omp_target_thread_limit. These values are added as long as they are constant.

Two functions are created getNumThreadsExprForTargetDirective and
getNumTeamsExprForTargetDirective. The original functions emitNumTeamsForTargetDirective
and emitNumThreadsForTargetDirective identify the expresion and emit the code.
However, for the Device version of the outlined function, we cannot emit anything.
Therefore, this is a first attempt to separate emision of code from deduction of the

Diff Detail

Event Timeline

josemonsalve2 created this revision.Jul 19 2021, 12:05 PM
josemonsalve2 requested review of this revision.Jul 19 2021, 12:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2021, 12:05 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript




If you are referring to new tests, working on them. If you are referring to those tests that are failing, is because introducing new attributes broke some tests because they expect a lot of functions to have the same attributes, this creates a new group.

Changing the attribute names to those sugested by @jdoerfert

josemonsalve2 marked 2 inline comments as done.Jul 19 2021, 3:34 PM
josemonsalve2 added inline comments.

Should I default here to 1? Since this is an omp target

jdoerfert added inline comments.Jul 19 2021, 3:38 PM

Yes, also above. This will make

`omp target`


`omp target num_teams(1)`

the same thing. Which is what we want, at least for now.


See clang-tidy warning, also DefaultNT is not initialized potentially. I think you should just return a nullptr if getNumTeamsExprForTargetDirective did and always return an Expr if you can.

Making the default num teams for omp target be 1. Also fixing clang-tidy error and missing initialization.

josemonsalve2 marked an inline comment as done.Jul 19 2021, 3:46 PM

Adding test file /clang/test/OpenMP/target_num_teams_num_threads_attributes.cpp

I've fixed all the clang tests. It is also not possible to provide a default
for omp target because the code relies on a nullptr being returned for generating
the right runtime call. Therefore I reverted that change and use -1 to flag
this case. I've also moved some elements to the emit function that were in the
getNumTeamsExpr function

josemonsalve2 retitled this revision from [OpenMP] Creating the `NumTeams` and `ThreadLimit` attributes to outlined functions to [OpenMP] Creating the `omp_target_num_teams` and `omp_target_thread_limit` attributes to outlined functions.Jul 20 2021, 10:23 AM
josemonsalve2 edited the summary of this revision. (Show Details)

Forgot to run git-clang-format

jdoerfert accepted this revision.Jul 26 2021, 12:06 PM

The codegen changes look sensible and the tests show only attributes changed. LGTM

This revision is now accepted and ready to land.Jul 26 2021, 12:06 PM

Rebasing to main

This revision was landed with ongoing or failed builds.Jul 27 2021, 2:21 PM
This revision was automatically updated to reflect the committed changes.