Common

Base class for primitives

struct dnnl::primitive

Base class for all computational primitives.

Subclassed by dnnl::batch_normalization_backward, dnnl::batch_normalization_forward, dnnl::binary, dnnl::concat, dnnl::convolution_backward_data, dnnl::convolution_backward_weights, dnnl::convolution_forward, dnnl::deconvolution_backward_data, dnnl::deconvolution_backward_weights, dnnl::deconvolution_forward, dnnl::eltwise_backward, dnnl::eltwise_forward, dnnl::gru_backward, dnnl::gru_forward, dnnl::inner_product_backward_data, dnnl::inner_product_backward_weights, dnnl::inner_product_forward, dnnl::layer_normalization_backward, dnnl::layer_normalization_forward, dnnl::lbr_gru_backward, dnnl::lbr_gru_forward, dnnl::logsoftmax_backward, dnnl::logsoftmax_forward, dnnl::lrn_backward, dnnl::lrn_forward, dnnl::lstm_backward, dnnl::lstm_forward, dnnl::matmul, dnnl::pooling_backward, dnnl::pooling_forward, dnnl::reorder, dnnl::resampling_backward, dnnl::resampling_forward, dnnl::shuffle_backward, dnnl::shuffle_forward, dnnl::softmax_backward, dnnl::softmax_forward, dnnl::sum, dnnl::vanilla_rnn_backward, dnnl::vanilla_rnn_forward

Public Types

enum kind

Kinds of primitives supported by the library.

Values:

enumerator undef

Undefined primitive.

enumerator reorder

A reorder primitive.

enumerator shuffle

A shuffle primitive.

enumerator concat

A (out-of-place) tensor concatenation primitive.

enumerator sum

A summation primitive.

enumerator convolution

A convolution primitive.

enumerator deconvolution

A deconvolution primitive.

enumerator eltwise

An element-wise primitive.

enumerator softmax

A softmax primitive.

enumerator pooling

A pooling primitive.

enumerator lrn

An LRN primitive.

enumerator batch_normalization

A batch normalization primitive.

enumerator layer_normalization

A layer normalization primitive.

enumerator inner_product

An inner product primitive.

enumerator rnn

A rnn primitive.

enumerator binary

A binary primitive.

enumerator logsoftmax

A logsoftmax primitive.

enumerator matmul

A matmul (matrix multiplication) primitive.

enumerator resampling

A resampling primitive.

Public Functions

primitive()

Default constructor. Constructs an empty object.

primitive(const primitive_desc_base &pd)

Constructs a primitive from a primitive descriptor.

Parameters
  • pd: Primitive descriptor.

kind get_kind() const

Returns the kind of the primitive.

Return

The primitive kind.

void execute(const stream &stream, const std::unordered_map<int, memory> &args) const

Executes computations specified by the primitive in a specified stream.

Arguments are passed via an arguments map containing <index, memory object> pairs. The index must be one of the DNNL_ARG_* values such as DNNL_ARG_SRC, and the memory must have a memory descriptor matching the one returned by primitive_desc::query_md(query::exec_arg_md, index) unless using dynamic shapes (see DNNL_RUNTIME_DIM_VAL).

Parameters
  • stream: Stream object. The stream must belong to the same engine as the primitive.

  • args: Arguments map.

cl::sycl::event execute_sycl(const stream &stream, const std::unordered_map<int, memory> &args, const std::vector<cl::sycl::event> &deps = {}) const

Executes computations specified by the primitive in a specified stream.

Arguments are passed via an arguments map containing <index, memory object> pairs. The index must be one of the DNNL_ARG_* values such as DNNL_ARG_SRC, and the memory must have a memory descriptor matching the one returned by primitive_desc::query_md(query::exec_arg_md, index) unless using dynamic shapes (see DNNL_RUNTIME_DIM_VAL).

Parameters
  • stream: Stream object. The stream must belong to the same engine as the primitive.

  • args: Arguments map.

  • deps: Optional vector with cl::sycl::event dependencies.

primitive &operator=(const primitive &rhs)

Assignment operator.

Normalization primitives flags

enum dnnl::normalization_flags

