diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 08ac288d..8107881b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -142,13 +142,10 @@ test_gnu: - pip install seaborn - pip install yt - cd $MILHOJA_CODE_REPO/tools/sedov_pypkg - - python setup.py test - - python setup.py sdist && cd dist - - pip install $(ls sedov-*.tar.gz) + - pip install . - python -c 'import sedov ; sedov.print_versions()' - cd $MILHOJA_CODE_REPO/tools/milhoja_pypkg - - python setup.py sdist && cd dist - - pip install $(ls milhoja-*.tar.gz) + - pip install . ##-- Check python virtual environment - pip list - $MILHOJA_CODE_REPO/tools/test_milhoja_installation.py -v 2 diff --git a/src/Milhoja_TileFlashxr.cpp b/src/Milhoja_TileFlashxr.cpp index 1b446aa5..aaad302d 100644 --- a/src/Milhoja_TileFlashxr.cpp +++ b/src/Milhoja_TileFlashxr.cpp @@ -34,7 +34,7 @@ TileFlashxr::TileFlashxr(const FlashxrTileRawPtrs tP, const FlashxTileRawInts tI, const FlashxTileRawReals tR) : Tile{}, - level_{static_cast(tI.level)}, + level_{static_cast(tI.level - 1)}, // 1-based Flash-X convention -> 0-based gridIdxOrBlkId_{tI.gridIdxOrBlkId}, tileIdx_{tI.tileIdx}, lo_{LIST_NDIM(tI.loX,tI.loY,tI.loZ)}, diff --git a/test/Base/code_generation/Analysis_op1.json b/test/Base/code_generation/Analysis_op1.json index 3c4b4519..ec11d716 100644 --- a/test/Base/code_generation/Analysis_op1.json +++ b/test/Base/code_generation/Analysis_op1.json @@ -20,7 +20,7 @@ "hi": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2]}, + "r": [1, 2]}, "idx": {"source": "tile_gridIndex"} } } diff --git a/test/Base/code_generation/Math_op1.json b/test/Base/code_generation/Math_op1.json index 6c24108e..4cfd7dcd 100644 --- a/test/Base/code_generation/Math_op1.json +++ b/test/Base/code_generation/Math_op1.json @@ -18,7 +18,7 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [1]}, + "rw": [1]}, "scratch": {"source": "scratch", "name": "_scratch3D"}, "deltas": {"source": "tile_deltas"} @@ -32,7 +32,7 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [2]}, + "rw": [2]}, "scratch": {"source": "scratch", "name": "_scratch3D"}, "deltas": {"source": "tile_deltas"} @@ -46,7 +46,7 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [1, 2]}, + "rw": [1, 2]}, "scratch": {"source": "scratch", "name": "_scratch4D"}, "deltas": {"source": "tile_deltas"} diff --git a/test/Base/code_generation/Simulation_op1.json b/test/Base/code_generation/Simulation_op1.json index ecb293ad..e22c8622 100644 --- a/test/Base/code_generation/Simulation_op1.json +++ b/test/Base/code_generation/Simulation_op1.json @@ -20,7 +20,7 @@ "hi": "tile_ubound"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "W": [1, 2]} + "w": [1, 2]} } } } diff --git a/test/Grid/general/code_generation/Simulation_op1.json b/test/Grid/general/code_generation/Simulation_op1.json index ecb293ad..e22c8622 100644 --- a/test/Grid/general/code_generation/Simulation_op1.json +++ b/test/Grid/general/code_generation/Simulation_op1.json @@ -20,7 +20,7 @@ "hi": "tile_ubound"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "W": [1, 2]} + "w": [1, 2]} } } } diff --git a/test/Sedov/code_generation/Hydro_op1.json b/test/Sedov/code_generation/Hydro_op1.json index f3912a2d..9e8771ce 100644 --- a/test/Sedov/code_generation/Hydro_op1.json +++ b/test/Sedov/code_generation/Hydro_op1.json @@ -31,16 +31,16 @@ "deltas": {"source": "tile_deltas"}, "Uin": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6, 9]}, + "r": [1, 2, 3, 4, 5, 6, 9]}, "flX": {"source": "grid_data", "structure_index": ["FLUXX", 1], - "W": [1, 2, 3, 4, 5]}, + "w": [1, 2, 3, 4, 5]}, "flY": {"source": "grid_data", "structure_index": ["FLUXY", 1], - "W": [1, 2, 3, 4, 5]}, + "w": [1, 2, 3, 4, 5]}, "flZ": {"source": "grid_data", "structure_index": ["FLUXZ", 1], - "W": [1, 2, 3, 4, 5]}, + "w": [1, 2, 3, 4, 5]}, "auxC": {"source": "scratch", "name": "_auxC"} } @@ -53,17 +53,17 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [1, 2, 3, 4, 6], - "W": [8]}, + "rw": [1, 2, 3, 4, 6], + "w": [8]}, "flX": {"source": "grid_data", "structure_index": ["FLUXX", 1], - "R": [1, 2, 3, 4, 5]}, + "r": [1, 2, 3, 4, 5]}, "flY": {"source": "grid_data", "structure_index": ["FLUXY", 1], - "R": [1, 2, 3, 4, 5]}, + "r": [1, 2, 3, 4, 5]}, "flZ": {"source": "grid_data", "structure_index": ["FLUXZ", 1], - "R": [1, 2, 3, 4, 5]} + "r": [1, 2, 3, 4, 5]} } }, "Eos::idealGammaDensIe": { @@ -74,8 +74,8 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 8], - "W": [5, 7]} + "r": [1, 8], + "w": [5, 7]} } }, "hy::computeSoundSpeedHll_oacc_summit": { @@ -86,7 +86,7 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 5, 9]}, + "r": [1, 5, 9]}, "auxC": {"source": "scratch", "name": "_auxC"} } @@ -102,7 +102,7 @@ "deltas": {"source": "tile_deltas"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6]}, + "r": [1, 2, 3, 4, 5, 6]}, "flX": {"source": "scratch", "name": "_flX"}, "auxC": {"source": "scratch", @@ -120,7 +120,7 @@ "deltas": {"source": "tile_deltas"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6]}, + "r": [1, 2, 3, 4, 5, 6]}, "flY": {"source": "scratch", "name": "_flY"}, "auxC": {"source": "scratch", @@ -138,7 +138,7 @@ "deltas": {"source": "tile_deltas"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6]}, + "r": [1, 2, 3, 4, 5, 6]}, "flZ": {"source": "scratch", "name": "_flZ"}, "auxC": {"source": "scratch", @@ -153,8 +153,8 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [1, 2, 3, 4, 6], - "W": [8]}, + "rw": [1, 2, 3, 4, 6], + "w": [8]}, "flX": {"source": "scratch", "name": "_flX"}, "flY": {"source": "scratch", @@ -171,8 +171,8 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 8], - "W": [5, 7]} + "r": [1, 8], + "w": [5, 7]} } } } diff --git a/test/Sedov/code_generation/Io_op1.json b/test/Sedov/code_generation/Io_op1.json index 7aa83dc6..edf29be5 100644 --- a/test/Sedov/code_generation/Io_op1.json +++ b/test/Sedov/code_generation/Io_op1.json @@ -14,7 +14,7 @@ "hi": "tile_hi"}, "solnData": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 6, 8]} + "r": [1, 2, 3, 4, 6, 8]} } } } diff --git a/test/Sedov/code_generation/Simulation_op1.json b/test/Sedov/code_generation/Simulation_op1.json index 35e1ec4f..692978fe 100644 --- a/test/Sedov/code_generation/Simulation_op1.json +++ b/test/Sedov/code_generation/Simulation_op1.json @@ -29,7 +29,7 @@ "deltas": {"source": "tile_deltas"}, "solnData": {"source": "grid_data", "structure_index": ["CENTER", 1], - "W": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]} + "w": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]} } }, "Eos::idealGammaDensIe": { @@ -40,8 +40,8 @@ "hi": {"source": "tile_ubound"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 8], - "W": [5, 7]} + "r": [1, 8], + "w": [5, 7]} } } } diff --git a/tools/milhoja_pypkg/VERSION b/tools/milhoja_pypkg/VERSION index 81340c7e..bbdeab62 100644 --- a/tools/milhoja_pypkg/VERSION +++ b/tools/milhoja_pypkg/VERSION @@ -1 +1 @@ -0.0.4 +0.0.5 diff --git a/tools/milhoja_pypkg/docs/source/developers_guide.rst b/tools/milhoja_pypkg/docs/source/developers_guide.rst index e30dbba0..62e06074 100644 --- a/tools/milhoja_pypkg/docs/source/developers_guide.rst +++ b/tools/milhoja_pypkg/docs/source/developers_guide.rst @@ -378,7 +378,35 @@ name of the item, followed by the suffix '_d'. Code Generation Interface ------------------------- -.. autoclass:: milhoja.TileWrapperGenerator_cpp + +Code Generation classes contained inside of the code generation interface follow +a loose naming pattern that determines what language and device the code is generated +for. The general format is as follows: + +`[object][_device][_language]` + +Where the `[object]` is the type of object being generated, either `DataPacket` +or `TileWrapper`. The `[_device]` is the device that the generated code will run +on, either `cpu` for running on the cpu, or the tpye of offloading to use if the +gpu is being used. Finally, the `[_language]` is the language that the code is +generated for. For example, `TaskFunctionC2FGenerator_OpenACC_F` is a class +for generating the C2F layer for TaskFunctions, with code that runs on the GPU +with OpenACC offloading, generated for fortran code. + +Since this is just a 'loose' rule, there are a few exceptions to this. The +TileWrapperGenerator class and the DataPacketGenerator class hide any language specific +generation rules inside of themselves, so there are no separate generators for language +or device specific data items. Generally, TileWrappers are only used on CPUs, so +there is no need to specify the device. TileWrappers are also compatible with both +Fortran & C++ Task Functions without extra modifications. DataPackets are designed +in a similar way, however, the generated code is not necessarily compatible with +both C++ and Fortran Task Functions (this will likely change in the future), and +DataPackets are primarily used for offloading purposes. The last exceptions are the +`DataPacketModGenerator` and the `TileWrapperModGenerator`, which exist to generate +fortran module interface files for use with the TaskFunction, therefore there is +no need to specify the language or device/offloading inside of the file name. + +.. autoclass:: milhoja.TileWrapperGenerator :members: .. autoclass:: milhoja.TileWrapperModGenerator :members: @@ -392,5 +420,9 @@ Code Generation Interface :members: .. autoclass:: milhoja.TaskFunctionC2FGenerator_cpu_F :members: +.. autoclass:: milhoja.TaskFunctionC2FGenerator_OpenACC_F + :members: .. autoclass:: milhoja.TaskFunctionCpp2CGenerator_cpu_F - :members: \ No newline at end of file + :members: +.. autoclass:: milhoja.TaskFunctionCpp2CGenerator_OpenACC_F + :members: diff --git a/tools/milhoja_pypkg/src/milhoja/DataPacketGenerator.py b/tools/milhoja_pypkg/src/milhoja/DataPacketGenerator.py index 9a9ff2b7..cef1f80e 100644 --- a/tools/milhoja_pypkg/src/milhoja/DataPacketGenerator.py +++ b/tools/milhoja_pypkg/src/milhoja/DataPacketGenerator.py @@ -7,9 +7,6 @@ from .parse_helpers import parse_extents from .generate_packet_file import generate_packet_file -from .Cpp2CLayerGenerator import Cpp2CLayerGenerator -from .C2FortranLayerGenerator import C2FortranLayerGenerator -from .DataPacketC2FModuleGenerator import DataPacketC2FModuleGenerator from .FortranTemplateUtility import FortranTemplateUtility from .CppTemplateUtility import CppTemplateUtility from .AbcCodeGenerator import AbcCodeGenerator @@ -35,9 +32,6 @@ def __init__( self, tf_spec: TaskFunction, indent: int, logger: BasicLogger, sizes: dict ): - if not isinstance(tf_spec, TaskFunction): - raise TypeError("TF Spec was not derived from task function.") - self._TOOL_NAME = "Milhoja DataPacket" self._sizes = deepcopy(sizes) self._indent = indent @@ -230,28 +224,6 @@ def generate_source_code(self, destination, overwrite): ) self._log("Done", LOG_LEVEL_BASIC_DEBUG) - if self._tf_spec.language.lower() == "fortran": - # dirty hack for fixing the test suite. In reality, this code - # should be moved outside of the data packet generator and into - # the task function generator. - self.cpp2c_layer = Cpp2CLayerGenerator( - self._tf_spec, self._indent, self._logger - ) - self.cpp2c_layer.generate_source_code(destination, overwrite) - - # generate fortran to c layer if necessary - self.c2f_layer = C2FortranLayerGenerator( - self._tf_spec, self._indent, self._logger - ) - # c2f layer does not use cgkit so no need - # to call generate_packet_file - self.c2f_layer.generate_source_code(destination, overwrite) - - self.dp_module = DataPacketC2FModuleGenerator( - self._tf_spec, self._indent, self._logger - ) - self.dp_module.generate_source_code(destination, overwrite) - @property def language(self): return self._tf_spec.language.lower() diff --git a/tools/milhoja_pypkg/src/milhoja/DataPacketC2FModuleGenerator.py b/tools/milhoja_pypkg/src/milhoja/DataPacketModGenerator.py similarity index 99% rename from tools/milhoja_pypkg/src/milhoja/DataPacketC2FModuleGenerator.py rename to tools/milhoja_pypkg/src/milhoja/DataPacketModGenerator.py index 4ebaf820..9935fbbe 100644 --- a/tools/milhoja_pypkg/src/milhoja/DataPacketC2FModuleGenerator.py +++ b/tools/milhoja_pypkg/src/milhoja/DataPacketModGenerator.py @@ -7,13 +7,12 @@ from . import LOG_LEVEL_BASIC -class DataPacketC2FModuleGenerator(AbcCodeGenerator): +class DataPacketModGenerator(AbcCodeGenerator): """ Responsible for generating the module interface file for use by the fortran task function and interoperability layers. Nothing is generated for C++ based task functions. """ - # C2F Module generator uses its own specific type mapping for the # fortran interface. _TYPE_MAPPING = { diff --git a/tools/milhoja_pypkg/src/milhoja/TaskFunctionAssembler.py b/tools/milhoja_pypkg/src/milhoja/TaskFunctionAssembler.py index 6f8cc585..88369b6f 100644 --- a/tools/milhoja_pypkg/src/milhoja/TaskFunctionAssembler.py +++ b/tools/milhoja_pypkg/src/milhoja/TaskFunctionAssembler.py @@ -17,7 +17,8 @@ TILE_FACE_AREAS_ARGUMENT, TILE_CELL_VOLUMES_ARGUMENT, TILE_ARGUMENTS_ALL, - THREAD_INDEX_ARGUMENT, THREAD_INDEX_VAR_NAME + THREAD_INDEX_ARGUMENT, THREAD_INDEX_VAR_NAME, + READ, WRITE, READ_WRITE, ACCESS_KEYS ) from .LogicError import LogicError from .AbcLogger import AbcLogger @@ -39,7 +40,7 @@ class TaskFunctionAssembler(object): * internal_call_graph is used here and in TaskFunction. It should likely become a class that checks the quality of the graph. * Milhoja should have an internal parser that can figure out the - R/W/RW status of each variable of the grid data arrays in each + r/w/rw status of each variable of the grid data arrays in each subroutine in the internal call graph. * Very low-priority optimization is determine if a scratch variable for one subroutine can double as scratch variable for another @@ -525,7 +526,7 @@ def determine_access_patterns(self): :return: Doubly-nested dict. First key is dummy argument; second, variable name. Each value is the ordered list of access patterns. - A result of ["R", "RW", "W", "R"] indicates that as the subroutines + A result of ["r", "rw", "w"] indicates that as the subroutines are executed in correct order, the variable was first read from, then written two a few times, and finally read from. """ @@ -536,7 +537,7 @@ def determine_access_patterns(self): if tf_dummy not in accesses: accesses[tf_dummy] = {} - for access in ["R", "RW", "W"]: + for access in ACCESS_KEYS: if access in arg_spec: for idx in arg_spec[access]: if idx not in accesses[tf_dummy]: @@ -575,13 +576,13 @@ def determine_variable_masks(self, variable_accesses): vars_in = set() vars_out = set() for variable, accesses in variables_all.items(): - assert all([e in ["R", "RW", "W"] for e in accesses]) - if accesses[0] in ["R", "RW"]: + assert all([e in ACCESS_KEYS for e in accesses]) + if accesses[0] in [READ, READ_WRITE]: vars_in.add(variable) else: vars_out.add(variable) - if any([e in ["RW", "W"] for e in accesses]): + if any([e in [READ_WRITE, WRITE] for e in accesses]): vars_out.add(variable) assert dummy not in masks @@ -629,13 +630,13 @@ def __get_grid_data(self): dummy_to_actuals[tf_dummy] = [] dummy_to_actuals[tf_dummy].append(arg_index) - # ----- REPLACE R/RW/W INFO WITH VARIABLE MASKS + # ----- REPLACE r/rw/w INFO WITH VARIABLE MASKS # tf_dummy_spec values are set to deep copies, so we can change below # without altering original specifications variable_accesses = self.determine_access_patterns() variable_masks = self.determine_variable_masks(variable_accesses) for dummy in tf_dummy_spec: - for each in ["R", "RW", "W"]: + for each in ACCESS_KEYS: if each in tf_dummy_spec[dummy]: del tf_dummy_spec[dummy][each] diff --git a/tools/milhoja_pypkg/src/milhoja/C2FortranLayerGenerator.py b/tools/milhoja_pypkg/src/milhoja/TaskFunctionC2FGenerator_OpenACC_F.py similarity index 99% rename from tools/milhoja_pypkg/src/milhoja/C2FortranLayerGenerator.py rename to tools/milhoja_pypkg/src/milhoja/TaskFunctionC2FGenerator_OpenACC_F.py index 961eb061..5cfcf987 100644 --- a/tools/milhoja_pypkg/src/milhoja/C2FortranLayerGenerator.py +++ b/tools/milhoja_pypkg/src/milhoja/TaskFunctionC2FGenerator_OpenACC_F.py @@ -45,7 +45,7 @@ def fname(self): return f"F_{self.name}" -class C2FortranLayerGenerator(AbcCodeGenerator): +class TaskFunctionC2FGenerator_OpenACC_F(AbcCodeGenerator): """ C to Fortran layer generator. Should only be used internally with the DataPacketGenerator. @@ -80,7 +80,7 @@ def __init__(self, tf_spec, indent, logger): super().__init__( tf_spec, "", tf_spec.output_filenames[TaskFunction.C2F_KEY]["source"], - indent, "Milhoja C2F Generator", logger + indent, "Milhoja Task Function C2F Generator OpenACC F", logger ) self.INDENT = " " * indent diff --git a/tools/milhoja_pypkg/src/milhoja/Cpp2CLayerGenerator.py b/tools/milhoja_pypkg/src/milhoja/TaskFunctionCpp2CGenerator_OpenACC_F.py similarity index 99% rename from tools/milhoja_pypkg/src/milhoja/Cpp2CLayerGenerator.py rename to tools/milhoja_pypkg/src/milhoja/TaskFunctionCpp2CGenerator_OpenACC_F.py index 889fcbe0..d8fc8d3c 100644 --- a/tools/milhoja_pypkg/src/milhoja/Cpp2CLayerGenerator.py +++ b/tools/milhoja_pypkg/src/milhoja/TaskFunctionCpp2CGenerator_OpenACC_F.py @@ -13,7 +13,7 @@ ) -class Cpp2CLayerGenerator(AbcCodeGenerator): +class TaskFunctionCpp2CGenerator_OpenACC_F(AbcCodeGenerator): """ C++ to C layer generator for Data Packets. Should only be used internally by the DataPacketGenerator. diff --git a/tools/milhoja_pypkg/src/milhoja/TaskFunctionGenerator_OpenACC_F.py b/tools/milhoja_pypkg/src/milhoja/TaskFunctionGenerator_OpenACC_F.py index 6b4b73ab..e1d2738a 100644 --- a/tools/milhoja_pypkg/src/milhoja/TaskFunctionGenerator_OpenACC_F.py +++ b/tools/milhoja_pypkg/src/milhoja/TaskFunctionGenerator_OpenACC_F.py @@ -201,6 +201,7 @@ def generate_source_code(self, destination, overwrite): intent = "OUT" else: raise LogicError("Unknown grid data variable class") + fptr.write(f"{INDENT*2}real, intent({intent}) :: {arg}_d(:, :, :, :, :)\n") elif src == SCRATCH_ARGUMENT: @@ -209,7 +210,7 @@ def generate_source_code(self, destination, overwrite): assert dimension > 0 tmp = [":" for _ in range(dimension + 1)] array = "(" + ", ".join(tmp) + ")" - fptr.write(f"{INDENT*2}{arg_type}, intent(IN) :: {arg}_d{array}\n") + fptr.write(f"{INDENT*2}{arg_type}, intent(INOUT) :: {arg}_d{array}\n") else: raise LogicError(f"{arg} of unknown argument class") diff --git a/tools/milhoja_pypkg/src/milhoja/TileWrapperGenerator_cpp.py b/tools/milhoja_pypkg/src/milhoja/TileWrapperGenerator.py similarity index 99% rename from tools/milhoja_pypkg/src/milhoja/TileWrapperGenerator_cpp.py rename to tools/milhoja_pypkg/src/milhoja/TileWrapperGenerator.py index 9f1d2b54..60caec2f 100644 --- a/tools/milhoja_pypkg/src/milhoja/TileWrapperGenerator_cpp.py +++ b/tools/milhoja_pypkg/src/milhoja/TileWrapperGenerator.py @@ -10,7 +10,7 @@ from .AbcCodeGenerator import AbcCodeGenerator -class TileWrapperGenerator_cpp(AbcCodeGenerator): +class TileWrapperGenerator(AbcCodeGenerator): """ A class for generating final, compilable C++ header and source code that defines a Milhoja_TileWrapper derived class for constructing the data item @@ -39,7 +39,7 @@ def __init__(self, tf_spec, indent, logger): super().__init__( tf_spec, header_filename, source_filename, indent, - TileWrapperGenerator_cpp.__LOG_TAG, logger + TileWrapperGenerator.__LOG_TAG, logger ) # ----- DETERMINE INTERNAL SCRATCH NEEDED & STORE diff --git a/tools/milhoja_pypkg/src/milhoja/__init__.py b/tools/milhoja_pypkg/src/milhoja/__init__.py index 66579e23..f68b9a93 100644 --- a/tools/milhoja_pypkg/src/milhoja/__init__.py +++ b/tools/milhoja_pypkg/src/milhoja/__init__.py @@ -40,7 +40,8 @@ THREAD_INDEX_ARGUMENT, THREAD_INDEX_VAR_NAME, SUPPORTED_LANGUAGES, - SUPPORTED_PROCESSORS + SUPPORTED_PROCESSORS, + READ, WRITE, READ_WRITE, ACCESS_KEYS ) # Custom exceptions @@ -62,7 +63,7 @@ from .TaskFunction import TaskFunction from .TaskFunctionAssembler import TaskFunctionAssembler from .AbcCodeGenerator import AbcCodeGenerator -from .TileWrapperGenerator_cpp import TileWrapperGenerator_cpp +from .TileWrapperGenerator import TileWrapperGenerator from .TileWrapperModGenerator import TileWrapperModGenerator from .TaskFunctionGenerator_cpu_cpp import TaskFunctionGenerator_cpu_cpp from .DataPacketGenerator import DataPacketGenerator @@ -70,6 +71,11 @@ from .TaskFunctionC2FGenerator_cpu_F import TaskFunctionC2FGenerator_cpu_F from .TaskFunctionGenerator_OpenACC_F import TaskFunctionGenerator_OpenACC_F from .TaskFunctionGenerator_cpu_F import TaskFunctionGenerator_cpu_F +from .TaskFunctionC2FGenerator_OpenACC_F \ + import TaskFunctionC2FGenerator_OpenACC_F +from .TaskFunctionCpp2CGenerator_OpenACC_F \ + import TaskFunctionCpp2CGenerator_OpenACC_F +from .DataPacketModGenerator import DataPacketModGenerator # Functions that use classes from .generate_data_item import generate_data_item diff --git a/tools/milhoja_pypkg/src/milhoja/check_grid_data_specification.py b/tools/milhoja_pypkg/src/milhoja/check_grid_data_specification.py index 12629b95..15bfd60b 100644 --- a/tools/milhoja_pypkg/src/milhoja/check_grid_data_specification.py +++ b/tools/milhoja_pypkg/src/milhoja/check_grid_data_specification.py @@ -23,7 +23,7 @@ def check_grid_data_specification(arg, spec, variable_index_base, logger): # LOG_NAME = ERROR_CHECK_LOG_TAG VALID_SPACES = ["center", "fluxx", "fluxy", "fluxz"] - VALID_VAR_INFO = ["R", "RW", "W"] + VALID_VAR_INFO = ["r", "rw", "w"] # ----- ERROR CHECK ARGUMENTS if not isinstance(logger, AbcLogger): diff --git a/tools/milhoja_pypkg/src/milhoja/check_grid_specification.py b/tools/milhoja_pypkg/src/milhoja/check_grid_specification.py index 90585b8f..adadaed9 100644 --- a/tools/milhoja_pypkg/src/milhoja/check_grid_specification.py +++ b/tools/milhoja_pypkg/src/milhoja/check_grid_specification.py @@ -45,13 +45,13 @@ def check_grid_specification(spec, logger): nxb = spec["nxb"] if not isinstance(nxb, numbers.Integral): - raise TypeError(f"NXB is not integer ({nxb})") + raise TypeError(f"nxb is not integer ({nxb})") elif nxb <= 0: raise ValueError(f"Non-positive NXB ({nxb})") nyb = spec["nyb"] if not isinstance(nyb, numbers.Integral): - raise TypeError(f"NYB is not integer ({nyb})") + raise TypeError(f"nyb is not integer ({nyb})") elif nyb <= 0: raise ValueError(f"Non-positive NYB ({nyb})") elif (dimension == 1) and (nyb != 1): @@ -59,7 +59,7 @@ def check_grid_specification(spec, logger): nzb = spec["nzb"] if not isinstance(nzb, numbers.Integral): - raise TypeError(f"NZB is not integer ({nzb})") + raise TypeError(f"nzb is not integer ({nzb})") elif nzb <= 0: raise ValueError(f"Non-positive NZB ({nzb})") elif (dimension < 3) and (nzb != 1): diff --git a/tools/milhoja_pypkg/src/milhoja/check_group_specification.py b/tools/milhoja_pypkg/src/milhoja/check_group_specification.py index 96cf24ba..26d72f4d 100644 --- a/tools/milhoja_pypkg/src/milhoja/check_group_specification.py +++ b/tools/milhoja_pypkg/src/milhoja/check_group_specification.py @@ -113,8 +113,8 @@ def check_group_specification(group_spec, logger): raise TypeError(msg) if SCRATCH_ARGUMENT in group_spec: - if len(group_spec[SCRATCH_ARGUMENT]) == 0: - raise LogicError(f"Empty {SCRATCH_ARGUMENT} subsection") + # It is fine to have an empty group_spec[SCRATCH_ARGUMENT], + # it means there are no arguments of source type 'scratch'. for variable, var_spec in group_spec[SCRATCH_ARGUMENT].items(): if not variable.startswith("_"): diff --git a/tools/milhoja_pypkg/src/milhoja/constants.py b/tools/milhoja_pypkg/src/milhoja/constants.py index 9090d8e7..2a4b4120 100644 --- a/tools/milhoja_pypkg/src/milhoja/constants.py +++ b/tools/milhoja_pypkg/src/milhoja/constants.py @@ -14,7 +14,7 @@ LOG_LEVELS = list(range(LOG_LEVEL_NONE, LOG_LEVEL_MAX+1)) -# If we ever want to support more languages in the future +# If we ever want to support more languages in the future? SUPPORTED_LANGUAGES = ["c++", "fortran"] # If we ever want to support TPUs or NPUs :) (kidding, just a formality) SUPPORTED_PROCESSORS = ["cpu", "gpu"] @@ -66,6 +66,12 @@ TILE_CELL_VOLUMES_ARGUMENT } +# ----- DATA ACCESS KEYWORDS +READ = "r" +WRITE = "w" +READ_WRITE = "rw" +ACCESS_KEYS = [READ, WRITE, READ_WRITE] + GRID_DATA_EXTENTS = { "CENTER": [ '{0} + 2 * {1} * MILHOJA_K1D', diff --git a/tools/milhoja_pypkg/src/milhoja/generate_data_item.py b/tools/milhoja_pypkg/src/milhoja/generate_data_item.py index 5c59bf66..b1f80622 100644 --- a/tools/milhoja_pypkg/src/milhoja/generate_data_item.py +++ b/tools/milhoja_pypkg/src/milhoja/generate_data_item.py @@ -3,7 +3,8 @@ from pathlib import Path from .constants import LOG_LEVEL_BASIC_DEBUG -from .TileWrapperGenerator_cpp import TileWrapperGenerator_cpp +from .constants import SUPPORTED_LANGUAGES +from .TileWrapperGenerator import TileWrapperGenerator from .DataPacketGenerator import DataPacketGenerator @@ -28,18 +29,21 @@ def generate_data_item(tf_spec, destination, overwrite, library_path, indent, data_item = tf_spec.data_item language = tf_spec.language - if (language.lower() == "c++" or language.lower() == "fortran") and \ - (data_item.lower() == "tilewrapper"): + # check language + if (language.lower() not in SUPPORTED_LANGUAGES): + msg = f"{language} is not supported." + raise ValueError(msg) + + if data_item.lower() == "tilewrapper": - generator = TileWrapperGenerator_cpp(tf_spec, indent, logger) + generator = TileWrapperGenerator(tf_spec, indent, logger) generator.generate_header_code(destination, overwrite) generator.generate_source_code(destination, overwrite) assert destination.joinpath(generator.header_filename).is_file() assert destination.joinpath(generator.source_filename).is_file() - elif (language.lower() == "c++" or language.lower() == "fortran") and \ - (data_item.lower() == "datapacket"): + elif data_item.lower() == "datapacket": library = Path(library_path).resolve() sizes_json = library.joinpath("include", "sizes.json") if not library.is_dir(): @@ -55,9 +59,8 @@ def generate_data_item(tf_spec, destination, overwrite, library_path, indent, with open(sizes_json, "r") as fptr: sizes = json.load(fptr) expected = { - "real", "int", "unsigned int", "std::size_t", - "IntVect", "RealVect", - "FArray1D", "FArray2D", "FArray3D", "FArray4D", + "real", "int", "unsigned int", "std::size_t", "IntVect", + "RealVect", "FArray1D", "FArray2D", "FArray3D", "FArray4D", "byte_align" } assert set(sizes) == expected @@ -74,6 +77,7 @@ def generate_data_item(tf_spec, destination, overwrite, library_path, indent, assert destination.joinpath(generator.header_filename).is_file() assert destination.joinpath(generator.source_filename).is_file() + else: msg = f"Cannot generate data item code for {data_item}/{language}" raise ValueError(msg) diff --git a/tools/milhoja_pypkg/src/milhoja/generate_task_function.py b/tools/milhoja_pypkg/src/milhoja/generate_task_function.py index 59fe0953..ce096818 100644 --- a/tools/milhoja_pypkg/src/milhoja/generate_task_function.py +++ b/tools/milhoja_pypkg/src/milhoja/generate_task_function.py @@ -4,6 +4,9 @@ from . import TaskFunctionC2FGenerator_cpu_F from . import TaskFunctionCpp2CGenerator_cpu_F from . import TileWrapperModGenerator +from . import TaskFunctionC2FGenerator_OpenACC_F +from . import TaskFunctionCpp2CGenerator_OpenACC_F +from . import DataPacketModGenerator def generate_task_function(tf_spec, destination, overwrite, indent, logger): @@ -46,21 +49,29 @@ def generate_task_function(tf_spec, destination, overwrite, indent, logger): c2f_generator.generate_source_code(destination, overwrite) assert destination.joinpath(generator.source_filename).is_file() - tile_wrapper_mod_generator = \ - TileWrapperModGenerator(tf_spec, indent, logger) - tile_wrapper_mod_generator.generate_source_code( - destination, overwrite - ) - - assert destination.joinpath( - tile_wrapper_mod_generator.source_filename - ).is_file() + mod_generator = TileWrapperModGenerator(tf_spec, indent, logger) + mod_generator.generate_source_code(destination, overwrite) + assert destination.joinpath(mod_generator.source_filename).is_file() elif (language.lower() == "fortran") and (offloading == "openacc"): generator = TaskFunctionGenerator_OpenACC_F(tf_spec, indent, logger) generator.generate_source_code(destination, overwrite) assert destination.joinpath(generator.source_filename).is_file() + generator = \ + TaskFunctionC2FGenerator_OpenACC_F(tf_spec, indent, logger) + generator.generate_source_code(destination, overwrite) + assert destination.joinpath(generator.source_filename).is_file() + + generator = \ + TaskFunctionCpp2CGenerator_OpenACC_F(tf_spec, indent, logger) + generator.generate_source_code(destination, overwrite) + assert destination.joinpath(generator.source_filename).is_file() + + generator = DataPacketModGenerator(tf_spec, indent, logger) + generator.generate_source_code(destination, indent) + assert destination.joinpath(generator.source_filename).is_file() + elif (language.lower() in ["c++", "fortran"]) and \ (data_item == "datapacket"): logger.warn("Milhoja TF", "No TF generation for use with DataPackets") diff --git a/tools/milhoja_pypkg/src/milhoja/tests/TestCheckGridDataSpecification.py b/tools/milhoja_pypkg/src/milhoja/tests/TestCheckGridDataSpecification.py index a5af8cef..96b6caf1 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/TestCheckGridDataSpecification.py +++ b/tools/milhoja_pypkg/src/milhoja/tests/TestCheckGridDataSpecification.py @@ -9,7 +9,7 @@ from milhoja import ( LOG_LEVEL_NONE, - GRID_DATA_ARGUMENT, SCRATCH_ARGUMENT, + GRID_DATA_ARGUMENT, SCRATCH_ARGUMENT, ACCESS_KEYS, LogicError, BasicLogger, check_grid_data_specification @@ -34,7 +34,7 @@ def setUp(self): self.__good = { "source": GRID_DATA_ARGUMENT, "structure_index": ["center", 1], - "R": [1] + "r": [1] } check_grid_data_specification(self.__name, self.__good, self.__index, self.__logger) @@ -77,7 +77,7 @@ def testGoodSpecs(self): for space, index, var_base in good_all: good_vars = list(range(var_base, 12)) - for access in ["R", "RW", "W"]: + for access in ACCESS_KEYS: good_spec = { "source": GRID_DATA_ARGUMENT, "structure_index": [space, index], @@ -86,7 +86,7 @@ def testGoodSpecs(self): check_grid_data_specification(name, good_spec, var_base, self.__logger) - for a1, a2 in it.combinations(["R", "RW", "W"], 2): + for a1, a2 in it.combinations(ACCESS_KEYS, 2): # Must be disjoint, but make out of order and non-contiguous. # Include the index base. vars1 = [var_base, 3, 5] @@ -112,7 +112,7 @@ def testGoodSpecs(self): vars1 = [99, 3, 5] vars2 = [9, 2] vars3 = [var_base, 101] - for a1, a2, a3 in it.permutations(["R", "RW", "W"]): + for a1, a2, a3 in it.permutations(ACCESS_KEYS): good_spec = { "source": GRID_DATA_ARGUMENT, "structure_index": [space, index], @@ -129,12 +129,12 @@ def testKeys(self): check_grid_data_specification(self.__name, bad_spec, self.__index, self.__logger) - # No R/RW/W keys + # No r/rw/w keys bad_spec = copy.deepcopy(self.__good) - self.assertTrue("R" in bad_spec) - self.assertTrue("RW" not in bad_spec) - self.assertTrue("W" not in bad_spec) - del bad_spec["R"] + self.assertTrue("r" in bad_spec) + self.assertTrue("rw" not in bad_spec) + self.assertTrue("w" not in bad_spec) + del bad_spec["r"] with self.assertRaises(ValueError): check_grid_data_specification(self.__name, bad_spec, self.__index, self.__logger) @@ -193,7 +193,7 @@ def testBadStructureIndex(self): self.__index, self.__logger) def testBadAccessPatterns(self): - for access in ["R", "RW", "W"]: + for access in ACCESS_KEYS: bad_spec = copy.deepcopy(self.__good) for bad in NOT_LIST_LIST: bad_spec[access] = bad @@ -214,11 +214,11 @@ def testBadAccessPatterns(self): self.__index, self.__logger) # Check for bad access patterns based on variable index set's base - for access in ["R", "RW", "W"]: + for access in ACCESS_KEYS: bad_spec = copy.deepcopy(self.__good) - del bad_spec["R"] - self.assertTrue("RW" not in bad_spec) - self.assertTrue("W" not in bad_spec) + del bad_spec["r"] + self.assertTrue("rw" not in bad_spec) + self.assertTrue("w" not in bad_spec) index = 1 for bad in [-2, -1, 0]: bad_spec[access] = [bad] @@ -244,11 +244,11 @@ def testBadAccessPatterns(self): index, self.__logger) # Catch repeated index - for access in ["R", "RW", "W"]: + for access in ACCESS_KEYS: bad_spec = copy.deepcopy(self.__good) - del bad_spec["R"] - self.assertTrue("RW" not in bad_spec) - self.assertTrue("W" not in bad_spec) + del bad_spec["r"] + self.assertTrue("rw" not in bad_spec) + self.assertTrue("w" not in bad_spec) bad_spec[access] = [3, 1, 1, 2] with self.assertRaises(LogicError): check_grid_data_specification(self.__name, bad_spec, @@ -256,11 +256,11 @@ def testBadAccessPatterns(self): # Variables can have only one access pattern common = 3 - for a1, a2 in it.combinations(["R", "RW", "W"], 2): + for a1, a2 in it.combinations(ACCESS_KEYS, 2): bad_spec = copy.deepcopy(self.__good) - del bad_spec["R"] - self.assertTrue("RW" not in bad_spec) - self.assertTrue("W" not in bad_spec) + del bad_spec["r"] + self.assertTrue("rw" not in bad_spec) + self.assertTrue("w" not in bad_spec) bad_spec[a1] = [1, common, 5] bad_spec[a2] = [9, 2, common] with self.assertRaises(ValueError): diff --git a/tools/milhoja_pypkg/src/milhoja/tests/TestDataPacketGenerator.py b/tools/milhoja_pypkg/src/milhoja/tests/TestDataPacketGenerator.py index c879acad..d4a7559e 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/TestDataPacketGenerator.py +++ b/tools/milhoja_pypkg/src/milhoja/tests/TestDataPacketGenerator.py @@ -12,11 +12,13 @@ BasicLogger, TaskFunction ) -from milhoja.Cpp2CLayerGenerator import Cpp2CLayerGenerator -from milhoja.C2FortranLayerGenerator import C2FortranLayerGenerator +from milhoja.TaskFunctionCpp2CGenerator_OpenACC_F \ + import TaskFunctionCpp2CGenerator_OpenACC_F +from milhoja.TaskFunctionC2FGenerator_OpenACC_F \ + import TaskFunctionC2FGenerator_OpenACC_F from milhoja.FortranTemplateUtility import FortranTemplateUtility from milhoja.TemplateUtility import TemplateUtility -from milhoja.DataPacketC2FModuleGenerator import DataPacketC2FModuleGenerator +from milhoja.DataPacketModGenerator import DataPacketModGenerator _FILE_PATH = Path(__file__).resolve().parent _DATA_PATH = _FILE_PATH.joinpath("data") @@ -238,10 +240,8 @@ def testPacketGeneration(self): destination, overwrite=False ) - generated_name_cpp = Path( - destination, - generator.source_filename - ) + generated_name_cpp = \ + Path(destination, generator.source_filename) correct_name_cpp = json_path.stem.replace("REF_", "") correct_name_cpp = Path( _DATA_PATH, @@ -257,10 +257,8 @@ def testPacketGeneration(self): json_path, generated_cpp, correct ) - generated_name_h = Path( - destination, - generator.header_filename - ) + generated_name_h = \ + Path(destination, generator.header_filename) correct_name_h = json_path.stem.replace("REF_", "") correct_name_h = Path( _DATA_PATH, @@ -275,77 +273,10 @@ def testPacketGeneration(self): json_path, generated_h, correct ) - # ..todo:: - # * currently the cpp2c layer is only generated when - # using a fortran task function there should be - # another "cpp2c layer" that's just for cpp task - # functions. - generated_cpp2c = None - generated_c2f = None - generated_dp_mod = None - if generator.language == "fortran": - # check cpp2c layer. - generated_cpp2c = Path( - destination, - generator.cpp2c_layer.source_filename - ) - correct_cpp2c = json_path.stem.replace("REF_", "") - correct_cpp2c = Path( - _DATA_PATH, - test[self.FOLDER], - "REF_" + str(correct_cpp2c) + "_Cpp2C.cpp" - ) - with open(generated_cpp2c, 'r') as generated: - with open(correct_cpp2c, 'r') as correct: - self.check_generated_files( - json_path, generated, correct - ) - - # check c2f layer. - generated_c2f = Path( - destination, - generator.c2f_layer.source_filename - ) - correct_c2f = json_path.stem.replace("REF_", "") - correct_c2f = Path( - _DATA_PATH, - test[self.FOLDER], - "REF_" + str(correct_c2f) + "_C2F.F90" - ) - with open(generated_c2f, 'r') as generated: - with open(correct_c2f, 'r') as correct: - self.check_generated_files( - json_path, generated, correct - ) - - # check module file - generated_dp_mod = Path( - destination, - generator.dp_module.source_filename - ) - correct_dp_mod = json_path.stem.replace("REF_", "") - correct_dp_mod = Path( - _DATA_PATH, - test[self.FOLDER], - "REF_DataPacket_" + str(correct_dp_mod) + - "_c2f_mod.F90" - ) - with open(generated_dp_mod, 'r') as generated: - with open(correct_dp_mod, 'r') as correct: - self.check_generated_files( - json_path, generated, correct - ) - # clean up generated files if test passes. try: os.remove(generated_name_cpp) os.remove(generated_name_h) - if generated_cpp2c: - os.remove(generated_cpp2c) - if generated_c2f: - os.remove(generated_c2f) - if generated_dp_mod: - os.remove(generated_dp_mod) # be careful when cleaning up here for file in Path(destination).glob("cg-tpl.*.cpp"): os.remove(file) @@ -479,7 +410,7 @@ def testCpp2CGenerator(self): # use default logging value for now logger = BasicLogger(LOG_LEVEL_NONE) destination = Path.cwd() - cpp2c = Cpp2CLayerGenerator(tf_spec, 4, logger) + cpp2c = TaskFunctionCpp2CGenerator_OpenACC_F(tf_spec, 4, logger) with self.assertRaises( LogicError, @@ -494,7 +425,20 @@ def testCpp2CGenerator(self): ): cpp2c.generate_source_code(destination, overwrite=False) + generated_cpp2c = Path(destination, cpp2c.source_filename) + correct_cpp2c = json_path.stem.replace("REF_", "") + correct_cpp2c = Path( + _DATA_PATH, test[self.FOLDER], + "REF_" + str(correct_cpp2c) + "_Cpp2C.cpp" + ) + with open(generated_cpp2c, 'r') as generated: + with open(correct_cpp2c, 'r') as correct: + self.check_generated_files( + json_path, generated, correct + ) + # cleanup + os.remove(generated_cpp2c) try: for file in Path(destination).glob("cg-tpl.*.cpp"): os.remove(file) @@ -516,28 +460,38 @@ def testModGeneration(self): if tf_spec.language.lower() == "c++": with self.assertRaises(LogicError, msg="Wrong language"): - mod_generator = DataPacketC2FModuleGenerator( + mod_generator = DataPacketModGenerator( tf_spec, 4, logger ) continue - mod_generator = DataPacketC2FModuleGenerator( - tf_spec, 4, logger - ) - + mod_generator = DataPacketModGenerator(tf_spec, 4, logger) with self.assertRaises(LogicError, msg="Header gen should fail."): mod_generator.generate_header_code(destination, True) mod_generator.generate_source_code(destination, True) - with self.assertRaises( FileExistsError, msg="File was overwritten!" ): mod_generator.generate_source_code(destination, False) + + generated_dp_mod = \ + Path(destination, mod_generator.source_filename) + correct_dp_mod = json_path.stem.replace("REF_", "") + correct_dp_mod = Path( + _DATA_PATH, test[self.FOLDER], + "REF_DataPacket_" + str(correct_dp_mod) + "_c2f_mod.F90" + ) + with open(generated_dp_mod, 'r') as generated: + with open(correct_dp_mod, 'r') as correct: + self.check_generated_files( + json_path, generated, correct + ) + os.remove(Path(destination, mod_generator.source_filename)) - def testC2fGenerator(self): + def testC2FGenerator(self): for test in self._sedov: json_path = test[self.JSON] sizes = test[self.SIZES] @@ -552,10 +506,7 @@ def testC2fGenerator(self): logger = BasicLogger(LOG_LEVEL_NONE) destination = Path.cwd() - c2f = C2FortranLayerGenerator( - tf_spec, 4, logger - ) - + c2f = TaskFunctionC2FGenerator_OpenACC_F(tf_spec, 4, logger) with self.assertRaises( LogicError, msg="C2F generate_header was not called?" @@ -563,13 +514,24 @@ def testC2fGenerator(self): c2f.generate_header_code(destination, overwrite=True) c2f.generate_source_code(destination, overwrite=True) - with self.assertRaises( FileExistsError, msg="C2F file was overwritten!" ): c2f.generate_source_code(destination, overwrite=False) + generated_c2f = Path(destination, c2f.source_filename) + correct_c2f = json_path.stem.replace("REF_", "") + correct_c2f = Path( + _DATA_PATH, test[self.FOLDER], + "REF_" + str(correct_c2f) + "_C2F.F90" + ) + with open(generated_c2f, 'r') as generated: + with open(correct_c2f, 'r') as correct: + self.check_generated_files( + json_path, generated, correct + ) + try: for file in Path(destination).glob("*.F90"): os.remove(file) diff --git a/tools/milhoja_pypkg/src/milhoja/tests/TestSubroutineGroup.py b/tools/milhoja_pypkg/src/milhoja/tests/TestSubroutineGroup.py index 745a46ab..4ee962fa 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/TestSubroutineGroup.py +++ b/tools/milhoja_pypkg/src/milhoja/tests/TestSubroutineGroup.py @@ -324,7 +324,7 @@ def testArgumentSpecification(self): expected = { "source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [2] + "rw": [2] } arg_spec = self.__group.argument_specification(good_sub, good_arg) self.assertEqual(expected, arg_spec) diff --git a/tools/milhoja_pypkg/src/milhoja/tests/TestSubroutineGroup_BadGroup.py b/tools/milhoja_pypkg/src/milhoja/tests/TestSubroutineGroup_BadGroup.py index 2f4a8813..4da0114b 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/TestSubroutineGroup_BadGroup.py +++ b/tools/milhoja_pypkg/src/milhoja/tests/TestSubroutineGroup_BadGroup.py @@ -241,7 +241,10 @@ def testEmptyScratch(self): del bad_spec[SCRATCH_ARGUMENT]["_scratch3D"] del bad_spec[SCRATCH_ARGUMENT]["_scratch4D"] self.assertEqual(0, len(bad_spec[SCRATCH_ARGUMENT])) - with self.assertRaises(LogicError): + # An empty scratch section should not raise LogicError, but ValueError is + # still expected in this test since scratch variable + # _scratch3D is needed for mapping to scratch - KW + with self.assertRaises(ValueError): SubroutineGroup(bad_spec, self.__logger) def testScratchKeys(self): diff --git a/tools/milhoja_pypkg/src/milhoja/tests/TestTileWrapperGenerator_cpp.py b/tools/milhoja_pypkg/src/milhoja/tests/TestTileWrapperGenerator_cpp.py index 4a32d067..99ba9e3d 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/TestTileWrapperGenerator_cpp.py +++ b/tools/milhoja_pypkg/src/milhoja/tests/TestTileWrapperGenerator_cpp.py @@ -16,7 +16,7 @@ def _create_generator(json_filename): logger = milhoja.BasicLogger(milhoja.LOG_LEVEL_NONE) tf_spec = milhoja.TaskFunction.from_milhoja_json(json_filename) - return milhoja.TileWrapperGenerator_cpp(tf_spec, INDENT, logger) + return milhoja.TileWrapperGenerator(tf_spec, INDENT, logger) class TestTileWrapperGenerator_cpp(milhoja.tests.TestCodeGenerators): diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/Hydro_op1.json b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/Hydro_op1.json index b0d75729..78e15409 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/Hydro_op1.json +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/Hydro_op1.json @@ -31,7 +31,7 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 5, 9]}, + "r": [1, 5, 9]}, "loU": {"source": "lbound", "array": "U"}, "auxC": {"source": "scratch", @@ -51,7 +51,7 @@ "deltas": {"source": "tile_deltas"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6]}, + "r": [1, 2, 3, 4, 5, 6]}, "loU": {"source": "lbound", "array": "U"}, "auxC": {"source": "scratch", @@ -75,7 +75,7 @@ "deltas": {"source": "tile_deltas"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6]}, + "r": [1, 2, 3, 4, 5, 6]}, "loU": {"source": "lbound", "array": "U"}, "auxC": {"source": "scratch", @@ -99,7 +99,7 @@ "deltas": {"source": "tile_deltas"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6]}, + "r": [1, 2, 3, 4, 5, 6]}, "loU": {"source": "lbound", "array": "U"}, "auxC": {"source": "scratch", @@ -128,8 +128,8 @@ "array": "flX"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [1, 2, 3, 4, 6], - "W": [8]}, + "rw": [1, 2, 3, 4, 6], + "w": [8]}, "loU": {"source": "lbound", "array": "U"} } @@ -143,9 +143,9 @@ "range": {"source": "tile_interior"}, "solnData": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4], - "RW": [6, 8], - "W": [5, 7, 9, 10]} + "r": [1, 2, 3, 4], + "rw": [6, 8], + "w": [5, 7, 9, 10]} } }, "Hydro_computeSoundSpeedHll_gpu_oacc": { @@ -156,7 +156,7 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 5, 9]}, + "r": [1, 5, 9]}, "loU": {"source": "lbound", "array": "U"}, "auxC": {"source": "scratch", @@ -176,7 +176,7 @@ "deltas": {"source": "tile_deltas"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6]}, + "r": [1, 2, 3, 4, 5, 6]}, "loU": {"source": "lbound", "array": "U"}, "flX": {"source": "scratch", @@ -200,7 +200,7 @@ "deltas": {"source": "tile_deltas"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6]}, + "r": [1, 2, 3, 4, 5, 6]}, "loU": {"source": "lbound", "array": "U"}, "flY": {"source": "scratch", @@ -224,7 +224,7 @@ "deltas": {"source": "tile_deltas"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [1, 2, 3, 4, 5, 6]}, + "r": [1, 2, 3, 4, 5, 6]}, "loU": {"source": "lbound", "array": "U"}, "flZ": {"source": "scratch", @@ -253,8 +253,8 @@ "array": "flX"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [1, 2, 3, 4, 6], - "W": [8]}, + "rw": [1, 2, 3, 4, 6], + "w": [8]}, "loU": {"source": "lbound", "array": "U"} } diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydroFC_2D.F90 b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydroFC_2D.F90 index 7dc40cba..c3149757 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydroFC_2D.F90 +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydroFC_2D.F90 @@ -54,11 +54,11 @@ subroutine gpu_tf_hydroFC_Fortran( & integer, intent(IN) :: tile_lo_d(:, :) integer, intent(IN) :: tile_hi_d(:, :) real, intent(IN) :: tile_deltas_d(:, :) - real, intent(INOUT) :: CC_1_d(:, :, :, :, :) + real, intent(INOUT) :: CC_1_d(:, :, :, :, :) real, intent(OUT) :: FLX_1_d(:, :, :, :, :) real, intent(OUT) :: FLY_1_d(:, :, :, :, :) real, intent(OUT) :: FLZ_1_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_auxc_d(:, :, :, :) + real, intent(INOUT) :: hydro_op1_auxc_d(:, :, :, :) integer :: n diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_2D.F90 b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_2D.F90 index d83aae41..73fd8e1c 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_2D.F90 +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_2D.F90 @@ -55,10 +55,10 @@ subroutine gpu_tf_hydro_Fortran( & integer, intent(IN) :: tile_hi_d(:, :) real, intent(IN) :: tile_deltas_d(:, :) real, intent(INOUT) :: U_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flX_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flY_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flZ_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_auxc_d(:, :, :, :) + real, intent(INOUT) :: hydro_op1_flX_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_flY_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_flZ_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_auxc_d(:, :, :, :) integer :: n diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_2D.json b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_2D.json index 44196b7b..a8202b46 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_2D.json +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_2D.json @@ -11,7 +11,6 @@ "name": "gpu_tf_hydro", "language": "Fortran", "processor": "GPU", - "computation_offloading": "OpenACC", "cpp_header": "gpu_tf_hydro_Cpp2C.h", "cpp_source": "gpu_tf_hydro_Cpp2C.cxx", "c2f_source": "gpu_tf_hydro_C2F.F90", diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_3D.F90 b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_3D.F90 index bc9a1ad0..019853b9 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_3D.F90 +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_3D.F90 @@ -71,10 +71,10 @@ subroutine gpu_tf_hydro_Fortran( & integer, intent(IN) :: tile_hi_d(:, :) integer, intent(IN) :: tile_lo_d(:, :) real, intent(INOUT) :: CC_1_d(:, :, :, :, :) - real, intent(IN) :: scratch_hydro_op1_auxC_d(:, :, :, :) - real, intent(IN) :: scratch_hydro_op1_flX_d(:, :, :, :, :) - real, intent(IN) :: scratch_hydro_op1_flY_d(:, :, :, :, :) - real, intent(IN) :: scratch_hydro_op1_flZ_d(:, :, :, :, :) + real, intent(INOUT) :: scratch_hydro_op1_auxC_d(:, :, :, :) + real, intent(INOUT) :: scratch_hydro_op1_flX_d(:, :, :, :, :) + real, intent(INOUT) :: scratch_hydro_op1_flY_d(:, :, :, :, :) + real, intent(INOUT) :: scratch_hydro_op1_flZ_d(:, :, :, :, :) integer, intent(IN) :: lbdd_CC_1_d(:, :) integer, intent(IN) :: lbdd_scratch_hydro_op1_auxC_d(:, :) integer, intent(IN) :: lbdd_scratch_hydro_op1_flX_d(:, :) diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_3D.json b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_3D.json index 0faaa8fe..19c00f3d 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_3D.json +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/FlashX/REF_gpu_tf_hydro_3D.json @@ -11,7 +11,6 @@ "name": "gpu_tf_hydro", "language": "Fortran", "processor": "GPU", - "computation_offloading": "OpenACC", "cpp_header": "gpu_tf_hydro_Cpp2C.h", "cpp_source": "gpu_tf_hydro_Cpp2C.cxx", "c2f_source": "gpu_tf_hydro_C2F.F90", diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_hydro_3D.F90 b/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_hydro_3D.F90 index 5c903b8b..0c34c9f0 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_hydro_3D.F90 +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_hydro_3D.F90 @@ -66,10 +66,10 @@ subroutine gpu_tf_hydro( & integer, intent(IN) :: tile_hi_d(:, :) real, intent(IN) :: tile_deltas_d(:, :) real, intent(INOUT) :: CC_1_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flX_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flY_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flZ_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_auxc_d(:, :, :, :) + real, intent(INOUT) :: hydro_op1_flX_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_flY_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_flZ_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_auxc_d(:, :, :, :) integer :: n integer(MILHOJA_INT) :: MH_idx diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_test2_3D.F90 b/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_test2_3D.F90 index 67f1a797..c0b555c0 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_test2_3D.F90 +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_test2_3D.F90 @@ -64,10 +64,10 @@ subroutine gpu_tf_test2_Fortran( & integer, intent(IN) :: tile_hi_d(:, :) real, intent(IN) :: tile_deltas_d(:, :) real, intent(INOUT) :: CC_1_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flX_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flY_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flZ_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_auxc_d(:, :, :, :) + real, intent(INOUT) :: hydro_op1_flX_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_flY_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_flZ_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_auxc_d(:, :, :, :) integer :: n diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_test_3D.F90 b/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_test_3D.F90 index c7a2fbe0..0c0e5ef6 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_test_3D.F90 +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/Sedov/REF_gpu_tf_test_3D.F90 @@ -64,10 +64,10 @@ subroutine gpu_tf_test_Fortran( & integer, intent(IN) :: tile_hi_d(:, :) real, intent(IN) :: tile_deltas_d(:, :) real, intent(INOUT) :: CC_1_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flX_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flY_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_flZ_d(:, :, :, :, :) - real, intent(IN) :: hydro_op1_auxc_d(:, :, :, :) + real, intent(INOUT) :: hydro_op1_flX_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_flY_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_flZ_d(:, :, :, :, :) + real, intent(INOUT) :: hydro_op1_auxc_d(:, :, :, :) integer :: n diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/Spark/__Hydro_op_spec.json b/tools/milhoja_pypkg/src/milhoja/tests/data/Spark/__Hydro_op_spec.json index 18ff3a8e..5788d201 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/Spark/__Hydro_op_spec.json +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/Spark/__Hydro_op_spec.json @@ -171,7 +171,7 @@ "CENTER", 1 ], - "RW": [ + "rw": [ 1, 2, 3, @@ -271,7 +271,7 @@ "CENTER", 1 ], - "RW": [ + "rw": [ 1, 2, 3, diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/fake/FakeA_op1.json b/tools/milhoja_pypkg/src/milhoja/tests/data/fake/FakeA_op1.json index b73c1a23..10212e23 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/fake/FakeA_op1.json +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/fake/FakeA_op1.json @@ -81,18 +81,18 @@ "array": "U"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [2, 3]}, + "rw": [2, 3]}, "loFl": {"source": "lbound", "array": "flX"}, "flX": {"source": "grid_data", "structure_index": ["FLUXX", 1], - "R": [1, 2]}, + "r": [1, 2]}, "flY": {"source": "grid_data", "structure_index": ["FLUXY", 1], - "W": [1, 2]}, + "w": [1, 2]}, "flZ": {"source": "grid_data", "structure_index": ["FLUXZ", 1], - "W": [1, 2]}, + "w": [1, 2]}, "scratch4D": {"source": "scratch", "name": "_same"}, "lo_S4D": {"source": "lbound", diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/fake/FakeB_op2.json b/tools/milhoja_pypkg/src/milhoja/tests/data/fake/FakeB_op2.json index 6202152f..6ce029ee 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/fake/FakeB_op2.json +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/fake/FakeB_op2.json @@ -82,21 +82,21 @@ "hi": "tile_hi"}, "solnData": {"source": "grid_data", "structure_index": ["CENTER", 1], - "R": [6, 5], - "W": [1]}, + "r": [6, 5], + "w": [1]}, "loSData": {"source": "lbound", "array": "solnData"}, "xFlux": {"source": "grid_data", "structure_index": ["FLUXX", 1], - "R": [3, 2]}, + "r": [3, 2]}, "yFlux": {"source": "grid_data", "structure_index": ["FLUXY", 1], - "W": [5, 1]}, + "w": [5, 1]}, "loFluxY": {"source": "lbound", "array": "yFlux"}, "zFlux": {"source": "grid_data", "structure_index": ["FLUXZ", 1], - "R": [5, 4]}, + "r": [5, 4]}, "loFlux": {"source": "lbound", "array": "xFlux"}, "loS_4D": {"source": "lbound", diff --git a/tools/milhoja_pypkg/src/milhoja/tests/data/fake/Math_op1.json b/tools/milhoja_pypkg/src/milhoja/tests/data/fake/Math_op1.json index 3b4b8b5c..bed7edc4 100644 --- a/tools/milhoja_pypkg/src/milhoja/tests/data/fake/Math_op1.json +++ b/tools/milhoja_pypkg/src/milhoja/tests/data/fake/Math_op1.json @@ -22,7 +22,7 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [1]}, + "rw": [1]}, "scratch": {"source": "scratch", "name": "_scratch3D"}, "deltas": {"source": "tile_deltas"} @@ -36,7 +36,7 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [2]}, + "rw": [2]}, "scratch": {"source": "scratch", "name": "_scratch3D"}, "deltas": {"source": "tile_deltas"} @@ -52,7 +52,7 @@ "hi": {"source": "tile_hi"}, "U": {"source": "grid_data", "structure_index": ["CENTER", 1], - "RW": [1, 2]}, + "rw": [1, 2]}, "scratch": {"source": "scratch", "name": "_scratch4D"}, "deltas": {"source": "tile_deltas"} diff --git a/tools/milhoja_pypkg/tox.ini b/tools/milhoja_pypkg/tox.ini index c881e226..006d6094 100644 --- a/tools/milhoja_pypkg/tox.ini +++ b/tools/milhoja_pypkg/tox.ini @@ -46,7 +46,7 @@ deps = flake8 commands = python setup.py check --strict --metadata - flake8 + flake8 --extend-ignore=E501 [testenv:format] # This can alter files, so users should use with care and this should never be diff --git a/tools/sedov_pypkg/setup.py b/tools/sedov_pypkg/setup.py index e417c1ec..d8b43f68 100755 --- a/tools/sedov_pypkg/setup.py +++ b/tools/sedov_pypkg/setup.py @@ -14,7 +14,7 @@ def version(): with open(fname, 'r') as fptr: return fptr.read().strip() -reqs_list = ['numpy', 'pandas', 'matplotlib', 'yt'] +reqs_list = ['nose', 'numpy', 'pandas', 'matplotlib', 'yt'] pkg_dict = {'sedov': ['PkgData/*', 'TestData/*']}