diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5d3f3405..7d6dfe92 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -159,13 +159,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/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/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 4bc3daf9..f68b9a93 100644 --- a/tools/milhoja_pypkg/src/milhoja/__init__.py +++ b/tools/milhoja_pypkg/src/milhoja/__init__.py @@ -63,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 @@ -71,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/constants.py b/tools/milhoja_pypkg/src/milhoja/constants.py index 986dfac8..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"] 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/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/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/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_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/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/tox.ini b/tools/milhoja_pypkg/tox.ini index 0cc22515..8fdbb297 100644 --- a/tools/milhoja_pypkg/tox.ini +++ b/tools/milhoja_pypkg/tox.ini @@ -49,7 +49,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/*']}