Flags for normalization primitives (can be combined via ‘|’)

Values:

enumerator none

Use no normalization flags. If specified, the library computes mean and variance on forward propagation for training and inference, outputs them on forward propagation for training, and computes the respective derivatives on backward propagation.

enumerator use_global_stats = 0x1u

Use global statistics. If specified, the library uses mean and variance provided by the user as an input on forward propagation and does not compute their derivatives on backward propagation. Otherwise, the library computes mean and variance on forward propagation for training and inference, outputs them on forward propagation for training, and computes the respective derivatives on backward propagation.

enumerator use_scale_shift = 0x2u

Use scale and shift parameters. If specified, the user is expected to pass scale and shift as inputs on forward propagation. On backward propagation of type dnnl::prop_kind::backward, the library computes their derivatives. If not specified, the scale and shift parameters are not used by the library in any way.

enumerator fuse_norm_relu = 0x4u

Fuse normalization with ReLU. On training, normalization will require the workspace to implement backward propagation. On inference, the workspace is not required and behavior is the same as when normalization is fused with ReLU using the post-ops API.

Execution argument indices

DNNL_ARG_SRC_0

Source argument #0.

DNNL_ARG_SRC

A special mnemonic for source argument for primitives that have a single source. An alias for DNNL_ARG_SRC_0.

DNNL_ARG_SRC_LAYER

A special mnemonic for RNN input vector. An alias for DNNL_ARG_SRC_0.

DNNL_ARG_FROM

A special mnemonic for reorder source argument. An alias for DNNL_ARG_SRC_0.

DNNL_ARG_SRC_1

Source argument #1.

DNNL_ARG_SRC_ITER

A special mnemonic for RNN input recurrent hidden state vector. An alias for DNNL_ARG_SRC_1.

DNNL_ARG_SRC_2

Source argument #2.

DNNL_ARG_SRC_ITER_C

A special mnemonic for RNN input recurrent cell state vector. An alias for DNNL_ARG_SRC_2.

DNNL_ARG_DST_0

Destination argument #0.

DNNL_ARG_DST

A special mnemonic for destination argument for primitives that have a single destination. An alias for DNNL_ARG_DST_0.

DNNL_ARG_TO

A special mnemonic for reorder destination argument. An alias for DNNL_ARG_DST_0.

DNNL_ARG_DST_LAYER

A special mnemonic for RNN output vector. An alias for DNNL_ARG_DST_0.

DNNL_ARG_DST_1

Destination argument #1.

DNNL_ARG_DST_ITER

A special mnemonic for RNN input recurrent hidden state vector. An alias for DNNL_ARG_DST_1.

DNNL_ARG_DST_2

Destination argument #2.

DNNL_ARG_DST_ITER_C

A special mnemonic for LSTM output recurrent cell state vector. An alias for DNNL_ARG_DST_2.

DNNL_ARG_WEIGHTS_0

Weights argument #0.

DNNL_ARG_WEIGHTS

A special mnemonic for primitives that have a single weights argument. Alias for DNNL_ARG_WEIGHTS_0.

DNNL_ARG_SCALE_SHIFT

A special mnemonic for scale and shift argument of normalization primitives. Alias for DNNL_ARG_WEIGHTS_0.

DNNL_ARG_WEIGHTS_LAYER

A special mnemonic for RNN weights applied to the layer input. An alias for DNNL_ARG_WEIGHTS_0.

DNNL_ARG_WEIGHTS_1

Weights argument #1.

DNNL_ARG_WEIGHTS_ITER

A special mnemonic for RNN weights applied to the recurrent input. An alias for DNNL_ARG_WEIGHTS_1.

DNNL_ARG_BIAS

Bias tensor argument.

DNNL_ARG_MEAN

Mean values tensor argument.

DNNL_ARG_VARIANCE

Variance values tensor argument.

DNNL_ARG_WORKSPACE

Workspace tensor argument. Workspace is used to pass information from forward propagation to backward propagation computations.

DNNL_ARG_SCRATCHPAD

Scratchpad (temporary storage) tensor argument.

DNNL_ARG_DIFF_SRC_0

Gradient (diff) of the source argument #0.

DNNL_ARG_DIFF_SRC

A special mnemonic for primitives that have a single diff source argument. An alias for DNNL_ARG_DIFF_SRC_0.

DNNL_ARG_DIFF_SRC_LAYER

A special mnemonic for gradient (diff) of RNN input vector. An alias for DNNL_ARG_DIFF_SRC_0.

DNNL_ARG_DIFF_SRC_1

Gradient (diff) of the source argument #1.

DNNL_ARG_DIFF_SRC_ITER

A special mnemonic for gradient (diff) of RNN input recurrent hidden state vector. An alias for DNNL_ARG_DIFF_SRC_1.

DNNL_ARG_DIFF_SRC_2

Gradient (diff) of the source argument #2.

DNNL_ARG_DIFF_SRC_ITER_C

A special mnemonic for gradient (diff) of RNN input recurrent cell state vector. An alias for DNNL_ARG_DIFF_SRC_1.

DNNL_ARG_DIFF_DST_0

Gradient (diff) of the destination argument #0.

DNNL_ARG_DIFF_DST

A special mnemonic for primitives that have a single diff destination argument. An alias for DNNL_ARG_DIFF_DST_0.

DNNL_ARG_DIFF_DST_LAYER

A special mnemonic for gradient (diff) of RNN output vector. An alias for DNNL_ARG_DIFF_DST_0.

DNNL_ARG_DIFF_DST_1

Gradient (diff) of the destination argument #1.

DNNL_ARG_DIFF_DST_ITER

A special mnemonic for gradient (diff) of RNN input recurrent hidden state vector. An alias for DNNL_ARG_DIFF_DST_1.

DNNL_ARG_DIFF_DST_2

Gradient (diff) of the destination argument #2.

DNNL_ARG_DIFF_DST_ITER_C

A special mnemonic for gradient (diff) of RNN input recurrent cell state vector. An alias for DNNL_ARG_DIFF_DST_2.

DNNL_ARG_DIFF_WEIGHTS_0

Gradient (diff) of the weights argument #0.

DNNL_ARG_DIFF_WEIGHTS

A special mnemonic for primitives that have a single diff weights argument. Alias for DNNL_ARG_DIFF_WEIGHTS_0.

DNNL_ARG_DIFF_SCALE_SHIFT

A special mnemonic for diff of scale and shift argument of normalization primitives. Alias for DNNL_ARG_DIFF_WEIGHTS_0.

DNNL_ARG_DIFF_WEIGHTS_LAYER

A special mnemonic for diff of RNN weights applied to the layer input. An alias for DNNL_ARG_DIFF_WEIGHTS_0.

DNNL_ARG_DIFF_WEIGHTS_1

Gradient (diff) of the weights argument #1.

DNNL_ARG_DIFF_WEIGHTS_ITER

A special mnemonic for diff of RNN weights applied to the recurrent input. An alias for DNNL_ARG_DIFF_WEIGHTS_1.

DNNL_ARG_DIFF_BIAS

Gradient (diff) of the bias tensor argument.

DNNL_ARG_ATTR_OUTPUT_SCALES

Output scaling factors provided at execution time.

DNNL_ARG_MULTIPLE_SRC

Starting index for source arguments for primitives that take a variable number of source arguments.

DNNL_ARG_MULTIPLE_DST

Starting index for destination arguments for primitives that produce a variable number of destination arguments.

DNNL_ARG_ATTR_ZERO_POINTS

Zero points provided at execution time.

DNNL_RUNTIME_DIM_VAL

A wildcard value for dimensions that are unknown at a primitive creation time.

DNNL_RUNTIME_SIZE_VAL

A size_t counterpart of the DNNL_RUNTIME_DIM_VAL. For instance, this value is returned by dnnl::memory::desc::get_size() if either of the dimensions or strides equal to DNNL_RUNTIME_DIM_VAL.

DNNL_RUNTIME_F32_VAL

A wildcard value for floating point values that are unknown at a primitive creation time.

DNNL_RUNTIME_S32_VAL

A wildcard value for int32_t values that are unknown at a primitive creation time.