Skip to content

(Closes #3330) MetaTransformation for OpenMPCPURoutineTrans#3345

Draft
LonelyCat124 wants to merge 2 commits intomasterfrom
3330_meta_transform
Draft

(Closes #3330) MetaTransformation for OpenMPCPURoutineTrans#3345
LonelyCat124 wants to merge 2 commits intomasterfrom
3330_meta_transform

Conversation

@LonelyCat124
Copy link
Collaborator

@LonelyCat124 LonelyCat124 commented Feb 23, 2026

Initial implementation which is very bare bones and unfinished. I got a bit confused with inheritance, and there are still various issues with this.

Things that I was hoping would work, e.g. using superclasses validate/apply methods is a bit messy due to the MRO, since super().apply(...) does result in a call to self.validate() which doesn't work if this has any type checking in its own validate function.

I can work around this by making it's own validate function do very little and manually calling each superclasses inherited functionality.

The alternative (and potentially neater way to do it) is to only define the inherited classes for the purposes of validating available options and having documentation fixes (potentially with other improvements) but then create instances of the superclasses as required. The issue with this is pulling out the appropriate options for each superclass (as the option validation would no longer work for just passing in all options)

I'm also not entirely sure how __init__ works on this class right now, I think it will just use OMPLoopTrans, but I'm not sure I even want the user to have the option to change that, so I should potentially override __init__ to not allow these options to be changed.

I will show its current "working state" in the next post.

@sergisiso @arporter Do either of you have thoughts on a best direction for this?

Edit:
I also havd to make a change in the Transformation base class to never fail on the "options" kwarg, as this could be being provided to the class by some superclass call and then breaking valid options checking in a different base classes' superclass. It was a bit weird, but is a problem of options still being defined on some classes but not newer ones.

@LonelyCat124
Copy link
Collaborator Author

LonelyCat124 commented Feb 23, 2026

Input Fortran:

Program x
    integer, dimension(1:5, 1:5) :: a
    integer, dimension(1:3) :: b
    integer :: i, j

    do i = 1, 5
      do j = 1, 5
         a(i,j) = i * j
      end do
    end do

    do i = 1, 3
        b(i) = i
    end do

    a(1:3, 1) = a(1:3, 1) + b(1:3)

    end program x

Psyclone script:

from psyclone.psyir.transformations.metatransformations.omp_cpu_routine_trans import OpenMPCPURoutineTrans
from psyclone.psyir.nodes import Routine


def trans(psyir):

    routines = psyir.walk(Routine)

    OpenMPCPURoutineTrans().apply(routines[0], nowait=True)

Output:

program x
  integer, dimension(5,5) :: a
  integer, dimension(3) :: b
  integer :: i
  integer :: j

  !$omp parallel default(shared) private(i,j)
  !$omp do schedule(auto)
  do i = 1, 5, 1
    do j = 1, 5, 1
      a(i,j) = i * j
    enddo
  enddo
  !$omp end do nowait
  !$omp do schedule(auto)
  do i = 1, 3, 1
    b(i) = i
  enddo
  !$omp end do nowait
  !$omp end parallel
  a(:3,1) = a(:3,1) + b(:)

end program x

You can also set nowait=False (or disable it) and get a corresponding result.

@LonelyCat124 LonelyCat124 self-assigned this Feb 23, 2026
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 45.16129% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.92%. Comparing base (214ae5a) to head (4d909ee).

Files with missing lines Patch % Lines
...tions/metatransformations/omp_cpu_routine_trans.py 37.03% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3345      +/-   ##
==========================================
- Coverage   99.95%   99.92%   -0.04%     
==========================================
  Files         384      385       +1     
  Lines       54214    54241      +27     
==========================================
+ Hits        54192    54202      +10     
- Misses         22       39      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant