Kernel Creation¶
The primary interface for creating numerical kernels in pystencils is the function create_kernel
.
- class pystencils.CreateKernelConfig(target=Target._CPU, jit=None, function_name='kernel', ghost_layers=None, iteration_slice=None, index_field=None, index_dtype=PsIntegerType(width=64, signed=True, const=False), default_dtype=PsIeeeFloatType(width=64, const=False), cpu_optim=None)¶
Options for create_kernel.
- Parameters:
-
target:
Target
= 1¶ The code generation target.
-
jit:
Optional
[JitBase
] = None¶ Just-in-time compiler used to compile and load the kernel for invocation from the current Python environment.
If left at None, a default just-in-time compiler will be inferred from the target parameter. To explicitly disable JIT compilation, pass pystencils.nbackend.jit.no_jit.
-
ghost_layers:
Union
[None
,int
,Sequence
[int
|tuple
[int
,int
]]] = None¶ Specifies the number of ghost layers of the iteration region.
- Options:
None: Required ghost layers are inferred from field accesses
int: A uniform number of ghost layers in each spatial coordinate is applied
Sequence[int, tuple[int, int]]
: Ghost layers are specified for each spatial coordinate.In each coordinate, a single integer specifies the ghost layers at both the lower and upper iteration limit, while a pair of integers specifies the lower and upper ghost layers separately.
When manually specifying ghost layers, it is the user’s responsibility to avoid out-of-bounds memory accesses. If
ghost_layers=None
is specified, the iteration region may otherwise be set using the iteration_slice option.
-
iteration_slice:
Optional
[Sequence
[slice
]] = None¶ Specifies the kernel’s iteration slice.
iteration_slice may only be set if
ghost_layers=None
. If it is set, a slice must be specified for each spatial coordinate. TODO: Specification of valid slices and their behaviour
-
index_field:
Optional
[Field
] = None¶ Index field for a sparse kernel.
If this option is set, a sparse kernel with the given field as index field will be generated.
-
index_dtype:
PsIntegerType
= PsIntegerType( width=64, signed=True, const=False )¶ Data type used for all index calculations.
-
default_dtype:
PsNumericType
= PsIeeeFloatType( width=64, const=False )¶ Default numeric data type.
This data type will be applied to all untyped symbols.
- pystencils.create_kernel(assignments, config=CreateKernelConfig(target=<Target._CPU: 1>, jit=<pystencils.backend.jit.jit.LegacyCpuJit object>, function_name='kernel', ghost_layers=None, iteration_slice=None, index_field=None, index_dtype=PsIntegerType( width=64, signed=True, const=False ), default_dtype=PsIeeeFloatType( width=64, const=False ), cpu_optim=None))¶
Create a kernel function from a set of assignments.
- Parameters:
assignments (
AssignmentCollection
|list
[Assignment
] |Assignment
) – The kernel’s sequence of assignments, expressed using SymPyconfig (
CreateKernelConfig
) – The configuration for the kernel translator
- Return type:
- Returns:
The numerical kernel in pystencil’s internal representation, ready to be exported or compiled
- class pystencils.backend.KernelFunction(body, target, name, parameters, required_headers, constraints, jit=<pystencils.backend.jit.jit.NoJit object>)¶
A pystencils kernel function.
The kernel function is the final result of the translation process. It is immutable, and its AST should not be altered any more, either, as this might invalidate information about the kernel already stored in the KernelFunction object.
- Parameters: