Element-wise

A primitive to perform element-wise operations such as the rectifier linear unit (ReLU).

Both forward and backward propagation primitives support in-place operation; that is, src and dst can refer to the same memory for forward propagation, and diff_dst and diff_src can refer to the same memory for backward propagation.

Warning

Because the original source data is required for backward propagation, in-place forward propagation is not generally supported in the training mode. However, for ReLU with the alpha parameter set to 0, either dst or src can be used for the backward propagation, which makes possible a performance benefit even in the training mode.

API

struct dnnl::eltwise_forward : public dnnl::primitive

Elementwise unary operation forward propagation primitive.

Public Functions

eltwise_forward()

Default constructor. Produces an empty object.

eltwise_forward(const primitive_desc &pd)

Constructs an eltwise forward propagation primitive.

Parameters
  • pd: Primitive descriptor for an eltwise forward propagation primitive.

struct desc

Descriptor for an elementwise forward propagation primitive.

Public Functions

desc(prop_kind prop_kind, algorithm algorithm, const memory::desc &data_desc, float alpha = 0, float beta = 0)

Constructs a descriptor for an elementwise forward propagation primitive.

Inputs:

Outputs:

Parameters
  • prop_kind: Propagation kind. Possible values are dnnl::prop_kind::forward_training, and dnnl::prop_kind::forward_inference.

  • algorithm: Elementwise algorithm kind.

  • data_desc: Source and destination memory descriptors.

  • alpha: The alpha parameter for the elementwise operation. Specific meaning depends on the algorithm.

  • beta: The beta parameter for the elementwise operation. Specific meaning depends on the algorithm.

struct primitive_desc : public dnnl::primitive_desc

Primitive descriptor for an elementwise forward propagation primitive.

Public Functions

primitive_desc()

Default constructor. Produces an empty object.

primitive_desc(const desc &desc, const engine &engine, bool allow_empty = false)

Constructs a primitive descriptor for an elementwise forward propagation primitive.

Parameters
  • desc: Descriptor for an elementwise forward propagation primitive.

  • engine: Engine to use.

  • allow_empty: A flag signifying whether construction is allowed to fail without throwing an exception. In this case an empty object will be produced. This flag is optional and defaults to false.

primitive_desc(const desc &desc, const primitive_attr &attr, const engine &engine, bool allow_empty = false)

Constructs a primitive descriptor for an elementwise forward propagation primitive.

Parameters
  • desc: Descriptor for an elementwise forward propagation primitive.

  • engine: Engine to use.

  • attr: Primitive attributes to use.

  • allow_empty: A flag signifying whether construction is allowed to fail without throwing an exception. In this case an empty object will be produced. This flag is optional and defaults to false.

memory::desc src_desc() const

Returns a source memory descriptor.

Return

Source memory descriptor.

Return

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

memory::desc dst_desc() const

Returns a destination memory descriptor.

Return

Destination memory descriptor.

Return

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

struct dnnl::eltwise_backward : public dnnl::primitive

Elementwise unary operation backward propagation primitive.

See

eltwise_forward

Public Functions

eltwise_backward()

Default constructor. Produces an empty object.

eltwise_backward(const primitive_desc &pd)

Constructs an eltwise backward propagation primitive.

Parameters
  • pd: Primitive descriptor for an eltwise backward propagation primitive.

struct desc

Descriptor for an elementwise backward propagation primitive.

Public Functions

desc(algorithm algorithm, const memory::desc &diff_data_desc, const memory::desc &data_desc, float alpha = 0, float beta = 0)

Constructs a descriptor for an elementwise backward propagation primitive.

Inputs:

Outputs:

Parameters
  • algorithm: Elementwise algorithm kind.

  • diff_data_desc: Diff source and destination memory descriptors.

  • data_desc: Source memory descriptor.

  • alpha: The alpha parameter for the elementwise operation. Specific meaning depends on the algorithm.

  • beta: The beta parameter for the elementwise operation. Specific meaning depends on the algorithm.

struct primitive_desc : public dnnl::primitive_desc

Primitive descriptor for eltwise backward propagation.

Public Functions

primitive_desc()

Default constructor. Produces an empty object.

primitive_desc(const desc &desc, const engine &engine, const eltwise_forward::primitive_desc &hint_fwd_pd, bool allow_empty = false)

Constructs a primitive descriptor for an elementwise backward propagation primitive.

Parameters
  • desc: Descriptor for an elementwise backward propagation primitive.

  • engine: Engine to use.

  • hint_fwd_pd: Primitive descriptor for an elementwise forward propagation primitive. It is used as a hint for deciding which memory format to use.

  • allow_empty: A flag signifying whether construction is allowed to fail without throwing an exception. In this case an empty object will be produced. This flag is optional and defaults to false.

primitive_desc(const desc &desc, const primitive_attr &attr, const engine &engine, const eltwise_forward::primitive_desc &hint_fwd_pd, bool allow_empty = false)

Constructs a primitive descriptor for an elementwise backward propagation primitive.

Parameters
  • desc: Descriptor for an elementwise backward propagation primitive.

  • attr: Primitive attributes to use.

  • engine: Engine to use.

  • hint_fwd_pd: Primitive descriptor for an elementwise forward propagation primitive. It is used as a hint for deciding which memory format to use.

  • allow_empty: A flag signifying whether construction is allowed to fail without throwing an exception. In this case an empty object will be produced. This flag is optional and defaults to false.

memory::desc src_desc() const

Returns a source memory descriptor.

Return

Source memory descriptor.

Return

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

memory::desc diff_src_desc() const

Returns a diff source memory descriptor.

Return

Diff source memory descriptor.

Return

A zero memory descriptor if the primitive does not have a diff source memory with.

memory::desc diff_dst_desc() const

Returns a diff destination memory descriptor.

Return

Diff destination memory descriptor.

Return

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