Skip to content
Snippets Groups Projects

Fix field size

Merged Markus Holzer requested to merge holzer/pystencils:FixFieldSize into master
1 unresolved thread
Files
2
+ 12
6
@@ -375,9 +375,11 @@ def create_function_boilerplate_code(parameter_info, name, ast_node, insert_chec
np_dtype = field.dtype.numpy_dtype
item_size = np_dtype.itemsize
aligned = any([a.lhs.args[2] for a in ast_node.assignments if
hasattr(a, 'lhs') and isinstance(a.lhs, cast_func) and
hasattr(a.lhs, 'dtype') and isinstance(a.lhs.dtype, VectorType)])
aligned = False
if ast_node.assignments:
aligned = any([a.lhs.args[2] for a in ast_node.assignments
if hasattr(a, 'lhs') and isinstance(a.lhs, cast_func)
and hasattr(a.lhs, 'dtype') and isinstance(a.lhs.dtype, VectorType)])
if ast_node.instruction_set and aligned:
byte_width = ast_node.instruction_set['width'] * item_size
@@ -492,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)
@@ -521,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)
@@ -588,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: