In contrast to general-purpose programming languages like C or Fortran, domain-specific languages (DSLs) are tailored to a specific application domain, for example weather and climate modelling. Two such DSLs are PSyclone and DAWN, which are being further developed by UKRI / STFC and MeteoSwiss in the scope of the ESiWACE project. They allow scientists to port their model codes more easily to new hardware, for example to central processing units (CPUs) or to different kinds of graphics processing units (GPUs). They also facilitate optimisation and parallelisation on different machines. With these capabilities, PSyclone and DAWN support weather and climate models in their transition to exascale by offering improved maintainability of the science code and the possibility of performance portability across different classes of computer architecture.

Two DSLs for different types of model code


A natural question to ask is why there needs to be more than one DSL for the same specific application domain, in our case for weather and climate modelling.

One answer to this is that each of the two DSLs, further developed within ESiWACE, takes quite a different approach. PSyclone is designed to support existing and new Fortran codes, whereas DAWN is designed to support codes written in a higher level domain-specific language. These higher level DSLs have been developed within the scope of the ESCAPE-2 project to fit the needs of different climate models. One of those high level domain-specific languages is DUSK, developed by MeteoSwiss.
Another answer is that the two DSLs support different types of climate and weather models. PSyclone, for example, supports LFRic, which is a mixed finite element code on an unstructured horizontal mesh, while DAWN supports ICON, which is a finite volume code on an icosahedral mesh.

Fostering synergies


O
ur DSLs thus have different strengths, and are essentially complementary.

However, this does not mean that they cannot benefit from one another, and ESiWACE researchers have been exploring a potential interoperability between those two. One type of code that PSyclone and DAWN both support is structured finite difference code. The ocean model NEMO is an important example, which is widely used in the community. Therefore a part of the NEMO code, modelling advection of temperature and salinity, was chosen as a use case.
Both DSLs translate code into a language-independent intermediate representation. From this stage they are able to produce several modified model codes using different kinds of languages or programming standards, tailored to a desired computer architecture and the desired degree of optimisation.
To execute the NEMO advection code on NVIDIA GPUs, PSyclone takes the unmodified code and automatically adds OpenACC directives (see figure, left side). For DAWN the code has to be translated manually into its high level DSL language DUSK so that DAWN can then output optimised CUDA code (see figure, middle). As CUDA is often more efficient than OpenACC, there is a potential performance advantage in using CUDA. 

Don’t you think it would be great if PSyclone and DAWN could be linked together to allow unmodified NEMO code to be translated to optimised CUDA code? - Well, it turns out that this is possible!

DSLs_inESiWACE.png
Transformation schemes of the NEMO advection code by the DSLs PSyclone, DAWN with DUSK and the newly developed
combination of PSyclone with DAWN. All schemes result in code versions that can run on NVIDIA GPUs.

Within the scope of ESiWACE, a new PSyclone backend has been developed, which translates from PSyclone’s internal model code representation to the internal representation of DAWN. With some additional PSyclone transformations to slightly restructure the input code, PSyclone is able to take the NEMO tracer advection code and translate it to DAWN’s intermediate code representation. From this, DAWN is able to output optimised CUDA code that produces results matching those obtained with the original Fortran code. This interoperability between the two weather and climate DSLs successfully combines the strengths of both (see the right side of the figure).

Rupert Ford (UKRI / STFC), Julia Duras (DKRZ), Matthias Roethlin (MeteoSwiss)


Photo source: pexels.com