From d8072b06bae31f37caf1ffa840cacd977a69cd44 Mon Sep 17 00:00:00 2001 From: markus holzer <markus.holzer@fau.de> Date: Wed, 3 Mar 2021 11:50:22 +0100 Subject: [PATCH] Generated C Code only once --- pystencils/cpu/cpujit.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py index 7486cf34e..c5b1b9489 100644 --- a/pystencils/cpu/cpujit.py +++ b/pystencils/cpu/cpujit.py @@ -494,12 +494,13 @@ def run_compile_step(command): class ExtensionModuleCode: - def __init__(self, module_name='generated', custom_backend=None): + def __init__(self, module_name='generated', custom_backend=None, generated_code=None): self.module_name = module_name self._ast_nodes = [] self._function_names = [] self._custom_backend = custom_backend + self._generated_code = generated_code def add_function(self, ast, name=None): self._ast_nodes.append(ast) @@ -523,7 +524,10 @@ class ExtensionModuleCode: for ast, name in zip(self._ast_nodes, self._function_names): old_name = ast.function_name ast.function_name = "kernel_" + name - print(generate_c(ast, custom_backend=self._custom_backend), file=file) + if self._generated_code: + print(self._generated_code, file=file) + else: + print(generate_c(ast, custom_backend=self._custom_backend), file=file) print(create_function_boilerplate_code(ast.get_parameters(), name, ast), file=file) ast.function_name = old_name print(create_module_boilerplate_code(self.module_name, self._function_names), file=file) @@ -590,7 +594,7 @@ def compile_and_load(ast, custom_backend=None): # Also the information of the field size should be contained in the hash string. Due to padding the generated code # can look similar for different field sizes. code_hash_str = "mod_" + hashlib.sha256((generated_code + fields_accessed).encode()).hexdigest() - code = ExtensionModuleCode(module_name=code_hash_str, custom_backend=custom_backend) + code = ExtensionModuleCode(module_name=code_hash_str, custom_backend=custom_backend, generated_code=generated_code) code.add_function(ast, ast.function_name) if cache_config['object_cache'] is False: -- GitLab