UpdateScalarInRows

#include <popops/UpdateScalarInRows.hpp>

Functions for updating values in tensors.

namespace popops

Common functions, such as elementwise and reductions.

Functions

void updateScalarInRows(poplar::Graph &graph, const poplar::Tensor &params, const poplar::Tensor &indices, poplar::program::Sequence &program, const poplar::DebugContext &debugContext = {})

Update in-place one scalar per row of the tensor params.

For each row, the index of the value to update is specified by the tensor indices. If the index from indices is equal to MASKED_LABEL_CODE then no update is carried out.

Pseudo-code:

for each row r
  if indices[r] != MASKED_LABEL_CODE
    params[r][indices[r]] = params[r][indices[r]] - 1.f

If the ith index is less than 0 or greater than the size of the row then the whole row of the param tensor is set to NaN. This is to match the interface of the backward phase of tf.nn.sparse_softmax_cross_entropy_with_logits, see https://www.tensorflow.org/api_docs/python/tf/nn/sparse_softmax_cross_entropy_with_logits

Parameters
  • graph – The Poplar graph.

  • params – The 2D tensor to be updated, the element type must be either float or half.

  • indices – 1D tensor, the element-type must be unsigned integer.

  • program – The program to be extended.

  • debugContext – Optional debug information.