Internal Code Representation (pystencilssfg.ir)

Contents

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 by get_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.

Return type:

str

Parameters:

cstyle (CodeStyle)

property depends: set[SfgVar]#

Set of objects this leaf depends on

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.

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

class pystencilssfg.ir.SfgKernelCallNode(kernel_handle)#
Parameters:

kernel_handle (SfgKernelHandle)

property depends: set[SfgVar]#

Set of objects this leaf depends on

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

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:
property children: Sequence[SfgCallTreeNode]#

This node’s children

property depends: set[SfgVar]#

Set of objects this leaf depends on

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

class pystencilssfg.ir.SfgSequence(children)#
Parameters:

children (Sequence[SfgCallTreeNode])

property children: Sequence[SfgCallTreeNode]#

This node’s children

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

class pystencilssfg.ir.SfgBlock(seq)#
Parameters:

seq (SfgSequence)

property children: Sequence[SfgCallTreeNode]#

This node’s children

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

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])

property depends: set[SfgVar]#

Set of objects this leaf depends on

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

class pystencilssfg.ir.SfgFunctionParams(parameters)#
Parameters:

parameters (Sequence[SfgVar])

property depends: set[SfgVar]#

Set of objects this leaf depends on

class pystencilssfg.ir.SfgRequireIncludes(includes)#
Parameters:

includes (Iterable[HeaderFile])

property depends: set[SfgVar]#

Set of objects this leaf depends on

class pystencilssfg.ir.SfgBranch(cond, branch_true, branch_false=None)#
Parameters:
property children: Sequence[SfgCallTreeNode]#

This node’s children

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

class pystencilssfg.ir.SfgSwitchCase(label, body)#
Parameters:
class DefaultCaseType#

Sentinel type representing the default case.

alias of object

property children: Sequence[SfgCallTreeNode]#

This node’s children

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

class pystencilssfg.ir.SfgSwitch(switch_arg, cases_dict, default=None)#
Parameters:
property children: tuple[SfgCallTreeNode, ...]#

This node’s children

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

class pystencilssfg.ir.SfgCodeEntity(name, parent_namespace)#

Base class for code entities.

Each code entity has a name and an optional enclosing namespace.

Parameters:
property name: str#

Name of this entity

property fqname: str#

Fully qualified name of this entity

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 namespace

  • parent – Parent namespace enclosing this namespace

  • parent_namespace (SfgNamespace)

get_entity(qual_name)#

Find an entity with the given qualified name within this namespace.

If qual_name contains any qualifying delimiters ::, each component but the last is interpreted as a namespace.

Return type:

SfgCodeEntity | None

Parameters:

qual_name (str)

class pystencilssfg.ir.SfgGlobalNamespace#

The C++ global namespace.

property fqname: str#

Fully qualified name of this entity

class pystencilssfg.ir.SfgKernelNamespace(name, parent)#

A namespace grouping together a number of kernels.

Parameters:
property name#

Name of this entity

class pystencilssfg.ir.SfgKernelHandle(name, namespace, kernel, inline=False)#

Handle to a pystencils kernel.

Parameters:
property parameters: Sequence[SfgKernelParamVar]#

Parameters to this kernel

property scalar_parameters: set[SfgVar]#

Scalar parameters to this kernel

property fields#

Fields accessed by this kernel

property kernel: Kernel#

Underlying pystencils kernel object

class pystencilssfg.ir.SfgFunction(name, namespace, tree, return_type=VoidType(), inline=False, constexpr=False, attributes=(), required_params=None)#

A free function.

Parameters:
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

Parameters:
  • name (str)

  • dtype (PsType)

  • cls (SfgClass)

  • default_init (tuple[ExprLike, ...] | None)

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

Parameters:
class pystencilssfg.ir.SfgConstructor(cls, parameters=(), initializers=(), body='')#

Constructor of a class

Parameters:
class pystencilssfg.ir.SfgClass(name, namespace, class_keyword=SfgClassKeyword.CLASS, bases=())#

A C++ class.

Parameters:
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 block

  • label (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:
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 name: str#

Name of this source file

property file_type: SfgSourceFileType#

File type of this source file

property prelude: str | None#

Text of the prelude comment

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)#
Parameters:

function_params (set[SfgVar])

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

get_code(cstyle)#

Returns the code of this node.

By convention, the code block emitted by this function should not contain a trailing newline.

Return type:

str

Parameters:

cstyle (CodeStyle)

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:
class pystencilssfg.ir.postprocessing.SfgDeferredVectorMapping(scalars, vector)#
Parameters: