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 ( 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, compiler_parameters=None, coffee=False)[source]

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

  • 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.CellFacetKernelArg(ast_arg)[source]

Bases: KernelArg

class firedrake.slate.slac.kernel_builder.CoefficientInfo(space_index, offset_index, shape, vector, local_temp)

Bases: tuple

Context information for creating coefficient temporaries.

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


Alias for field number 4


Alias for field number 1


Alias for field number 2


Alias for field number 0


Alias for field number 3

class firedrake.slate.slac.kernel_builder.IndexCreator[source]

Bases: object

property domains

ISL domains for the currently known indices.

class firedrake.slate.slac.kernel_builder.LayerCountKernelArg(ast_arg)[source]

Bases: KernelArg

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.

  • 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>

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.


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


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

coord_sym = <coffee.base.Symbol object>
property integral_type

Returns the integral type associated with a Slate kernel.

it_sym = <coffee.base.Symbol object>
mesh_layer_count_sym = <coffee.base.Symbol object>
mesh_layer_sym = <coffee.base.Symbol object>

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.


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']
class firedrake.slate.slac.kernel_builder.LocalLoopyKernelBuilder(expression, tsfc_parameters=None)[source]

Bases: object

Constructor for the LocalGEMKernelBuilder class.

  • expression – a TensorBase object.

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

cell_facets_arg_name = 'cell_facets'
cell_orientations_arg_name = 'cell_orientations'
cell_sizes_arg_name = 'cell_sizes'

Saves all coefficients of self.expression where non-mixed coefficients are dicts of form {coeff: (name, extent)} and mixed coefficients are double dicts of form {mixed_coeff: {coeff_per_space: (name, extent)}}.

collect_tsfc_kernel_data(mesh, tsfc_coefficients, wrapper_coefficients, kinfo)[source]

Collect the kernel data aka the parameters fed into the subkernel, that are coordinates, orientations, cell sizes and cofficients.

coordinates_arg_name = 'coords'

Calculation of the range of a coefficient.

facet_integral_predicates(mesh, integral_type, kinfo)[source]
generate_lhs(tensor, temp)[source]

Generation of an lhs for the loopy kernel, which contains the TSFC assembly of the tensor.

generate_tsfc_calls(terminal, loopy_tensor)[source]

A setup method to initialize all the local assembly kernels generated by TSFC. This function also collects any information regarding orientations and extra include directories.

initialise_terminals(var2terminal, coefficients)[source]

Initilisation of the variables in which coefficients and the Tensors coming from TSFC are saved.


var2terminal – dictionary that maps Slate Tensors to gem Variables

is_integral_type(integral_type, type)[source]
layer_arg_name = 'layer'
layer_count_name = 'layer_count'
layer_integral_predicates(tensor, integral_type)[source]
local_facet_array_arg_name = 'facet_array'

This method generates loopy arguments from the kernel data, which are then fed to the TSFC loopy kernel. The arguments are arrays and have to be fed element by element to loopy aka they have to be subarrayrefed.


A helper method to retrieve tensor shape information. In particular needed for the right shape of scalar tensors.

slate_call(prg, temporaries)[source]
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']

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

class firedrake.slate.slac.kernel_builder.SlateWrapperBag(coeffs)[source]

Bases: object

firedrake.slate.slac.optimise module

class firedrake.slate.slac.optimise.ActionBag(coeff, pick_op)

Bases: tuple

Create new instance of ActionBag(coeff, pick_op)


Alias for field number 0


Alias for field number 1


Remove double transposes from optimised Slate expression.


Flip an index. Using this function essentially reverses the order of multiplication.

firedrake.slate.slac.optimise.optimise(expression, parameters)[source]

Optimises a Slate expression, by pushing blocks and multiplications inside the expression and by removing double transposes.

  • expression – A (potentially unoptimised) Slate expression.

  • parameters – A dict of compiler parameters.

Returns: An optimised Slate expression


Executes a Slate compiler optimisation pass. The optimisation is achieved by pushing blocks from the outside to the inside of an expression. Without the optimisation the local TSFC kernels are assembled first and then the result of the assembly kernel gets indexed in the Slate kernel (and further linear algebra operations maybe done on it). The optimisation pass essentially changes the order of assembly and indexing.


expression – A (potentially unoptimised) Slate expression.

Returns: An optimised Slate expression, where Blocks are terminal whereever possible.


Executes a Slate compiler optimisation pass. The optimisation is achieved by pushing DiagonalTensor from the outside to the inside of an expression.


expression – A (potentially unoptimised) Slate expression.

Returns: An optimised Slate expression, where DiagonalTensors are sitting on terminal tensors whereever possible.

firedrake.slate.slac.optimise.push_mul(tensor, options)[source]

Executes a Slate compiler optimisation pass. The optimisation is achieved by pushing coefficients from the outside to the inside of an expression. The optimisation pass essentially changes the order of operations in the expressions so that only matrix-vector products are executed.

  • tensor – A (potentially unoptimised) Slate expression.

  • options – Optimisation pass options, e.g. if the multiplication should be replaced by an action.

Returns: An optimised Slate expression,

where only matrix-vector products are executed whereever possible.

firedrake.slate.slac.tsfc_driver module

class firedrake.slate.slac.tsfc_driver.ContextKernel(tensor, coefficients, original_integral_type, tsfc_kernels)

Bases: tuple

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

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


Alias for field number 1


Alias for field number 2


Alias for field number 0


Alias for field number 3

firedrake.slate.slac.tsfc_driver.compile_terminal_form(tensor, prefix, *, tsfc_parameters=None, coffee=True)[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.

  • 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.


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.Integral`s 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]

Bases: MultiFunction

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.

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

Bases: 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: 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, ...)
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.

  • 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.merge_loopy(slate_loopy, output_arg, builder, var2terminal, name)[source]

Merges tsfc loopy kernels and slate loopy kernel into a wrapper kernel.

firedrake.slate.slac.utils.slate2gem(expression, options)[source]
firedrake.slate.slac.utils.slate_to_gem(expression, options)[source]

Convert a slate expression to gem.


expression – A slate expression.


A singleton list of gem expressions and a mapping from gem variables to UFL “terminal” forms.


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


exprs – A list of Slate expressions.

Module contents