Skip to content

Stencil

#include <stencil.hh>
template<int NDIM>
class Stencil

Defined in src/lib/ncarray/expression/stencil.hh:57

A Stencil for defining expressions over an array with determined offsets.

A Stencil holds the offsets and set of operations for reducing the host-time cost of constructing the expression evaluation infrastructure each time that an expression is evaluated. If the same operation(s) is(are) being performed many times with solely the underlying pointers being changed, then the Stencil can reduce the overall execution time significantly.

A Stencil can only be created to evaluate operations that run on a single array. Examples include convolutions, or reductions that can be expressed in terms of arithmetic operations on sub-views of the array.

  • NDIM The number of dimensions of the array operands.
Name Kind Owner
Stencil function Declared here
apply function Declared here
create function Declared here
m_kernel variable Declared here
m_instrs variable Declared here
m_offsets variable Declared here
m_constants_buf variable Declared here
m_constants_offsets variable Declared here
m_work_dtype variable Declared here
m_expr_dtype variable Declared here
Return Name Description
Stencil Defaulted constructor.
void apply inline Apply the stencil.

Stencil() = default

Defined in src/lib/ncarray/expression/stencil.hh:59

Defaulted constructor.


inline

template<ViewArrayLike Src, OwningArrayLike Dest> inline void apply(const Src & src, Dest & dest, std::optional< cudaStream_t > stream = std::nullopt)

Defined in src/lib/ncarray/expression/stencil.hh:176

Apply the stencil.

Run the pre-constructed kernel on an input array and a pre-created output array. The input must match the input used for creation of the kernel in the number and location of pointer axes as well as the dimensionality. A CUDA stream may be provided to run the execution on, if desired.

NOTE: If a stream is provided for running the kernel on, this function will NOT synchronize. This constrasts with other APIs which always do before returning control the host caller. This is because if a stream is passed in order to record the kernel as part of a graph, synchronization is NOT permitted in the capture. Since it is not possible to know whether the stream is provided in order to construct a graph, or not, all synchronization is the caller’s responsibility when providing a stream.

  • Src The input array type.

  • Dest The output array type.

  • src The input array.

  • dest The output array.

  • stream Optionally, provide a stream to launch the kernel on.

Return Name Description
Stencil< NDIM > create static inline Create a stencil from a set of relative offsets and a math function.

static inline

template<typename SrcT, typename Func> static inline Stencil< NDIM > create(const std::vector< StaticCoords< NDIM > > & offsets_in, const std::vector< std::uint8_t > & is_pointer_axis, Func && op_func, bool is_soarr = false)

Defined in src/lib/ncarray/expression/stencil.hh:74

Create a stencil from a set of relative offsets and a math function.

  • T The array datatype.

  • Func The lambda type for the expression to be evaluated.

  • offsets_in List of StaticCoords representing the window (e.g. {0,0}, {0,1}…)

  • is_pointer_axis A vector of flags for whether each dimension is a pointer dim. The compiled kernel will only work for arrays that have the same kinds of pointer dimensions (although shape and stride can vary freely).

  • op_func A lambda that takes a vector of views and returns an expression.

  • is_soarr A boolean flag as to whether SOArrayPolicy traversal is needed.

Return Name Description
CUfunction m_kernel
std::vector< Instruction > m_instrs
std::vector< StaticCoords< NDIM > > m_offsets
std::vector< std::uint8_t > m_constants_buf
std::vector< std::uint16_t > m_constants_offsets
DType m_work_dtype
DType m_expr_dtype

CUfunction m_kernel

Defined in src/lib/ncarray/expression/stencil.hh:230


std::vector< Instruction > m_instrs

Defined in src/lib/ncarray/expression/stencil.hh:231


std::vector< StaticCoords< NDIM > > m_offsets

Defined in src/lib/ncarray/expression/stencil.hh:232


std::vector< std::uint8_t > m_constants_buf

Defined in src/lib/ncarray/expression/stencil.hh:234


std::vector< std::uint16_t > m_constants_offsets

Defined in src/lib/ncarray/expression/stencil.hh:235


DType m_work_dtype

Defined in src/lib/ncarray/expression/stencil.hh:237


DType m_expr_dtype

Defined in src/lib/ncarray/expression/stencil.hh:238