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][MLIR] Fix to mapping adding additional map pointer component for Descriptor mappings, helps to fix use_device_addr/ptr with these types #122

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

agozillon
Copy link

This PR basically adds an additional pointer binding for the descriptor base address. which we attach the user data to, it also makes sure that the mapping for the descriptor is always at a minimum "to" where possible, as regardless of whether or not we wish to map the user data the descriptor wrapping the data must be mapped across as the kernel will still make an attempt to access descriptor information to perform various tasks such as indexing into the user data. This may eventually be restricted a little further in the future to only allow descriptors to have a to mapping in cases where it's legal to have a to mapping (i.e. not legal on an exit directive).

…for Descriptor mappings, helps to fix use_device_addr/ptr with these types

This PR basically adds an additional pointer binding for the descriptor base address. which we attach the user data to, it also makes sure that the mapping for the descriptor is always at a minimum "to" where possible, as regardless of whether or not we wish to map the user data the descriptor wrapping the data must be mapped across as the kernel will still make an attempt to access descriptor information to perform various tasks such as indexing into the user data. This may eventually be restricted a little further in the future to only allow descriptors to have a to mapping in cases where it's legal to have a to mapping (i.e. not legal on an exit directive).
Copy link

@dpalermo dpalermo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that smoke-fort-fails/flang-471469 passes with this change...as well as smoke-fort/milestone-3-babel.

@agozillon agozillon merged commit 0eb6000 into ROCm:amd-trunk-dev Jul 18, 2024
3 of 5 checks passed
Copy link

@skatrak skatrak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Andrew for the post-merge review here. It's mainly just some nits to improve readability a bit, for when you have some time to work on them. Only one small concern that may potentially cause issues. Thank you!

op.getMapType().value()),
builder.getIntegerAttr(
builder.getIntegerType(64, false),
getDescriptorMapType(op.getMapType().value(), target)),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know for sure the map_type argument is defined by this point or would it make sense to do something like this instead?

Suggested change
getDescriptorMapType(op.getMapType().value(), target)),
getDescriptorMapType(op.getMapType().value_or(llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE), target)),

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, maybe we could just make the map_type argument required but default-valued to 0 in MLIR instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map type should never be unset by Flang, which is the only frontend that will use this pass!

Comment on lines +68 to +71
static_cast<
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
(newDescFlag &
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM)) &&
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like this be equivalent? I'm just suggesting it because these if statements are quite difficult to read currently:

Suggested change
static_cast<
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
(newDescFlag &
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM)) &&
llvm::to_underlying(newDescFlag & llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM) &&

@@ -59,6 +59,34 @@ class OMPMapInfoFinalizationPass
/*corresponding local alloca=*/fir::AllocaOp>
localBoxAllocas;

unsigned long getDescriptorMapType(unsigned long mapTypeFlag,
mlir::Operation *target) {
auto newDescFlag = llvm::omp::OpenMPOffloadMappingFlags(mapTypeFlag);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: To shorten the isa_and_nonnull to isa checks below and improve readability a bit, maybe add here:

  if (!target)
    return mapTypeFlag;

@@ -2721,6 +2721,24 @@ static void processMapMembersWithParent(

assert(memberDataIdx >= 0 && "could not find mapped member of structure");

if (checkIfPointerMap(memberClause)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe a short descriptive comment of what's achieved by this block here would be nice.

Copy link
Author

@agozillon agozillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to add these nits to the main PR set that will eventually override these changes, the upstream PRs can be found here:

llvm#96266
llvm#96265

So please do review these, I'll aim to port over the comments from here to the PR, but if you wish to also add them inline again on the upstream PR it'd be greatly appreciated!

op.getMapType().value()),
builder.getIntegerAttr(
builder.getIntegerType(64, false),
getDescriptorMapType(op.getMapType().value(), target)),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map type should never be unset by Flang, which is the only frontend that will use this pass!

@agozillon
Copy link
Author

Happy to add these nits to the main PR set that will eventually override these changes, the upstream PRs can be found here:

llvm#96266 llvm#96265

So please do review these, I'll aim to port over the comments from here to the PR, but if you wish to also add them inline again on the upstream PR it'd be greatly appreciated!

Primarily as it saves me replicating the work and risking some disjoint between the end results, but if you feel strongly about any of the comments I am more than happy to make the adjustments to ATD! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants