Skip to content

Commit

Permalink
Updates after PSyclone main repository sync and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Maurice Jamieson committed May 30, 2024
1 parent b136831 commit 459bc69
Show file tree
Hide file tree
Showing 3 changed files with 967 additions and 0 deletions.
95 changes: 95 additions & 0 deletions examples/xdsl/benchmarks/pw_advection/advection_mpi.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
subroutine main()
use mpi
use timer
real*8, dimension(:,:,:), allocatable :: su, sv, sw, u, v, w
real*8, dimension(:), allocatable :: tzc1, tzc2, tzd1, tzd2
integer :: k, j, i, nx, ny, nz, rank
integer :: itimer0, itimer1, mpi_err

call MPI_Init(mpi_err)

rank=MPI_CommRank()

nx=256
ny=512
nz=256

allocate(su(nz, ny, nx))
allocate(sv(nz, ny, nx))
allocate(sw(nz, ny, nx))
allocate(u(nz, ny, nx))
allocate(v(nz, ny, nx))
allocate(w(nz, ny, nx))
allocate(tzc1(nz))
allocate(tzc2(nz))
allocate(tzd1(nz))
allocate(tzd2(nz))

!itimer0 = setup_timer()

if (rank == 0) then
!call timer_init()
!call timer_start(itimer0, label='Initialise')
end if

do i=1, nx
do j=1, ny
do k=1, nz
u(k,j,i)=10.0
v(k,j,i)=20.0
w(k,j,i)=30.0
end do
end do
end do

do k=1, nz
tzc1(k)=50.0
tzc2(k)=15.0
tzd1(k)=100.0
tzd2(k)=5.0
end do

if (rank == 0) then
!call timer_stop(itimer0)
!call timer_start(itimer1, label='Compute')
end if

do i=2,nx-1
do j=2,ny-1
do k=2,nz-1
su(k, j, i)=&
(2.0*(u(k, j, i-1)*(u(k, j, i)+u(k, j, i-1))-u(k, j, i+1)*(u(k, j, i)+u(k, j, i+1)))) + &
(1.0*(u(k, j-1, i)*(v(k, j-1, i)+v(k, j-1, i+1))-u(k, j+1, i)*(v(k, j, i)+v(k, j, i+1)))) + &
(tzc1(k)*u(k-1, j, i)*(w(k-1, j, i)+w(k-1, j, i+1))-tzc2(k)*u(k+1, j, i)*(w(k, j, i)+w(k, j, i+1)))

sv(k, j, i)=&
(2.0*(v(k, j-1, i)*(v(k, j, i)+v(k, j-1, i))-v(k, j+1, i)*(v(k, j, i)+v(k, j+1, i)))) + &
(2.0*(v(k, j, i-1)*(u(k, j, i-1)+u(k, j+1, i-1))-v(k, j, i+1)*(u(k, j, i)+u(k, j+1, i)))) + &
(tzc1(k)*v(k-1, j, i)*(w(k-1, j, i)+w(k-1, j+1, i))-tzc2(k)*v(k+1, j, i)*(w(k, j, i)+w(k, j+1, i)))

sw(k, j, i)=&
(tzd1(k)*w(k-1, j, i)*(w(k, j, i)+w(k-1, j, i))-tzd2(k)*w(k+1, j, i)*(w(k, j, i)+w(k+1, j, i))) + &
(2.0*(w(k, j, i-1)*(u(k, j, i-1)+u(k+1, j, i-1))-w(k, j, i+1)*(u(k, j, i)+u(k+1, j, i)))) + &
(2.0*(w(k, j-1, i)*(v(k, j-1, i)+v(k+1, j-1, i))-w(k, j+1, i)*(v(k, j, i)+v(k+1, j, i))))
end do
end do
end do

if (rank == 0) then
!call timer_stop(itimer1)
!call timer_report()
end if

deallocate(su)
deallocate(sv)
deallocate(sw)
deallocate(u)
deallocate(v)
deallocate(w)
deallocate(tzc1)
deallocate(tzc2)
deallocate(tzd1)
deallocate(tzd2)

call MPI_Finalize()
end subroutine main
62 changes: 62 additions & 0 deletions examples/xdsl/xdsl_backends_transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -----------------------------------------------------------------------------
# BSD 3-Clause License
#
# Copyright (c) 2018-2022, Science and Technology Facilities Council.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------

from __future__ import print_function
import sys
from psyclone.psyir.backend.xdsl import xDSLWriter
from xdsl.printer import Printer
from xdsl.dialects.builtin import ModuleOp


def trans(psy):
writer = xDSLWriter()
printer = Printer(stream=sys.stdout)

routine_list = []
for invoke in psy.invokes.invoke_list:
sched = invoke.schedule

routine_list.append(writer(sched))

top_level = ModuleOp(routine_list)
printer.print_op(top_level)

f = open("psy_output.mlir", "w")
p2 = Printer(stream=f)
p2.print_op(top_level)
f.close()

print("")
print("")
print("")
Loading

0 comments on commit 459bc69

Please sign in to comment.