Skip to content
Snippets Groups Projects
Commit 6718973d authored by Markus Holzer's avatar Markus Holzer
Browse files

Reveal base_pointer_spec for the user

parent 03909356
No related branches found
No related tags found
1 merge request!210WIP: Assembly
......@@ -18,7 +18,7 @@ AssignmentOrAstNodeList = List[Union[Assignment, ast.Node]]
def create_kernel(assignments: AssignmentOrAstNodeList, function_name: str = "kernel", type_info='double',
split_groups=(), iteration_slice=None, ghost_layers=None,
skip_independence_check=False) -> KernelFunction:
skip_independence_check=False, base_pointer_spec=None) -> KernelFunction:
"""Creates an abstract syntax tree for a kernel function, by taking a list of update rules.
Loops are created according to the field accesses in the equations.
......@@ -39,6 +39,7 @@ def create_kernel(assignments: AssignmentOrAstNodeList, function_name: str = "ke
all dimensions
skip_independence_check: don't check that loop iterations are independent. This is needed e.g. for
periodicity kernel, that access the field outside the iteration bounds. Use with care!
base_pointer_spec: specifies which field accesses are resolved by pointers see :func:`parse_base_pointer_info`
Returns:
AST node representing a function, that can be printed as C or CUDA code
......@@ -73,7 +74,8 @@ def create_kernel(assignments: AssignmentOrAstNodeList, function_name: str = "ke
typed_split_groups = [[type_symbol(s) for s in split_group] for split_group in split_groups]
split_inner_loop(ast_node, typed_split_groups)
base_pointer_spec = [['spatialInner0'], ['spatialInner1']] if len(loop_order) >= 2 else [['spatialInner0']]
if base_pointer_spec is None:
base_pointer_spec = [['spatialInner0'], ['spatialInner1']] if len(loop_order) >= 2 else [['spatialInner0']]
base_pointer_info = {field.name: parse_base_pointer_info(base_pointer_spec, loop_order,
field.spatial_dimensions, field.index_dimensions)
for field in fields_without_buffers}
......
......@@ -15,7 +15,8 @@ def create_cuda_kernel(assignments,
iteration_slice=None,
ghost_layers=None,
skip_independence_check=False,
use_textures_for_interpolation=True):
use_textures_for_interpolation=True,
base_pointer_spec=None):
assert assignments, "Assignments must not be empty!"
fields_read, fields_written, assignments = add_types(assignments, type_info, not skip_independence_check)
all_fields = fields_read.union(fields_written)
......@@ -73,7 +74,8 @@ def create_cuda_kernel(assignments,
implement_interpolations(ast, implement_by_texture_accesses=use_textures_for_interpolation)
base_pointer_spec = [['spatialInner0']]
if base_pointer_spec is None:
base_pointer_spec = [['spatialInner0']]
base_pointer_info = {f.name: parse_base_pointer_info(base_pointer_spec, [2, 1, 0],
f.spatial_dimensions, f.index_dimensions)
for f in all_fields}
......
......@@ -31,7 +31,8 @@ def create_kernel(assignments,
cpu_prepend_optimizations=[],
use_auto_for_assignments=False,
opencl_queue=None,
opencl_ctx=None):
opencl_ctx=None,
base_pointer_spec=None):
"""
Creates abstract syntax tree (AST) of kernel, using a list of update equations.
......@@ -57,6 +58,7 @@ def create_kernel(assignments,
gpu_indexing_params: dict with indexing parameters (constructor parameters of indexing class)
e.g. for 'block' one can specify '{'block_size': (20, 20, 10) }'
cpu_prepend_optimizations: list of extra optimizations to perform first on the AST
base_pointer_spec: specifies which field accesses are resolved by pointers see :func:`parse_base_pointer_info`
Returns:
abstract syntax tree (AST) object, that can either be printed as source code with `show_code` or
......@@ -94,7 +96,7 @@ def create_kernel(assignments,
from pystencils.cpu import add_openmp
ast = create_kernel(assignments, type_info=data_type, split_groups=split_groups,
iteration_slice=iteration_slice, ghost_layers=ghost_layers,
skip_independence_check=skip_independence_check)
skip_independence_check=skip_independence_check, base_pointer_spec=base_pointer_spec)
for optimization in cpu_prepend_optimizations:
optimization(ast)
omp_collapse = None
......@@ -119,7 +121,8 @@ def create_kernel(assignments,
indexing_creator=indexing_creator_from_params(gpu_indexing, gpu_indexing_params),
iteration_slice=iteration_slice, ghost_layers=ghost_layers,
skip_independence_check=skip_independence_check,
use_textures_for_interpolation=use_textures_for_interpolation)
use_textures_for_interpolation=use_textures_for_interpolation,
base_pointer_spec=base_pointer_spec)
if target == 'opencl':
from pystencils.opencl.opencljit import make_python_function
ast._backend = 'opencl'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment