# firedrake.slate.slac package¶

## firedrake.slate.slac.compiler module¶

This is Slate’s Linear Algebra Compiler. This module is responsible for generating C++ kernel functions representing symbolic linear algebra expressions written in Slate.

This linear algebra compiler uses both Firedrake’s form compiler, the Two-Stage Form Compiler (TSFC) and COFFEE’s kernel abstract syntax tree (AST) optimizer. TSFC provides this compiler with appropriate kernel functions (in C) for evaluating integral expressions (finite element variational forms written in UFL). COFFEE’s AST base helps with the construction of code blocks throughout the kernel returned by: compile_expression.

The Eigen C++ library (http://eigen.tuxfamily.org/) is required, as all low-level numerical linear algebra operations are performed using this templated function library.

firedrake.slate.slac.compiler.compile_expression(slate_expr, tsfc_parameters=None)[source]

Takes a Slate expression slate_expr and returns the appropriate firedrake.op2.Kernel object representing the Slate expression.

Parameters
• slate_expr – a :class:’TensorBase’ expression.

• tsfc_parameters – an optional dict of form compiler parameters to be passed to TSFC during the compilation of ufl forms.

Returns: A tuple containing a SplitKernel(idx, kinfo)

## firedrake.slate.slac.kernel_builder module¶

class firedrake.slate.slac.kernel_builder.CoefficientInfo

Bases: tuple

Context information for creating coefficient temporaries.

Parameters
• space_index – An integer denoting the function space index.

• offset_index – An integer denoting the starting position in the vector temporary for assignment.

• shape – A singleton with an integer describing the shape of the coefficient temporary.

• vector – The slate.AssembledVector containing the relevant data to be placed into the temporary.

• local_temp – The local temporary for the coefficient vector.

Create new instance of CoefficientInfo(space_index, offset_index, shape, vector, local_temp)

property local_temp

Alias for field number 4

property offset_index

Alias for field number 1

property shape

Alias for field number 2

property space_index

Alias for field number 0

property vector

Alias for field number 3

class firedrake.slate.slac.kernel_builder.LocalKernelBuilder(expression, tsfc_parameters=None)[source]

Bases: object

The primary helper class for constructing cell-local linear algebra kernels from Slate expressions.

This class provides access to all temporaries and subkernels associated with a Slate expression. If the Slate expression contains nodes that require operations on already assembled data (such as the action of a slate tensor on a ufl.Coefficient), this class provides access to the expression which needs special handling.

Instructions for assembling the full kernel AST of a Slate expression is provided by the method construct_ast.

Constructor for the LocalKernelBuilder class.

Parameters
• expression – a TensorBase object.

• tsfc_parameters – an optional dict of parameters to provide to TSFC when constructing subkernels associated with the expression.

cell_facet_sym = <coffee.base.Symbol object>
cell_orientations_sym = <coffee.base.Symbol object>
cell_size_sym = <coffee.base.Symbol object>
coefficient(coefficient)[source]

Extracts the kernel arguments corresponding to a particular coefficient. This handles both the case when the coefficient is defined on a mixed or non-mixed function space.

coefficient_map[source]

Generates a mapping from a coefficient to its kernel argument symbol. If the coefficient is mixed, all of its split components will be returned.

context_kernels[source]

Gathers all ContextKernels containing all TSFC kernels, and integral type information.

coord_sym = <coffee.base.Symbol object>
expression_flops[source]
property integral_type

Returns the integral type associated with a Slate kernel.

it_sym = <coffee.base.Symbol object>
mesh_layer_sym = <coffee.base.Symbol object>
needs_cell_facets[source]

Searches for any embedded forms (by inspecting the ContextKernels) which require looping over cell facets. If any are found, this function returns True and False otherwise.

needs_mesh_layers[source]

Searches for any embedded forms (by inspecting the ContextKernels) which require mesh level information (extrusion measures). If any are found, this function returns True and False otherwise.

supported_integral_types = ['cell', 'interior_facet', 'exterior_facet', 'interior_facet_horiz_top', 'interior_facet_horiz_bottom', 'interior_facet_vert', 'exterior_facet_top', 'exterior_facet_bottom', 'exterior_facet_vert']
supported_subdomain_types = ['subdomains_exterior_facet', 'subdomains_interior_facet']
terminal_flops[source]

## firedrake.slate.slac.tsfc_driver module¶

class firedrake.slate.slac.tsfc_driver.ContextKernel

Bases: tuple

A bundled object containing TSFC subkernels corresponding to a particular integral type.

Parameters
• tensor – The terminal Slate tensor corresponding to the list of TSFC assembly kernels.

• coefficients – The local coefficients of the tensor contained in the integrands (arguments for TSFC subkernels).

• original_integral_type – The unmodified measure type of the form integrals.

• tsfc_kernels – A list of local tensor assembly kernels provided by TSFC.

Create new instance of ContextKernel(tensor, coefficients, original_integral_type, tsfc_kernels)

property coefficients

Alias for field number 1

property original_integral_type

Alias for field number 2

property tensor

Alias for field number 0

property tsfc_kernels

Alias for field number 3

firedrake.slate.slac.tsfc_driver.compile_terminal_form(tensor, prefix=None, tsfc_parameters=None)[source]

Compiles the TSFC form associated with a Slate Tensor object. This function will return a ContextKernel which stores information about the original tensor, integral types and the corresponding TSFC kernels.

Parameters
• tensor – A Slate Tensor.

• prefix – An optional string indicating the prefix for the subkernel.

• tsfc_parameters – An optional dict of parameters to provide TSFC.

Returns: A ContextKernel containing all relevant information.

firedrake.slate.slac.tsfc_driver.transform_integrals(integrals)[source]

Generates a mapping of the form:

{original_integral_type: transformed_integrals}

where the original_integral_type is the pre-transformed integral type. The transformed_integrals are an iterable of ufl.Integrals with the appropriately modified type. For example, an interior_facet integral will become an exterior_facet integral.

## firedrake.slate.slac.utils module¶

class firedrake.slate.slac.utils.RemoveRestrictions[source]

UFL MultiFunction for removing any restrictions on the integrals of forms.

expr(o, *ops)

Reuse object if operands are the same objects.

Use in your own subclass by setting e.g.

expr = MultiFunction.reuse_if_untouched


as a default rule.

positive_restricted(o)[source]
class firedrake.slate.slac.utils.SymbolWithFuncallIndexing(symbol, rank=None, offset=None)[source]

Bases: coffee.base.Symbol

A functionally equivalent representation of a coffee.Symbol, with modified output for rank calls. This is syntactically necessary when referring to symbols of Eigen::MatrixBase objects.

class firedrake.slate.slac.utils.Transformer[source]

Bases: coffee.visitor.Visitor

Replaces all out-put tensor references with a specified name of :type: Eigen::Matrix with appropriate shape. This class is primarily for COFFEE acrobatics, jumping through nodes and redefining where appropriate.

The default name of "A" is assigned, otherwise a specified name may be passed as the name keyword argument when calling the visitor.

visit_Decl(o, *args, **kwargs)[source]

Visits a declared tensor and changes its type to :template: result Eigen::MatrixBase<Derived>.

i.e. double A[n][m] —> const Eigen::MatrixBase<Derived> &A_

visit_FunDecl(o, *args, **kwargs)[source]

Visits a COFFEE FunDecl object and reconstructs the FunDecl body and header to generate Eigen::MatrixBase C++ template functions.

Creates a template function for each subkernel form.

template <typename Derived>
static inline void foo(Eigen::MatrixBase<Derived> const & A, ...)
{
[Body...]
}

visit_Node(o, *args, **kwargs)

A visit method that reconstructs nodes if their children have changed.

visit_Symbol(o, *args, **kwargs)[source]

Visits a COFFEE symbol and redefines it as a Symbol with FunCall indexing.

i.e. A[j][k] —> A(j, k)

visit_list(o, *args, **kwargs)[source]

Visits an input of COFFEE objects and returns the complete list of said objects.

visit_object(o, *args, **kwargs)[source]

Visits an object and returns it.

e.g. string —> string

A recursive depth-first search (DFS) algorithm for traversing a DAG consisting of Slate expressions.

Parameters
• graph – A DAG whose nodes (vertices) are Slate expressions with edges connected to dependent expressions.

• node – A starting vertex.

• visited – A set keeping track of visited nodes.

• schedule – A list of reverse-postordered nodes. This list is used to produce a topologically sorted list of Slate nodes.

firedrake.slate.slac.utils.eigen_tensor(expr, temporary, index)[source]

Returns an appropriate assignment statement for populating a particular Eigen::MatrixBase tensor. If the tensor is mixed, then access to the block() of the eigen tensor is provided. Otherwise, no block information is needed and the tensor is returned as is.

Parameters
• expr – a slate.Tensor node.

• temporary – the associated temporary of the expr argument.

• index – a tuple of integers used to determine row and column information. This is provided by the SplitKernel associated with the expr.

firedrake.slate.slac.utils.topological_sort(exprs)[source]

Topologically sorts a list of Slate expressions. The expression graph is constructed by relating each Slate node with a list of dependent Slate nodes.

Parameters

exprs – A list of Slate expressions.

firedrake.slate.slac.utils.traverse_dags(exprs)[source]

Traverses a set of DAGs and returns each node.

Parameters

exprs – An iterable of Slate expressions.