Internal Code Representation (pystencilssfg.ir
)#
- class pystencilssfg.ir.SfgCallTreeNode#
Base class for all nodes comprising SFG call trees.
## Code Printing
For extensibility, code printing is implemented inside the call tree. Therefore, every instantiable call tree node must implement the method
get_code
. By convention, the string returned byget_code
should not contain a trailing newline.- abstract property children: Sequence[SfgCallTreeNode]#
This node’s children
- abstract get_code(cstyle)#
Returns the code of this node.
By convention, the code block emitted by this function should not contain a trailing newline.
- property required_includes: set[HeaderFile]#
Return a set of header includes required by this node
- class pystencilssfg.ir.SfgCallTreeLeaf#
A leaf node of the call tree.
Leaf nodes must implement
depends
for automatic parameter collection.- property children: Sequence[SfgCallTreeNode]#
This node’s children
- class pystencilssfg.ir.SfgEmptyNode#
A leaf node that does not emit any code.
Empty nodes must still implement
depends
.
- class pystencilssfg.ir.SfgKernelCallNode(kernel_handle)#
- Parameters:
kernel_handle (SfgKernelHandle)
- class pystencilssfg.ir.SfgGpuKernelInvocation(kernel_handle, grid_size, block_size, shared_memory_bytes, stream)#
A CUDA or HIP kernel invocation.
See https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#execution-configuration or https://rocmdocs.amd.com/projects/HIP/en/latest/how-to/hip_cpp_language_extensions.html#calling-global-functions for the syntax.
- Parameters:
kernel_handle (SfgKernelHandle)
grid_size (SfgStatements)
block_size (SfgStatements)
shared_memory_bytes (SfgStatements | None)
stream (SfgStatements | None)
- property children: Sequence[SfgCallTreeNode]#
This node’s children
- class pystencilssfg.ir.SfgSequence(children)#
- Parameters:
children (Sequence[SfgCallTreeNode])
- property children: Sequence[SfgCallTreeNode]#
This node’s children
- class pystencilssfg.ir.SfgBlock(seq)#
- Parameters:
seq (SfgSequence)
- property children: Sequence[SfgCallTreeNode]#
This node’s children
- class pystencilssfg.ir.SfgStatements(code_string, defines, depends, includes=())#
Represents (a sequence of) statements in the source language.
This class groups together arbitrary code strings (e.g. sequences of C++ statements, cf. https://en.cppreference.com/w/cpp/language/statements), and annotates them with the set of symbols read and written by these statements.
It is the user’s responsibility to ensure that the code string is valid code in the output language, and that the lists of required and defined objects are correct and complete.
- Parameters:
code_string (
str
) – Code to be printed out.defined_params – Variables that will be newly defined and visible to code in sequence after these statements.
required_params – Variables that are required as input to these statements.
defines (Iterable[SfgVar])
depends (Iterable[SfgVar])
includes (Iterable[HeaderFile])
- class pystencilssfg.ir.SfgRequireIncludes(includes)#
- Parameters:
includes (Iterable[HeaderFile])
- class pystencilssfg.ir.SfgBranch(cond, branch_true, branch_false=None)#
- Parameters:
cond (SfgStatements)
branch_true (SfgSequence)
branch_false (SfgSequence | None)
- property children: Sequence[SfgCallTreeNode]#
This node’s children
- class pystencilssfg.ir.SfgSwitchCase(label, body)#
- Parameters:
label (str | SfgSwitchCase.DefaultCaseType)
body (SfgSequence)
- property children: Sequence[SfgCallTreeNode]#
This node’s children
- class pystencilssfg.ir.SfgSwitch(switch_arg, cases_dict, default=None)#
- Parameters:
switch_arg (SfgStatements)
cases_dict (dict[str, SfgSequence])
default (SfgSequence | None)
- property children: tuple[SfgCallTreeNode, ...]#
This node’s children
- class pystencilssfg.ir.SfgCodeEntity(name, parent_namespace)#
Base class for code entities.
Each code entity has a name and an optional enclosing namespace.
- Parameters:
name (str)
parent_namespace (SfgNamespace)
- property parent_namespace: SfgNamespace | None#
Parent namespace of this entity
- class pystencilssfg.ir.SfgNamespace(name, parent_namespace)#
A C++ namespace.
Each namespace has a name and a parent; its fully qualified name is given as
<parent.name>::<name>
.- Parameters:
name (
str
) – Local name of this namespaceparent – Parent namespace enclosing this namespace
parent_namespace (SfgNamespace)
- class pystencilssfg.ir.SfgGlobalNamespace#
The C++ global namespace.
- class pystencilssfg.ir.SfgKernelNamespace(name, parent)#
A namespace grouping together a number of kernels.
- Parameters:
name (str)
parent (SfgNamespace)
- property name#
Name of this entity
- class pystencilssfg.ir.SfgKernelHandle(name, namespace, kernel, inline=False)#
Handle to a pystencils kernel.
- Parameters:
name (str)
namespace (SfgKernelNamespace)
kernel (Kernel)
inline (bool)
- property parameters: Sequence[SfgKernelParamVar]#
Parameters to this kernel
- property fields#
Fields accessed by this kernel
- class pystencilssfg.ir.SfgFunction(name, namespace, tree, return_type=VoidType(), inline=False, constexpr=False, attributes=(), required_params=None)#
A free function.
- Parameters:
name (str)
namespace (SfgNamespace)
tree (SfgCallTreeNode)
return_type (PsType)
inline (bool)
constexpr (bool)
required_params (Sequence[SfgVar] | None)
- class pystencilssfg.ir.SfgVisibility(value)#
Visibility qualifiers of C++
- class pystencilssfg.ir.SfgClassKeyword(value)#
Class keywords of C++
- class pystencilssfg.ir.SfgClassMember(cls)#
Base class for class member entities
- Parameters:
cls (SfgClass)
- class pystencilssfg.ir.SfgMemberVariable(name, dtype, cls, default_init=None)#
Variable that is a field of a class
- class pystencilssfg.ir.SfgMethod(name, cls, tree, return_type=VoidType(), inline=False, const=False, static=False, constexpr=False, virtual=False, override=False, attributes=(), required_params=None)#
Instance method of a class
- class pystencilssfg.ir.SfgConstructor(cls, parameters=(), initializers=(), body='')#
Constructor of a class
- class pystencilssfg.ir.SfgClass(name, namespace, class_keyword=SfgClassKeyword.CLASS, bases=())#
A C++ class.
- Parameters:
name (str)
namespace (SfgNamespace)
class_keyword (SfgClassKeyword)
bases (Sequence[str])
- class pystencilssfg.ir.SfgEntityDecl(entity)#
Declaration of a function, class, method, or constructor
- Parameters:
entity (SourceEntity_T)
- class pystencilssfg.ir.SfgEntityDef(entity)#
Definition of a function, class, method, or constructor
- Parameters:
entity (SourceEntity_T)
- class pystencilssfg.ir.SfgVisibilityBlock(visibility)#
Visibility-qualified block inside a class definition body.
Visibility blocks host the code elements placed inside a class body: method and constructor declarations, in-class method and constructor definitions, as well as variable declarations and definitions.
- Parameters:
visibility (
SfgVisibility
) – The visibility qualifier of this block
- class pystencilssfg.ir.SfgNamespaceBlock(namespace, label=None)#
A C++ namespace block.
- Parameters:
namespace (
SfgNamespace
) – Namespace associated with this blocklabel (
Optional
[str
]) – Label printed at the opening brace of this block. This may be the namespace name, or a compressed qualified name containing one or more of its parent namespaces.
- property elements: list[str | SfgNamespaceBlock | SfgClassBody | SfgEntityDecl | SfgEntityDef]#
Sequence of source elements that make up the body of this namespace
- class pystencilssfg.ir.SfgClassBody(cls, default_block, vis_blocks)#
Body of a class definition.
- Parameters:
cls (SfgClass)
default_block (SfgVisibilityBlock)
vis_blocks (Iterable[SfgVisibilityBlock])
- class pystencilssfg.ir.SfgSourceFileType(value)#
An enumeration.
- class pystencilssfg.ir.SfgSourceFile(name, file_type, prelude=None)#
A C++ source file.
- Parameters:
name (
str
) – Name of the file (without parent directories), e.g.Algorithms.cpp
file_type (
SfgSourceFileType
) – Type of the source file (header or translation unit)prelude (
Optional
[str
]) – Optionally, text of the prelude comment printed at the top of the file
- property file_type: SfgSourceFileType#
File type of this source file
- property includes: list[HeaderFile]#
Sequence of header files to be included at the top of this file
- property elements: list[str | SfgNamespaceBlock | SfgClassBody | SfgEntityDecl | SfgEntityDef]#
Sequence of source elements comprising the body of this file
Postprocessing#
- class pystencilssfg.ir.postprocessing.PostProcessingResult(function_params)#
- class pystencilssfg.ir.postprocessing.SfgDeferredNode#
Nodes of this type are inserted as placeholders into the kernel call tree and need to be expanded at a later time.
Subclasses of SfgDeferredNode correspond to nodes that cannot be created yet because information required for their construction is not yet known.
- property children: Sequence[SfgCallTreeNode]#
This node’s children
- class pystencilssfg.ir.postprocessing.SfgDeferredParamSetter(param, rhs)#
- Parameters:
param (SfgVar | sp.Symbol)
rhs (ExprLike)
- class pystencilssfg.ir.postprocessing.SfgDeferredFieldMapping(psfield, extraction, cast_indexing_symbols=True)#
Deferred mapping of a pystencils field to a field data structure.
- Parameters:
psfield (Field)
extraction (SupportsFieldExtraction)
cast_indexing_symbols (bool)
- class pystencilssfg.ir.postprocessing.SfgDeferredVectorMapping(scalars, vector)#
- Parameters:
scalars (Sequence[sp.Symbol | SfgVar])
vector (SupportsVectorExtraction)