From 3309a5362a13f840e84a2f67b9ba7141aae58cc4 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Thu, 1 Oct 2020 18:50:46 -0700 Subject: TOSA spec 0.20.0, initial public version Change-Id: I7c528ebf7e78759ada4bb951b2471c367d3f4525 --- chapters/reduction.adoc | 303 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 chapters/reduction.adoc (limited to 'chapters/reduction.adoc') diff --git a/chapters/reduction.adoc b/chapters/reduction.adoc new file mode 100644 index 0000000..bef68a3 --- /dev/null +++ b/chapters/reduction.adoc @@ -0,0 +1,303 @@ +// +// This confidential and proprietary software may be used only as +// authorised by a licensing agreement from ARM Limited +// (C) COPYRIGHT 2020 ARM Limited +// ALL RIGHTS RESERVED +// The entire notice above must be reproduced on all authorised +// copies and copies may only be made to the extent permitted +// by a licensing agreement from ARM Limited. + +=== Reduction Operators + +==== REDUCE_ANY + +Reduce a tensor along the given axes with a logical OR operation + +*Arguments:* + +|=== +|Argument|Type|Name|Shape|Description + +|Input|in_t*|input|in_shape|Input tensor from 1 to 4 dims +|Attribute|int|axes|[]|List of axes with size from 1 to rank(input1). Values are integers into the 0-based dimensions of the input tensor. An empty list is not allowed. +|Attribute|int|keep_dims|-|If 1, axes reduced will be retained with length=1. +|Output|out_t*|output|out_shape|Output tensor. Same rank as the input tensor if keep_dims set, else one less than input tensor rank. +|=== + +*Operation Function:* + +[source,c] +---- +tmp_shape = in_shape; +for_each (axis in axes[]) { + tmp_shape[axis]=1; +} +if (keep_dims) assert(tmp_shape == out_shape) +for_each (index in tmp_shape) { + tensor_write(output, tmp_shape, index, false) +} +for_each (index in in_shape) { + tmp_index = index; + for each (axis in axes[]) { + tmp_index[axis]=0; + } + value = tensor_read(input, in_shape, index) + acc = tensor_read(output, tmp_shape, tmp_index) + acc = acc || value + tensor_write(output, tmp_shape, tmp_index, acc) +} +---- + +*Supported Data Types:* + +|=== +|Profile|Mode|in_t|out_t + +|Any|Boolean|bool|bool +|=== + +==== REDUCE_ALL + +Reduce a tensor along the given axes with a logical AND operation + +*Arguments:* + +|=== +|Argument|Type|Name|Shape|Description + +|Input|in_t*|input|in_shape|Input tensor from 1 to 4 dims +|Attribute|int|axes|[]|List of axes with size from 1 to rank(input1). Values are integers into the 0-based dimensions of the input tensor. An empty list is not allowed. +|Attribute|int|keep_dims|-|If 1, axes reduced will be retained with length=1. +|Output|out_t*|output|out_shape|Output tensor. Same rank as the input tensor if keep_dims set, else one less than input tensor rank. +|=== + +*Operation Function:* + +[source,c] +---- +tmp_shape = in_shape; +for_each (axis in axes[]) { + tmp_shape[axis]=1; +} +if (keep_dims) assert(tmp_shape == out_shape) +for_each (index in tmp_shape) { + tensor_write(output, tmp_shape, index, true) +} +for_each (index in in_shape) { + tmp_index = index; + for each (axis in axes[]) { + tmp_index[axis]=0; + } + value = tensor_read(input, in_shape, index) + acc = tensor_read(output, tmp_shape, tmp_index) + acc = acc && value + tensor_write(output, tmp_shape, tmp_index, acc) +} +---- + +*Supported Data Types:* + +|=== +|Profile|Mode|in_t|out_t + +|Any|Boolean|bool|bool +|=== + +==== REDUCE_MAX + +Reduce a tensor along the given axes with a maximum operation + +*Arguments:* + +|=== +|Argument|Type|Name|Shape|Description + +|Input|in_t*|input|in_shape|Input tensor from 1 to 4 dims +|Attribute|int|axes|[]|List of axes with size from 1 to rank(input1). Values are integers into the 0-based dimensions of the input tensor. An empty list is not allowed. +|Attribute|int|keep_dims|-|If 1, axes reduced will be retained with length=1. +|Output|out_t*|output|out_shape|Output tensor. Same rank as the input tensor if keep_dims set, else one less than input tensor rank. +|=== + +*Operation Function:* + +[source,c] +---- +tmp_shape = in_shape; +for_each (axis in axes[]) { + tmp_shape[axis]=1; +} +if (keep_dims) assert(tmp_shape == out_shape) +for_each (index in tmp_shape) { + tensor_write(output, tmp_shape, index, minimum) +} +for_each (index in in_shape) { + tmp_index = index; + for each (axis in axes[]) { + tmp_index[axis]=0; + } + value = tensor_read(input, in_shape, index) + acc = tensor_read(output, tmp_shape, tmp_index) + acc = apply_max(acc, value) + tensor_write(output, tmp_shape, tmp_index, acc) +} +---- + +*Supported Data Types:* + +|=== +|Profile|Mode|in_t|out_t + +|Any|signed 8|aint8|aint8 +|Any|signed 16|int16|int16 +|Any|signed 32|int32|int32 +|MI, MT|float|float|float +|=== + +==== REDUCE_MIN + +Reduce a tensor along the given axes with a minimum operation + +*Arguments:* +|=== +|Argument|Type|Name|Shape|Description + +|Input|in_t*|input|in_shape|Input tensor from 1 to 4 dims +|Attribute|int|axes|[]|List of axes with size from 1 to rank(input1). Values are integers into the 0-based dimensions of the input tensor. An empty list is not allowed. +|Attribute|int|keep_dims|-|If 1, axes reduced will be retained with length=1. +|Output|out_t*|output|out_shape|Output tensor. Same rank as the input tensor if keep_dims set, else one less than input tensor rank. +|=== + +*Quantization Parameters:* + +Quantization is ignored when doing the REDUCE_MIN operation. The input and output must maintain the same parameters. + +*Operation Function:* + +[source,c] +---- +tmp_shape = in_shape; +for_each (axis in axes[]) { + tmp_shape[axis]=1; +} +if (keep_dims) assert(tmp_shape == out_shape) +for_each (index in tmp_shape) { + tensor_write(output, tmp_shape, index, maximum) +} +for_each (index in in_shape) { + tmp_index = index; + for each (axis in axes[]) { + tmp_index[axis]=0; + } + value = tensor_read(input, in_shape, index) + acc = tensor_read(output, tmp_shape, tmp_index) + acc = apply_min(acc, value) + tensor_write(output, tmp_shape, tmp_index, acc) +} +---- + +*Supported Data Types:* + +|=== +|Profile|Mode|in_t|out_t + +|Any|signed 8|aint8|aint8 +|Any|signed 16|int16|int16 +|Any|signed 32|int32|int32 +|MI, MT|float|float|float +|=== + +==== REDUCE_PRODUCT + +Reduce a tensor along the given axes by computing the product of the axes. + +*Arguments:* + +|=== +|Argument|Type|Name|Shape|Description + +|Input|in_t*|input|in_shape|Input tensor from 1 to 4 dims +|Attribute|int|axes|[]|List of axes with size from 1 to rank(input1). Values are integers into the 0-based dimensions of the input tensor. An empty list is not allowed. +|Attribute|int|keep_dims|-|If 1, axes reduced will be retained with length=1. +|Output|out_t*|output|out_shape|Output tensor. Same rank as the input tensor if keep_dims set, else one less than input tensor rank. +|=== + +*Operation Function:* + +[source,c] +---- +tmp_shape = in_shape; +for_each (axis in axes[]) { + tmp_shape[axis]=1; +} +if (keep_dims) assert(tmp_shape == out_shape) +for_each (index in tmp_shape) { + tensor_write(output, tmp_shape, index, 1.0) +} +for_each (index in in_shape) { + tmp_index = index; + for each (axis in axes[]) { + tmp_index[axis]=0; + } + value = tensor_read(input, in_shape, index) + acc = tensor_read(output, tmp_shape, tmp_index) + acc = acc * value + tensor_write(output, tmp_shape, tmp_index, acc) +} +---- + +*Supported Data Types:* + +|=== +|Profile|Mode|in_t|out_t + +|MI, MT|float|float|float +|=== + +==== REDUCE_SUM + +Reduce a tensor along the given axes by computing the sum of the axes. + +*Arguments:* + +|=== +|Argument|Type|Name|Shape|Description + +|Input|in_t*|input|in_shape|Input tensor from 1 to 4 dims +|Attribute|int|axes|[]|List of axes with size from 1 to rank(input1). Values are integers into the 0-based dimensions of the input tensor. An empty list is not allowed. +|Attribute|int|keep_dims|-|If 1, axes reduced will be retained with length=1. +|Output|out_t*|output|out_shape|Output tensor. Same rank as the input tensor if keep_dims set, else one less than input tensor rank. +|=== + +*Operation Function:* + +[source,c] +---- +tmp_shape = in_shape; +for_each (axis in axes[]) { + tmp_shape[axis]=1; +} +if (keep_dims) assert(tmp_shape == out_shape) +for_each (index in tmp_shape) { + tensor_write(output, tmp_shape, index, 0) +} +for_each (index in in_shape) { + tmp_index = index; + for each (axis in axes[]) { + tmp_index[axis]=0; + } + value = tensor_read(input, in_shape, index) + acc = tensor_read(output, tmp_shape, tmp_index) + acc = apply_add(acc, value) + tensor_write(output, tmp_shape, tmp_index, acc) +} +---- + +*Supported Data Types:* + +|=== +|Profile|Mode|in_t|out_t + +|Any|signed 32|int32|int32 +|MI, MT|float|float|float +|=== + -- cgit v1.2.1