psyclone.domain.common
A package module for domain/common.
Submodules
psyclone.domain.common.algorithm
psyclone.domain.common.extract_driver_creator
psyclone.domain.common.psylayer
- Submodules
- Classes
PSyLoop
PSyLoop.args_filter()
PSyLoop.dag_name
PSyLoop.field
PSyLoop.field_name
PSyLoop.field_space
PSyLoop.gen_mark_halos_clean_dirty()
PSyLoop.has_inc_arg()
PSyLoop.iteration_space
PSyLoop.kernel
PSyLoop.loop_type
PSyLoop.node_str()
PSyLoop.unique_fields_with_halo_reads()
PSyLoop.unique_modified_args()
PSyLoop.valid_loop_types
psyclone.domain.common.transformations
- Submodules
- Classes
Classes
ExtractDriverCreator
: This class provides the functionality to create a driver that
- class psyclone.domain.common.ExtractDriverCreator(integer_type=<psyclone.psyir.symbols.datatypes.ScalarType object>, real_type=<psyclone.psyir.symbols.datatypes.ScalarType object>)
This class provides the functionality to create a driver that reads in extracted data produced by using the PSyData kernel-extraction functionality.
- Parameters:
integer_type (
psyclone.psyir.symbols.ScalarType
) – default scalar integer type to be used for integer variables. Defaults to INTEGER_TYPE.real_type (
psyclone.psyir.symbols.ScalarType
) – default scalar real type to be used for real variables. Defaults to REAL8_TYPE.
Inheritance
- add_all_kernel_symbols(sched, symbol_table, writer=<psyclone.psyir.backend.fortran.FortranWriter object>)
This function adds all symbols used in sched to the symbol table. It uses GOcean-specific knowledge to declare fields and flatten their name.
- Parameters:
sched (
psyclone.psyir.nodes.Schedule
) – the schedule that will be called by this driver program.symbol_table (
psyclone.psyir.symbols.SymbolTable
) – the symbol table to which to add all found symbols.writer (
psyclone.psyir.backend.fortan.FortranWriter
) – a Fortran writer used when flattening a StructureReference.
- Raises:
InternalError – if a non-derived type has an unknown intrinsic type.
InternalError – if an unknown derived type is encountered. At this stage only the dl_esm_inf field type is supported.
- static add_call(program, name, args)
This function creates a call to the subroutine of the given name, providing the arguments. The call will be added to the program and to the symbol table.
- Parameters:
program (
psyclone.psyir.nodes.Routine
) – the PSyIR Routine to which any code must be added. It also contains the symbol table to be used.name (str) – name of the subroutine to call.
args (list of
psyclone.psyir.nodes.Node
) – list of all arguments for the call.
- Raises:
TypeError – if there is a symbol with the specified name defined that is not a RoutineSymbol.
- static add_result_tests(program, output_symbols)
Adds tests to check that all output variables have the expected value.
- Parameters:
program (
psyclone.psyir.nodes.Routine
) – the program to which the tests should be added.output_symbols (list of 2-tuples of
psyclone.psyir.symbols.Symbol
) – a list containing all output variables of the executed code. Each entry in the list is a 2-tuple, containing first the symbol that was computed when executing the kernels, and then the symbol containing the expected values that have been read in from a file.
- create(nodes, read_write_info, prefix, postfix, region_name)
This function uses the PSyIR to create a stand-alone driver that reads in a previously created file with kernel input and output information, and calls the kernels specified in the ‘nodes’ PSyIR tree with the parameters from the file. It returns the file container which contains the driver.
- Parameters:
nodes (list of
psyclone.psyir.nodes.Node
) – a list of nodes.read_write_info (
psyclone.psyir.tools.ReadWriteInfo
) – information about all input and output parameters.prefix (str) – the prefix to use for each PSyData symbol, e.g. ‘extract’ as prefix will create symbols extract_psydata.
postfix (str) – a postfix that is appended to an output variable to create the corresponding variable that stores the output value from the kernel data file. The caller must guarantee that no name clashes are created when adding the postfix to a variable and that the postfix is consistent between extract code and driver code (see ‘ExtractTrans.determine_postfix()’).
region_name ((str,str)) – an optional name to use for this PSyData area, provided as a 2-tuple containing a location name followed by a local name. The pair of strings should uniquely identify a region.
- Returns:
the program PSyIR for a stand-alone driver.
- Return type:
psyclone.psyir.psyir.nodes.FileContainer
- create_flattened_symbol(flattened_name, reference, symbol_table, writer=<psyclone.psyir.backend.fortran.FortranWriter object>)
Takes a reference to a structure and creates a new Symbol of the type that the reference resolves to, e.g. fld%data… will be mapped to real, dimension(:,:), and fld%data$whole%xstart to integer.
- Parameters:
flattened_name (str) – the new ‘flattened’ name to be used for the newly created symbol.
reference (
psyclone.psyir.nodes.StructureReference
) – the reference to a structure.symbol_table (
psyclone.psyir.symbols.SymbolTable
) – the symbol table to use to make sure a unique name is created (based on flattened_name).writer (
psyclone.psyir.backend.language_writer.LanguageWriter
) – a backend visitor to convert the reference into a string, which is then used to find the corresponding gocean-grid-properties.
- Raises:
InternalError – if the structure access is not to a GOCean grid property.
InternalError – if there is no default type defined for the type of the GOCean grid property (defaults are defined in the constructor of this class).
InternalError – if the gocean grid property type is neither ‘array’ nor ‘scalar’.
- Returns:
the new symbol created.
- Return type:
psyclone.psyir.symbol.DataSymbol
- static create_read_in_code(program, psy_data, read_write_info, postfix)
This function creates the code that reads in the NetCDF file produced during extraction. For each:
variable that is read-only, it will declare the symbol and add code that reads in the variable using the PSyData library.
variable that is read and written, it will create code to read in the variable that is read, and create a new variable with the same name and “_post” added which is read in to store the values from the NetCDF file after the instrumented region was executed. In the end, the variable that was read and written should have the same value as the corresponding “_post” variable.
variable that is written only, it will create a variable with “_post” as postfix that reads in the output data from the NetCDF file. It then also declares a variable without postfix (which will be the parameter to the function), allocates it based on the shape of the corresponding “_post” variable, and initialises it with 0.
- Parameters:
program (
psyclone.psyir.nodes.Routine
) – the PSyIR Routine to which any code must be added. It also contains the symbol table to be used.psy_data (
psyclone.psyir.symbols.DataSymbol
) – the PSyData symbol to be used.read_write_info (
psyclone.psyir.tools.ReadWriteInfo
) – information about all input and output parameters.postfix (str) – a postfix that is added to a variable to create the corresponding variable that stores the output value from the kernel data file.
- Returns:
a list with all output parameters, i.e. variables that need to be verified after executing the kernel. Each entry is a 2-tuple containing the symbol of the computed variable, and the symbol of the variable that contains the value read from the file.
- Return type:
list of 2-tuples of
psyclone.psyir.symbols.Symbol
- flatten_reference(old_reference, symbol_table, writer=<psyclone.psyir.backend.fortran.FortranWriter object>)
Replaces old_reference which is a structure type with a new simple Reference and a flattened name (replacing all % with _).
- Parameters:
old_reference (
psyclone.psyir.nodes.StructureReference
) – a reference to a structure member.symbol_table (
psyclone.psyir.symbols.SymbolTable
) – the symbol table to which to add the newly defined flattened symbol.writer (
psyclone.psyir.backend.fortran.FortranWriter
) – a Fortran writer used when flattening a StructureReference.
- static flatten_string(fortran_string)
Replaces all % with _ in the string, creating a ‘flattened’ name.
- Parameters:
fortran_string (str) – the Fortran string containing ‘%’.
- Returns:
a flattened string (all ‘%’ replaced with ‘_’.)
- Return type:
str
- get_driver_as_string(nodes, read_write_info, prefix, postfix, region_name, writer=<psyclone.psyir.backend.fortran.FortranWriter object>)
This function uses create() function to get the PSyIR of a stand-alone driver, and then uses the provided language writer to create a string representation in the selected language (defaults to Fortran).
- Parameters:
nodes (List[
psyclone.psyir.nodes.Node
]) – a list of nodes.read_write_info (
psyclone.psyir.tools.ReadWriteInfo
) – information about all input and output parameters.prefix (str) – the prefix to use for each PSyData symbol, e.g. ‘extract’ as prefix will create symbols extract_psydata.
postfix (str) – a postfix that is appended to an output variable to create the corresponding variable that stores the output value from the kernel data file. The caller must guarantee that no name clashes are created when adding the postfix to a variable and that the postfix is consistent between extract code and driver code (see ‘ExtractTrans.determine_postfix()’).
region_name ((str,str)) – an optional name to use for this PSyData area, provided as a 2-tuple containing a location name followed by a local name. The pair of strings should uniquely identify a region.
language_writer (
psyclone.psyir.backend.language_writer.LanguageWriter
) – a backend visitor to convert PSyIR representation to the selected language. It defaults to the FortranWriter.
- Returns:
the driver in the selected language.
- Return type:
str
- static import_modules(program, sched)
This function adds all the import statements required for the actual kernel calls. It finds all calls in the PSyIR tree and checks for calls with a ImportInterface. Any such call will get a ContainerSymbol added for the module, and a RoutineSymbol with an import interface pointing to this module.
- Parameters:
program (
psyclone.psyir.nodes.Routine
) – the PSyIR Routine to which any code must be added. It also contains the symbol table to be used.sched (
psyclone.psyir.nodes.Schedule
) – the schedule that will be called by the driver program created.
- write_driver(nodes, read_write_info, prefix, postfix, region_name, writer=<psyclone.psyir.backend.fortran.FortranWriter object>)
This function uses the get_driver_as_string() function to get a a stand-alone driver, and then writes this source code to a file. The file name is derived from the region name: “driver-“+module_name+”_”+region_name+”.f90”
- Parameters:
nodes (List[
psyclone.psyir.nodes.Node
]) – a list of nodes.read_write_info (
psyclone.psyir.tools.ReadWriteInfo
) – information about all input and output parameters.prefix (str) – the prefix to use for each PSyData symbol, e.g. ‘extract’ as prefix will create symbols extract_psydata.
postfix (str) – a postfix that is appended to an output variable to create the corresponding variable that stores the output value from the kernel data file. The caller must guarantee that no name clashes are created when adding the postfix to a variable and that the postfix is consistent between extract code and driver code (see ‘ExtractTrans.determine_postfix()’).
region_name ((str,str)) – an optional name to use for this PSyData area, provided as a 2-tuple containing a location name followed by a local name. The pair of strings should uniquely identify a region.
language_writer (
psyclone.psyir.backend.language_writer.LanguageWriter
) – a backend visitor to convert PSyIR representation to the selected language. It defaults to the FortranWriter.