Sum#

The sum primitive sums \(N\) tensors. The variable names follow the standard Conventions.

\[\dst(\overline{x}) = \sum\limits_{i = 1}^{N} scales(i) \cdot \src_i(\overline{x})\]

The sum primitive does not have a notion of forward or backward propagations. The backward propagation for the sum operation is simply an identity operation.

Execution Arguments#

When executed, the inputs and outputs should be mapped to an execution argument index as specified by the following table.

primitive input/output

execution argument index

\(\src\)

DNNL_ARG_MULTIPLE_SRC

\(\dst\)

DNNL_ARG_DST

Operation Details#

  • The \(\dst\) memory format can be either specified by a user or derived the most appropriate one by the primitive. The recommended way is to allow the primitive to choose the appropriate format.

  • The sum primitive requires all source and destination tensors to have the same shape. Implicit broadcasting is not supported.

Post-ops and Attributes#

The sum primitive does not support any post-ops or attributes.

Data Types Support#

The sum primitive supports arbitrary data types for source and destination tensors.

Data Representation#

Sources, Destination#

The sum primitive works with arbitrary data tensors. There is no special meaning associated with any logical dimensions.

API#

struct sum : public dnnl::primitive#

Out-of-place summation (sum) primitive.

Public Functions

sum()#

Default constructor. Produces an empty object.

sum(const primitive_desc &pd)#

Constructs a sum primitive.

Parameters:

pd – Primitive descriptor for sum primitive.

struct primitive_desc : public dnnl::primitive_desc_base#

Primitive descriptor for a sum primitive.

Public Functions

primitive_desc()#

Default constructor. Produces an empty object.

primitive_desc(const memory::desc &dst, const std::vector<float> &scales, const std::vector<memory::desc> &srcs, const engine &aengine, const primitive_attr &attr = primitive_attr())#

Constructs a primitive descriptor for a sum primitive.

Parameters:
  • dst – Destination memory descriptor.

  • scales – Vector of scales to multiply data in each source memory by.

  • srcs – Vector of source memory descriptors.

  • aengine – Engine to perform the operation on.

  • attr – Primitive attributes to use (optional).

primitive_desc(const std::vector<float> &scales, const std::vector<memory::desc> &srcs, const engine &aengine, const primitive_attr &attr = primitive_attr())#

Constructs a primitive descriptor for a sum primitive.

This version derives the destination memory descriptor automatically.

Parameters:
  • scales – Vector of scales by which to multiply data in each source memory object.

  • srcs – Vector of source memory descriptors.

  • aengine – Engine on which to perform the operation.

  • attr – Primitive attributes to use (optional).

memory::desc src_desc(int idx = 0) const#

Returns a source memory descriptor.

Parameters:

idx – Source index.

Returns:

Source memory descriptor.

Returns:

A zero memory descriptor if the primitive does not have a source parameter with index pdx.

memory::desc dst_desc() const#

Returns a destination memory descriptor.

Returns:

Destination memory descriptor.

Returns:

A zero memory descriptor if the primitive does not have a destination parameter.