kernel Module

class kernel.Constant(name, value)

Bases: object

Class representing a numerical constant.

This class can be used to use placeholders for constants in kernels.

Parameters:
  • name (str) – Name of constant
  • value – Numerical value (can actually be any data type)
replace(s)

Replace all occurrences in a string and return result

Ignores the constant if it is not a C-variable. For example, if the name of the constant is mass, then it would not replace it in mass1 or Hmass.

Parameters:s (str) – string to work on
class kernel.Cpp11MT19937

Bases: kernel.Module

get_cpp_arguments_ast()

Return the code to define arguments to add to the library.

get_cpp_headers_ast()

Return the code to include the required header file(s).

get_cpp_post_loop_code_ast()

Return the code to place after the loop.

get_cpp_pre_loop_code_ast()

Return the code to place before the loop.

get_python_parameters()

Return the parameters to add to the launch of the shared library.

class kernel.Header(name, system=True)

Bases: object

class kernel.Kernel(name, code, constants=None, headers=None, reductions=None, static_args=None)

Bases: object

Computational kernel, i.e. C-code + numerical constants.

Stores the C source code of a kernel and substitutes in any numerical constants that are to be copied it when the class is created.

Parameters:
  • name – name of the kernel
  • code – C source code
  • constants – List of constants (type Constant) which are to be substituted in.
  • reductions – list of reductions required by kernel if using parallel looping.
code

Kernel source code after substitution of numerical constants

headers

Return C headers required for kernel

hexdigest()

Unique md5 hexdigest which is used for identifying the kernel.

name

Kernel name.

reduction_variable_lookup(var)

Provides a method to determine if a variable undergoes a Reduction.

static_args
class kernel.Module

Bases: object

get_cpp_arguments_ast()

Return the code to define arguments to add to the library.

get_cpp_headers_ast()

Return the code to include the required header file(s).

get_cpp_post_loop_code_ast()

Return the code to place after the loop.

get_cpp_pre_loop_code_ast()

Return the code to place before the loop.

get_python_parameters()

Return the parameters to add to the launch of the shared library.

class kernel.Reduction(variable, pointer, operator='+')

Bases: object

Object to store Reduction operations required by kernels. Currently holds only one Reduction per instance.

Parameters:
  • variable (str) – Variable name eg ‘u’.
  • pointer (str) – C pointer syntax of variable being reduced upon eg ‘u[0]’.
  • operator (char) – operator performed in Reduction, default ‘+’.
index

Returns index in C pointer syntax, eg u[0] returns 0

operator

Returns C operator

pointer

Returns C pointer syntax

variable

Returns variable name

kernel.analyse(kernel_in=None, dat_dict=None)
Parameters:
  • kernel_in (kernel) – Kernel to analyse.
  • dat_dict (list) – List of variables which should be assumed are in global memory.
Returns:

Dict of operations and their estimated number of occurences.

Previous topic

host Module

Next topic

loop Module

This Page