Code Generation#

Invocation#

create_kernel

Create a kernel function from a set of assignments.

Configuration#

The code generation driver (create_kernel, but also DefaultKernelCreationDriver) can be configured by passing it a CreateKernelConfig object. This object can be constructed incrementally:

cfg = ps.CreateKernelConfig()
cfg.default_dtype = "float32"
cfg.target = ps.Target.X86_AVX
cfg.cpu.openmp.enable = True
cfg.cpu.vectorize.enable = True
cfg.cpu.vectorize.assume_inner_stride_one = True

Options and Option Categories#

The following options and option categories are exposed by the configuration object:

Target Specification#

target

The code generation target.

Data Types#

default_dtype

Default numeric data type.

index_dtype

Data type used for all index calculations.

Iteration Space#

ghost_layers

Specifies the number of ghost layers of the iteration region.

iteration_slice

Specifies the kernel's iteration slice.

index_field

Index field for a sparse kernel.

Kernel Constraint Checks#

allow_double_writes

If True, don't check if every field is only written at a single location.

skip_independence_check

By default the assignment list is checked for read/write independence.

Target-Specific Options#

The following categories with target-specific options are exposed:

cpu

Options for CPU kernels

gpu

Options for GPU kernels

sycl

Options for SYCL kernels

Kernel Object and Just-In-Time Compilation#

function_name

Name of the generated function

jit

Just-in-time compiler used to compile and load the kernel for invocation from the current Python environment.

Configuration System Classes#

CreateKernelConfig

Options for create_kernel.

CpuOptions

Configuration options specific to CPU targets.

OpenMpOptions

Configuration options controlling automatic OpenMP instrumentation.

VectorizationOptions

Configuration for the auto-vectorizer.

GpuOptions

Configuration options specific to GPU targets.

SyclOptions

Options specific to the SYCL target.

GpuIndexingScheme

Available index translation schemes for GPU kernels.

AUTO

Special value that can be passed to some options for invoking automatic behaviour.

Implementation Details

Option

Option descriptor.

BasicOption

Subclass of Option where Arg_T == Option_T.

Category

Descriptor for a category of options.

ConfigBase

Base class for configuration categories.

Target Specification#

Target

The Target enumeration represents all possible targets that can be used for code generation.

Code Generation Driver and Helper Classes#

Driver#

DefaultKernelCreationDriver

Drives the default kernel creation sequence.

KernelFactory

Factory for wrapping up backend and IR objects into exportable kernels and function objects.

get_driver

Create a code generation driver object from the given configuration.

CPU Loop Strategies#

GPU Indexing#

HardwareProperties

GpuIndexMappingStrategy

GpuIndexing

Factory for GPU indexing objects required during code generation.

GpuLaunchConfiguration

Base class for launch configurations for CUDA and HIP kernels.

AutomaticLaunchConfiguration

Launch configuration that is dynamically computed from kernel parameters.

ManualLaunchConfiguration

Manual GPU launch configuration.

DynamicBlockSizeLaunchConfiguration

GPU launch configuration that dynamically computes the grid size from either the default block size or a computed block size.

Output Code Objects#

Kernel

A pystencils kernel.

GpuKernel

Internal representation of a kernel function targeted at CUDA GPUs.

Parameter

Parameter to an output object of the code generator.

Lambda

A one-line function emitted by the code generator as an auxiliary object.