This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.
Needs ReviewPublic

Authored by abidmalikwaterloo on Jun 30 2021, 6:42 PM.

Details

Summary

This includes a basic implementation for the OpenMP target data, exit data, and enter data constructs
operation.

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
abidmalikwaterloo requested review of this revision.Jun 30 2021, 6:42 PM

Is this ready for review?

Is this ready for review?

Yes.

abidmalikwaterloo retitled this revision from Added target data, exit data, and enter data operation definition for MLIR. to [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR..Jul 1 2021, 8:51 AM
abidmalikwaterloo edited the summary of this revision. (Show Details)
clementval requested changes to this revision.Jul 1 2021, 8:52 AM
clementval added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
253

Indent looks off.

270

Since map is a required clause on the Fortran side it would be better to have it directly for the first version of the op.

275

Indent.

287

Not sure if there is a guidelines for that but I think op should use snake_case. At least in the OMP dialect snake_case is used until now so you should follow it. (ex: num_threads on the parallel op).

290

Indent looks off in the description.

304

Since map is a required clause on the Fortran side it would be better to have it directly for the first version of the op.

311

I don't think it makes sense to have a region attached for standalone directives.

337

Since map is a required clause on the Fortran side it would be better to have it directly for the first version of the op.

344

I don't think exit data should have a region attached.

This revision now requires changes to proceed.Jul 1 2021, 8:52 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

map([[map-type-modifier[,]]map-type:]list)

Based on Thread discussion, the following segmentation of the map clause operands should work.

Optional<StringAttr>:$mapTypeModifier
Optional<StringAttr>:$mapType
Variadic<AnyType>:$mapOperands

acc exit data and enter data also follow the same pattern. Any suggestions?

clementval added inline comments.Jul 2 2021, 4:45 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

Not sure it would do the trick since you can have multiple map clauses with different map type and map type modifier. If you model it like that you can have only one clause represented by operation.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

I intend to make it more in line with the OpenACC data environment; copy, copying, copyout. etc.

Variadic<AnyType>:$mapOperands
Variadic<AnyType>:$mapToOperands
Variadic<AnyType>:$mapFromOperands
Variadic<AnyType>:$mapToFromOperands
Variadic<AnyType>:$mapAllocOperands
Variadic<AnyType>:$mapReleaseOperands
Variadic<AnyType>:$mapDeleteOperands
Variadic<AnyType>:$mapTypeModifier

clementval added inline comments.Jul 2 2021, 12:21 PM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

Also clause can take several map-type-modifier (map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] locator-list)) so a single Optional<StringAttr> will not work. You might need a special type that encapsulate all the information.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

How about Variadic<AnyType>:$mapTypeModifier? or we need a separate operand for each map<X> Operands? I feel that we need a separate modifier operand for each map<X>Operands.

clementval added inline comments.Jul 6 2021, 7:26 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

I guess a enum would fit better here. The problem is that the map-type-modifier is associated with a specific map clause so if we have the different operands as you mentioned before, how do we know which one is associated with the map-type-modifier ?

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

We need to know about each modifier for each map clause
OptionalAttribute<MapTypeModifier>=$mapTypeModifierTo
OptionalAttribute<MapTypeModifier>=$mapTypeModifierFrom
OptionalAttribute<MapTypeModifier>=$mapTypeModifierToFrom
and so on for each type.
enum MapTypeModifier = [ always, close, mapper].
Does this make sense?

clementval added inline comments.Jul 7 2021, 6:41 PM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

I don't think that's enough since you can have something like in the following example:

!$omp target enter data map(always, to: a) map(to:b)

In this case the two operands should end up in mapToOperands but with a different modifier.

Maybe a vector holding the modifier for each operands would work (VectorOf<MapTypeModifier>). With this you would be able to store the operands in the mapToOperands with a vector of size 2 that holds the modifier values ([always, none]). The vector size is of course equal to the total number of operands in you 8 operands variadic arguments.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

MLIR does not have a VectorOf operation class. We need to define one ( I think, not an MLIR expert). The quick solution to this is to define an operand for each map-type for each type modifier.

FOR "TO"
Variadic <AnyType> = $mapToAlways
Variadic <AnyType> = $mapToClose
Variadic <AnyType> = $mapToMapper
Variadic <AnyType> = $mapToNone

Similarly, we can define for each map-type { from, tofrom , alloc ,release ,delete}. The only caveat is that we will have 24 operands for the operation.

clementval added inline comments.Jul 9 2021, 9:15 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

It has vectorof class. I took it from the mlir file directly.

clementval added inline comments.Jul 9 2021, 9:24 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

You might need to add it as an attribute instead of an operand. I didn’t check but for aure the operand segment attribute is an vector of int.

abidmalikwaterloo marked 3 inline comments as done.Jul 12 2021, 9:27 AM
abidmalikwaterloo added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

let arguments = (ins Optional<I1>:$if_expr,

Optional<AnyInteger>:$device,
Variadic<AnyType>:$use_device_ptr,
Variadic<AnyType>:$use_device_addr,
Variadic<AnyType>:$mapOperands,
Variadic<AnyType>:$mapToOperands,
Variadic<AnyType>:$mapFromOperands,
Variadic<AnyType>:$mapToFromOperands,
Variadic<AnyType>:$mapAllocOperands,
Variadic<AnyType>:$mapReleaseOperands,
Variadic<AnyType>:$mapDeleteOperands,
VectorOfLengthAndType<[7],[AnyType]>:$map_type_modifier_always,
VectorOfLengthAndType<[7],[AnyType]>:$map_type_modifier_close,
VectorOfLengthAndType<[7],[AnyType]>:$map_type_modifier_mapper);

I feel this should work. The vectors will keep track of modifier for each map type.

clementval added inline comments.Jul 12 2021, 10:55 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

I think a single vector would be easier and you can encode the values of always, close and mapper (maybe in a uint). It is done like this in the runtime so you will have less processing during the translation. It will also accept new modifiers if newer version of the standard add some.

The vector should not be fixed in size. Its size should be equal to the number of operands. Like if you have 2 operands in $mapOperands and in $mapToOperands` the vector size is 3.

abidmalikwaterloo marked an inline comment as done.Jul 12 2021, 1:18 PM
abidmalikwaterloo added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

The vector should not be fixed in size. Its size should be equal to the number of operands. Like if you have 2 operands in $mapOperands and ( You mean 1 here right???) in $mapToOperands` the vector size is 3.

We are assuming the order in which the map operands appear will define the operands in the vector map_type_modifier and the corresponding element will define the content (modifier defined by a unit). For example, consider the following:

map (always, to : v1, v2) map(to: a, b) map ( from:p)

we have five operands. The vector size is five. The vector representation [always, always, none, none, none]

clementval added inline comments.Jul 13 2021, 7:26 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
270

Yeah that's what I mean. If you find a better way represent the information it's also fine but I thought this is concise and will be perfectly fitted for the translation later.

abidmalikwaterloo marked 13 inline comments as done.

Added map clase support to target data, enter data and exit data
Revised according to the reviewer's comments
Added a test case
Used snake_case format

clementval requested changes to this revision.Jul 15 2021, 8:23 AM

Indent are off in many places. Can you update that?

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
256

Indent is still off here.

276

Indent still off.

287

Arguments are not aligned.

313

Indent is off.

394

Indent

This revision now requires changes to proceed.Jul 15 2021, 8:23 AM

Revised for indentation as pinpointed by the reviewer.

clementval requested changes to this revision.Jul 16 2021, 9:47 AM
clementval added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
342

Indent.

mlir/test/Dialect/OpenMP/ops.mlir
296

Exit data is not tested here.

This revision now requires changes to proceed.Jul 16 2021, 9:47 AM

Added test example for exit data operation

clementval requested changes to this revision.Jul 20 2021, 8:42 AM
clementval added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
287

There is still an indent problem here.

401

Is AnyType really what we want here? Should be an enum or an integer encoding the value. As a side not, we could also have a single $map_operands argument and have a second vector to encode the map-type but that just a thought.

This revision now requires changes to proceed.Jul 20 2021, 8:42 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
276

Need to wor

287

Need to check my editor

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
401
  • Based on the previous patches, I have the impression that the community prefers to make operations flexible and adaptable as things are fluid at a higher level. I would prefer enum
  • I tried to make the operation in line with the acc. data operations. Single vector to hold map_type and operand to hold all map operands should work as in the case of map_type_modifier
