psyclone.psyir.transformations.increase_rank_loop_arrays_trans#

This module contains the IncreaseRankLoopArrays transformation.

Classes#

class psyclone.psyir.transformations.increase_rank_loop_arrays_trans.IncreaseRankLoopArraysTrans[source]#

This transformation takes a loop and a list of arrays accessed inside the loop, and increases those arrays with an additional dimension with the size of the interation space. Then it indexes all accesses with the loop variable, so that each iteration accesses a unique location. Effectively making the sub-array private for each iteration of the loop. It also indexes assignments outside the loop to iterate over the whole new rank.

>>> from psyclone.psyir.backend.fortran import FortranWriter
>>> from psyclone.psyir.frontend.fortran import FortranReader
>>> from psyclone.psyir.nodes import Loop
>>> from psyclone.psyir.transformations import IncreaseRankLoopArraysTrans
>>> code = ("""
... program test
...     integer :: N=10, M=10
...     integer :: i, j
...     real, dimension(N) :: ztmp
...     ! (Array) Assignments to the target variable outside the loop are
...     ! permited, but any other use will not pass the validation
...     ztmp = 0
...     ztmp(0) = 1
...     do i = -5, M + 3
...         do j = 1, N
...             ztmp(j) = 1
...         end do
...         do j = 1, N
...             ztmp(j) = ztmp(j) + 1
...         end do
...     end do
... end program
... """)
>>> psyir = FortranReader().psyir_from_source(code)
>>> irla = IncreaseRankLoopArraysTrans()
>>> irla.apply(psyir.walk(Loop)[0], arrays=['ztmp'])
>>> print(FortranWriter()(psyir))
program test
  integer, save :: n = 10
  integer, save :: m = 10
  integer :: i
  integer :: j
  real, dimension(n,-5:m + 3) :: ztmp

  ztmp = 0
  ztmp(0,:) = 1
  do i = -5, m + 3, 1
    do j = 1, n, 1
      ztmp(j,i) = 1
    enddo
    do j = 1, n, 1
      ztmp(j,i) = ztmp(j,i) + 1
    enddo
  enddo

end program test

Inheritance

Inheritance diagram of IncreaseRankLoopArraysTrans
apply(node, arrays=None, **kwargs)[source]#

Applies the transformation.

Parameters:
  • node (Loop) – target Loop node.

  • arrays (Optional[list[Union[Symbol, str]]]) – list of arrays that will have their rank increased.

validate(node, **kwargs)[source]#

Checks that the supplied node is a valid target.

Parameters:
Raises: