This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Use common interface to access GPU Grid Values
ClosedPublic

Authored by saiislam on Jul 9 2020, 9:56 AM.

Details

Summary

Use common interface for accessing target specific GPU grid values in NVPTX
OpenMP codegen as proposed in https://reviews.llvm.org/D80917

Originally authored by Greg Rodgers (@gregrodgers).

Diff Detail

Event Timeline

saiislam created this revision.Jul 9 2020, 9:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2020, 9:56 AM

Changing to getGridValue would be useful for sharing parts of this with amdgcn.

The aomp toolchain handles codegen for amdgcn by adding if (isAMDGCN) to this file. Until such time as tregions obsoletes this code, I think we should go with layers instead of scattered conditionals.

I.e. rename CGOpenMPRuntimeNVPTX to CGOpenMPRuntimeGPU which contains code that is common to nvptx and amdgcn. That probably uses getGridValue() as a way to abstract over minor differences. Derive CGOpenMPRuntimeAMDGCN and CGOpenMPRuntimeNVPTX from CGOpenMPRuntimeGPU to implement (virtual) functions which are different between the two.

clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
628 ↗(On Diff #276767)

This looks unrelated to using the constants. Amdgcn doesn't have an nvvm_read_ptx_sreg_warpsize so does need a different means of accessing the wave size, but that's not directly related to using OMPGridValues

jdoerfert added inline comments.Jul 10 2020, 4:42 PM
clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
654 ↗(On Diff #276767)

Why do we keep the enum value with this name then?

Changing to getGridValue would be useful for sharing parts of this with amdgcn.

The aomp toolchain handles codegen for amdgcn by adding if (isAMDGCN) to this file. Until such time as tregions obsoletes this code, I think we should go with layers instead of scattered conditionals.

I.e. rename CGOpenMPRuntimeNVPTX to CGOpenMPRuntimeGPU which contains code that is common to nvptx and amdgcn. That probably uses getGridValue() as a way to abstract over minor differences. Derive CGOpenMPRuntimeAMDGCN and CGOpenMPRuntimeNVPTX from CGOpenMPRuntimeGPU to implement (virtual) functions which are different between the two.

Here is an implementation: D83723 . It also provides target specific implementation of getNVPTXWarpSize() as proof of concept.

saiislam marked an inline comment as done.Jul 17 2020, 8:39 AM
saiislam added inline comments.
clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
654 ↗(On Diff #276767)

Enums in OMPGridValues.h has been named like this because many of the values are dependent on a different value in the same enum. For example, hardcoded value of number of bits required to represent the max number of threads in a warp (LaneIDBits here), is computed as log of WarpSize. Similarly, mask of this value (LaneIDMask below) is based on WarpSize. A future change in WarpSize thus will require update in all the enums based on (and prefixed as) WarpSize, so less chances of a manual error.

See this: https://github.com/llvm/llvm-project/blob/8b6821a5843bb321b3738e2519beae7142e62928/llvm/include/llvm/Frontend/OpenMP/OMPGridValues.h#L120

saiislam updated this revision to Diff 278787.Jul 17 2020, 8:43 AM

Removed getNVPTXWarpSize() changes for a separate patch and rebased.

saiislam updated this revision to Diff 278799.Jul 17 2020, 9:07 AM

Corrected.

This revision is now accepted and ready to land.Jul 17 2020, 9:22 AM
This revision was automatically updated to reflect the committed changes.