Contents

class

SushiBLAS::ReductionOps

Records reductions of a tensor into a scalar result tensor or along an axis.

Declared in
include/SushiBLAS/engine/math/reductions.hpp

Note

A whole-tensor reduction needs a contiguous operand with storage. The axis reductions honour strides. Var, std, logsumexp, argmax and argmin reject an empty tensor.

Public member functions

explicit ReductionOps(TaskRecorder &recorder) noexcept

Builds a view that records through recorder, which must outlive the view.

explicit ReductionOps(Engine &engine) noexcept

Builds a view that records on engine's own graph.

ReductionOps(const ReductionOps &)=default
ReductionOps & operator=(const ReductionOps &)=delete
ReductionOps(ReductionOps &&)=default
ReductionOps & operator=(ReductionOps &&)=delete
~ReductionOps()=default
TaskHandle sum(const Tensor &t, Tensor &result)

Sum of all elements.

Computes result = sum(t_i).

Parameters

t

Input tensor.

result

Scalar output tensor.

Returns

The handle of the recorded task.

TaskHandle mean(const Tensor &t, Tensor &result)

Mean of all elements.

Computes result = sum(t_i) / num_elements.

Parameters

t

Input tensor.

result

Scalar output tensor.

Returns

The handle of the recorded task.

TaskHandle max(const Tensor &t, Tensor &result)

Maximum value in the tensor.

Finds result = max(t_i). Any NaN element makes the result NaN; an empty tensor gives std::numeric_limits<T>::lowest().

Parameters

t

Input tensor.

result

Scalar output tensor.

Returns

The handle of the recorded task.

TaskHandle min(const Tensor &t, Tensor &result)

Minimum value in the tensor.

Finds result = min(t_i). Any NaN element makes the result NaN; an empty tensor gives std::numeric_limits<T>::max().

Parameters

t

Input tensor.

result

Scalar output tensor.

Returns

The handle of the recorded task.

TaskHandle argmax(const Tensor &t, Tensor &result)

Index of the maximum value.

Parameters

t

Input tensor.

result

Scalar INT64 tensor; receives the lowest index of the maximum.

Exceptions

std::invalid_argument

if t is empty.

Returns

The handle of the recorded task.

TaskHandle argmin(const Tensor &t, Tensor &result)

Index of the minimum value.

Parameters

t

Input tensor.

result

Scalar INT64 tensor; receives the lowest index of the minimum.

Exceptions

std::invalid_argument

if t is empty.

Returns

The handle of the recorded task.

TaskHandle var(const Tensor &t, Tensor &result)

Variance of all elements.

Parameters

t

Input tensor.

result

Scalar output tensor.

Exceptions

std::invalid_argument

if t is empty.

Returns

The handle of the recorded task.

TaskHandle std(const Tensor &t, Tensor &result)

Standard Deviation of all elements.

Parameters

t

Input tensor.

result

Scalar output tensor.

Exceptions

std::invalid_argument

if t is empty.

Returns

The handle of the recorded task.

TaskHandle prod(const Tensor &t, Tensor &result)

Product of all elements.

Parameters

t

Input tensor.

result

Scalar output tensor.

Returns

The handle of the recorded task.

TaskHandle logsumexp(const Tensor &t, Tensor &result)

Log-Sum-Exp reduction.

Computes result = log(sum(exp(t_i - max(t)))). Used for numerical stability in softmax calculations.

Parameters

t

Input tensor.

result

Scalar output tensor.

Exceptions

std::invalid_argument

if t is empty.

Returns

The handle of the recorded task.

TaskHandle max_along(const Tensor &t, int axis, Tensor &result)

Computes the maximum along one axis of a rank-2 tensor.

Parameters

axis

0 for a per-column maximum, 1 for a per-row maximum.

result

Rank-1 tensor of the surviving length, sharing t's dtype.

Exceptions

std::runtime_error

on a rank, axis, length or dtype mismatch.

See also

include/SushiBLAS/engine/math/README.md

TaskHandle sum_along(const Tensor &t, int axis, Tensor &result)

Computes the Neumaier-compensated sum along one axis of a rank-2 tensor.

Parameters

axis

0 for column sums, 1 for row sums.

result

Rank-1 tensor of the surviving length, sharing t's dtype.

Exceptions

std::runtime_error

on a rank, axis, length or dtype mismatch.

See also

include/SushiBLAS/engine/math/README.md

TaskHandle mean_spatial(const Tensor &t, Tensor &result)

Computes the mean over the two spatial axes of an NHWC tensor: [N, H, W, C] -> [N, C].

Parameters

t

Must be rank 4, NHWC, with rows contiguous with one another.

result

Rank-2 [N, C] tensor sharing t's dtype.

Exceptions

std::runtime_error

on a rank, shape, stride or dtype mismatch.

See also

include/SushiBLAS/engine/math/README.md

TaskHandle asum(const Tensor &t, Tensor &result)

L1 Norm (Sum of absolute values).

Parameters

t

Input tensor.

result

Scalar output tensor.

Returns

The handle of the recorded task.

TaskHandle nrm2(const Tensor &t, Tensor &result)

L2 Norm (Euclidean norm).

Parameters

t

Input tensor.

result

Scalar output tensor.

Returns

The handle of the recorded task.

TaskHandle count_nonfinite(const Tensor &t, Tensor &result)

Counts the elements of t that are infinite or NaN into an INT64 scalar.

Parameters

t

Must be HALF, FLOAT32 or FLOAT64.

result

Must hold exactly one element of dtype INT64.

Exceptions

std::runtime_error

if result is not an INT64 scalar or t's dtype is not real.

See also

include/SushiBLAS/engine/math/README.md