clementval added inline comments.Jul 21 2021, 8:30 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
401
  • Based on the previous patches, I have the impression that the community prefers to make operations flexible and adaptable as things are fluid at a higher level. I would prefer enum

I think we try to be permissive where we have actual data but here is smith that we have to encode so I would make it more strict otherwise the translation will be complicated.

  • I tried to make the operation in line with the acc. data operations. Single vector to hold map_type and operand to hold all map operands should work as in the case of map_type_modifier

Sure it is just a suggestion. It is totally fine to keep it the way you have it now. OpenACC has multiple clauses to represent the different map-types so that's why it was done like that.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
401
  • Based on the previous patches, I have the impression that the community prefers to make operations flexible and adaptable as things are fluid at a higher level. I would prefer enum

I think we try to be permissive where we have actual data but here is smith that we have to encode so I would make it more strict otherwise the translation will be complicated.

  • I tried to make the operation in line with the acc. data operations. Single vector to hold map_type and operand to hold all map operands should work as in the case of map_type_modifier

Sure it is just a suggestion. It is totally fine to keep it the way you have it now. OpenACC has multiple clauses to represent the different map-types so that's why it was done like that.

401

VectorOf<[AnyInteger]>:$map_type_modifier should be fine. Whatever the coding we adapt, it will be translated to an integer number for storing.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
401

Does this make sence?

clementval added inline comments.Sep 9 2021, 2:45 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
266

Longer than 80

268

Longer than 80

401

Yeah it should work. I would go ahead and even restrict the type of integer you use here.

abidmalikwaterloo marked 7 inline comments as done.Sep 15 2021, 10:53 AM
abidmalikwaterloo marked an inline comment as done.
abidmalikwaterloo marked 6 inline comments as done.Sep 15 2021, 10:58 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
401

<IntOrIndex> should be Okay

Made changes to alignment
Made AnyType to AnyInteger for map_type_modifier

clementval added inline comments.Sep 23 2021, 6:16 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
115

Extra line doesn't seem to fit the file format.

230

Extra line doesn't seem to fit the file format.

244

Extra line doesn't seem to fit the file format.

353

What's the purpose of the region on enter data?

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
353

If I am correct, it is defining the region within which the scope exit.

Remove space as mentioned by the reviewer

clementval requested changes to this revision.Sep 24 2021, 5:39 AM
clementval added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
353

I'm pretty sure enter data does not need an attached region. It's a standalone directive so no other operation will be nested inside its region. target exit data does not have one so these two operations are very close and it should be reflected in their MLIR design.

This revision now requires changes to proceed.Sep 24 2021, 5:39 AM
abidmalikwaterloo marked 5 inline comments as done.Oct 18 2021, 6:01 PM

made changes in the data enter operation

clementval added inline comments.Oct 19 2021, 12:08 AM
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
263

There still lines exceeding the 80 characters limit. Can you double check the whole patch so we can approve it.

abidmalikwaterloo marked an inline comment as done.Oct 22 2021, 12:00 PM

Correct indentation for comments

I have kind of lost track on this. Is this up to date and ready to go?

Will try to finalize this week.

Sorry for the delay. Will work on it

Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2022, 8:08 AM
shraiysh added a comment.EditedApr 25 2022, 7:40 PM

Looks okay to me, please wait for Kiran/Valentin's comments. Also, will you be adding assembly format/verifier for this later?

The summary says map clause is not supported but there are map operands in the patch. Can we get these two in sync - we should either update summary or remove map-related operands.

Also, please rebase before further reviews.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
267

please put variables in documentation within backticks(`). This is because when the documentation is rendered on mlir.llvm.org, $ and _ interact to give unexpected text if backticks are not used.

Looks okay to me, please wait for Kiran/Valentin's comments. Also, will you be adding an assembly format/verifier for this later?

Yes

The summary says the map clause is not supported but there are map operands in the patch. Can we get these two in sync - we should either update the summary or remove map-related operands.

Also, please rebase before further reviews.

Will do

Looks okay to me, please wait for Kiran/Valentin's comments. Also, will you be adding an assembly format/verifier for this later?

Yes

The summary says the map clause is not supported but there are map operands in the patch. Can we get these two in sync - we should either update the summary or remove map-related operands.

Also, please rebase before further reviews.

Will do

Do you or did you work on the rest of the lowering to OpenMPIRBuilder/LLVM IR? Might be good to have the broader pictures sometime before designing the operation.

Looks okay to me, please wait for Kiran/Valentin's comments. Also, will you be adding an assembly format/verifier for this later?

Yes

The summary says the map clause is not supported but there are map operands in the patch. Can we get these two in sync - we should either update the summary or remove map-related operands.

Also, please rebase before further reviews.

Will do

Do you or did you work on the rest of the lowering to OpenMPIRBuilder/LLVM IR? Might be good to have the broader pictures sometime before designing the operation.

I put the line of action that we had in mind ( based on the OpenACC translation) in the FLANG meeting with other team members. I will work on the same line. My thinking is to work on translation and see what we need to change in the operation API at this level. But, I will clean and update the patch based on the feedback as it is hanging around too long.

abidmalikwaterloo edited the summary of this revision. (Show Details)May 3 2022, 12:08 PM

Looks okay to me, please wait for Kiran/Valentin's comments. Also, will you be adding an assembly format/verifier for this later?

Yes

The summary says the map clause is not supported but there are map operands in the patch. Can we get these two in sync - we should either update the summary or remove map-related operands.

Also, please rebase before further reviews.

Will do

I have updated the summary.

I have updated the summary.

Do we have any comments on this? I can submit the "assembly format" later. Need the operation definition for the next step : lowering to LLVM IR

Please rebase, I cannot download this patch because it is too old :(

abidmalikwaterloo edited the summary of this revision. (Show Details)

Rebase the patch and clean some formatting as needed

Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 7:21 AM

Minor nits about documentation.

LGTM given that verifier and assembly format will be added soon for each of these as a separate patch soon. Please wait for atleast one more +1.

The OpenMP IRBuilder work does not have to wait for this patch to merge. You can start working on that while keeping this patch as a dependency.

clang/lib/Testing/CMakeLists.txt
6 ↗(On Diff #429235)

nit: Merge conflict. Please remove.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
267

nit: Ping on this comment. The variable names have not been put in backticks and this is going to cause issues with autogenerated documentation.

273

Data mapping is very similar to data privatization. Would it be a good idea to push this to the frontends while we have not concretely decided on openmp dialect privatization/mapping? If you have an idea on how to implement mapping in OpenMP Dialect to LLVM IR maybe we can go ahead with this.

CC @kiranchandramohan for suggestions regarding privatization.

340

It is not clear which element in this list corresponds to which map type. It would be nice if we could either document that here, or have separate operands for each map type. (same for other two constructs too)

shraiysh requested changes to this revision.May 18 2022, 2:15 AM
This revision now requires changes to proceed.May 18 2022, 2:15 AM
clang/lib/Testing/CMakeLists.txt
33 ↗(On Diff #429235)

Are these okay? In D105584 these were not

shraiysh added inline comments.May 26 2022, 7:30 PM
clang/lib/Testing/CMakeLists.txt
33 ↗(On Diff #429235)

No, this is not okay. There is some issue with these patches and I don't know what it is, but these unrelated changes should not be seen here. Thank you for pointing this out :)

abidmalikwaterloo marked 2 inline comments as done.Jun 13 2022, 11:51 AM
abidmalikwaterloo added inline comments.
clang/lib/Testing/CMakeLists.txt
6 ↗(On Diff #429235)

removed

33 ↗(On Diff #429235)

removed them manually

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
273

@kiranchandramohan @raghavendhra I would like to keep it like this! Any comments

340

I feel keeping it in vector makes more sense. I will document it here. As per OpenMP Specifications:
The map-type can be to, from, tofrom, or alloc.

397

will document map type here as wekk

abidmalikwaterloo marked 2 inline comments as done.Jun 13 2022, 5:57 PM
abidmalikwaterloo added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
340

Correction: map_type_modifier can be "always, close, and mapper"

Revised the patcg according to the reviews of the reviewers.
clean the code and add some comments

@abidmalikwaterloo ninja check-mlir is failing with your most upto date patch. Can you please double check?

Thanks!

Update ops.mlir test cases. llvm-lit is working and all tests are passing

Why not adding the assemblyFormat directly for these operations like your patch D105584?

Why not adding the assembly format directly for these operations like your patch D105584?

OK, I will do it!

Added assembly format
changed the type of mape_type_modifier

I just updated the patch. Something went wrong. I used arc diff --update <patch> for uploading. However, it seems it is not comparing the last submitted patch.

@abidmalikwaterloo Can you please check your last patch pushed for review? https://buildkite.com/llvm-project/diff-checks/builds/117796 states it can not apply your patch something to do with usage of diff --update <patch>? Can you please check?

abidmalikwaterloo added a comment.EditedAug 8 2022, 9:53 AM

@abidmalikwaterloo Can you please check your last patch pushed for review? https://buildkite.com/llvm-project/diff-checks/builds/117796 states it can not apply your patch something to do with the usage of diff --update <patch>? Can you please check?

@raghavendhra I tried to correct it but could not figure out the solution. Do you have any? I am not experienced with the phabricator framework. One solution is to submit another patch with all changes till today and abandon this one.

@abidmalikwaterloo Can you please check your last patch pushed for review? https://buildkite.com/llvm-project/diff-checks/builds/117796 states it can not apply your patch something to do with the usage of diff --update <patch>? Can you please check?

@raghavendhra I tried to correct it but could not figure out the solution. Do you have any? I am not experienced with the phabricator framework. One solution is to submit another patch with all changes till today and abandon this one.

Sorry, I am new to phabricator as well. I use "arc diff" to upload my revisions for review after addressing review comments. If no one responds probably I am fine with new review and abandoning this one.

@abidmalikwaterloo Can you please check your last patch pushed for review? https://buildkite.com/llvm-project/diff-checks/builds/117796 states it can not apply your patch something to do with the usage of diff --update <patch>? Can you please check?

@raghavendhra I tried to correct it but could not figure out the solution. Do you have any? I am not experienced with the phabricator framework. One solution is to submit another patch with all changes till today and abandon this one.

Sorry, I am new to phabricator as well. I use "arc diff" to upload my revisions for review after addressing review comments. If no one responds probably I am fine with new review and abandoning this one.

Did you try arc diff --update D105255 from your branch?

@abidmalikwaterloo Can you please check your last patch pushed for review? https://buildkite.com/llvm-project/diff-checks/builds/117796 states it can not apply your patch something to do with the usage of diff --update <patch>? Can you please check?

@raghavendhra I tried to correct it but could not figure out the solution. Do you have any? I am not experienced with the phabricator framework. One solution is to submit another patch with all changes till today and abandon this one.

Sorry, I am new to phabricator as well. I use "arc diff" to upload my revisions for review after addressing review comments. If no one responds probably I am fine with new review and abandoning this one.

Did you try arc diff --update D105255 from your branch?

yes, I tried this. Actually, I updated the patch. through this

@abidmalikwaterloo Can you please check your last patch pushed for review? https://buildkite.com/llvm-project/diff-checks/builds/117796 states it can not apply your patch something to do with the usage of diff --update <patch>? Can you please check?

@raghavendhra I tried to correct it but could not figure out the solution. Do you have any? I am not experienced with the phabricator framework. One solution is to submit another patch with all changes till today and abandon this one.

Sorry, I am new to phabricator as well. I use "arc diff" to upload my revisions for review after addressing review comments. If no one responds probably I am fine with new review and abandoning this one.

Did you try arc diff --update D105255 from your branch?

yes, I tried this. Actually, I updated the patch. through this

The problem is likely that the commit before the commit of this patch is not in tree,

The easiest way is to create a new branch from main and cherry-pick the commit you need for this patch on the top of it. Then you just use arc diff --update and it should work.

[MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR

[MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR

Looks like it's not the complete revision. There are almost no diffs anymore.

[MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR

Looks like it's not the complete revision. There are almost no diffs anymore.

My OS system crashed last week. I am working on it.

clementval resigned from this revision.Nov 2 2022, 1:53 PM
kiranchandramohan resigned from this revision.Nov 3 2022, 10:21 AM
shraiysh resigned from this revision.Aug 25 2023, 4:26 PM