aboutsummaryrefslogtreecommitdiff
path: root/chapters/tensor_ops.adoc
blob: a36a7f1810b791778b4f10402db1c70edb531b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// This confidential and proprietary software may be used only as
// authorised by a licensing agreement from ARM Limited
// (C) COPYRIGHT 2020-2024 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.

=== Tensor Operators

==== ARGMAX

This returns the index with the largest value across the given axis of the input tensor.
If multiple locations have equal values, returns the first match along the search axis.
NaN values always compare as greater than non-NaN values.
If an entire axis consists of NaN, the last location must be returned.

include::{generated}/operators/ARGMAX.adoc[]

[source,c++]
----
include::{pseudocode}/operators/ARGMAX.tosac[lines=10..-1]
----

==== AVG_POOL2D

This performs an average pooling over the given input tensor.
A sliding window of size given by <kernel size> is passed over the input tensor, with the mean value being placed in the output tensor.
When calculating the average, only the number of valid input tensor values, but not padding, are used to calculate the divisor.

include::{generated}/operators/AVG_POOL2D.adoc[]

[source,c++]
----
include::{pseudocode}/operators/AVG_POOL2D.tosac[lines=10..-1]
----

==== CONV2D

Performs a 2D convolution over the given tensor input, using the weight tensor.

include::{generated}/operators/CONV2D.adoc[]

[source,c++]
----
include::{pseudocode}/operators/CONV2D.tosac[lines=10..-1]
----

==== CONV3D

Performs a 3D convolution over the given input tensor.

include::{generated}/operators/CONV3D.adoc[]

[source,c++]
----
include::{pseudocode}/operators/CONV3D.tosac[lines=10..-1]
----

==== DEPTHWISE_CONV2D

Performs 2D convolutions separately over each channel of the given tensor input, using the weight tensor.

include::{generated}/operators/DEPTHWISE_CONV2D.adoc[]

[source,c++]
----
include::{pseudocode}/operators/DEPTHWISE_CONV2D.tosac[lines=10..-1]
----

==== FFT2D

Performs a batched complex 2D Fast Fourier Transform over the input.
The complex input values are constructed from the corresponding values in the input_real and input_imag tensors.
The resulting values in the output are split into the output_real and output_imag tensors.
No normalization is applied on either the forward or inverse versions of the operation.

// output[h][w] = \sum_{m=0}^{H-1}\sum_{n=0}^{W-1}input[m][n] * \exp\left(-2\pi i\left(\frac{mh}{H} + \frac{nw}{W}\right)\right)

.Calculation for the forward FFT2D calculation (inverse=false)
image::forward_fft2d.svg["forward FFT definition", align="center"]

// output[h][w] = \sum_{m=0}^{H-1}\sum_{n=0}^{W-1}input[m][n] * \exp\left(2\pi i\left(\frac{mh}{H} + \frac{nw}{W}\right)\right)

.Calculation for the inverse FFT2D calculation (inverse=true)
image::inverse_fft2d.svg["inverse FFT definition", align="center"]

include::{generated}/operators/FFT2D.adoc[]

[source,c++]
----
include::{pseudocode}/operators/FFT2D.tosac[lines=10..-1]
----

==== FULLY_CONNECTED

Performs a fully connected network.

include::{generated}/operators/FULLY_CONNECTED.adoc[]

[source,c++]
----
include::{pseudocode}/operators/FULLY_CONNECTED.tosac[lines=10..-1]
----

==== MATMUL

Performs two dimensional matrix multiplications. This allows both inputs to be activations, rather than reserving weights as an attribute in the FULLY_CONNECTED operator.

include::{generated}/operators/MATMUL.adoc[]

[source,c++]
----
include::{pseudocode}/operators/MATMUL.tosac[lines=10..-1]
----

==== MAX_POOL2D

This performs a max pooling over the given input tensor. A sliding window of size given by <kernel size> is passed over the input tensor, with the maximum value being placed in the output tensor.

include::{generated}/operators/MAX_POOL2D.adoc[]

[source,c++]
----
include::{pseudocode}/operators/MAX_POOL2D.tosac[lines=10..-1]
----

==== RFFT2D

Performs a batched 2D real-valued Fast Fourier Transform over the input where the input tensor consists of real values producing complex valued output.
The complex output values will be split into the output_real and output_imag tensor arguments.
RFFT2D takes advantage of Hermitian symmetry to only calculate the first half of the final output axis.
Imaginary values with locations (0,0), (0,W/2), (H/2,0) and (H/2,W/2) are zero.

// output[h][w] = \sum_{m=0}^{H-1}\sum_{n=0}^{W-1}input[m][n] * \exp\left(-2\pi i\left(\frac{mh}{H} + \frac{nw}{W}\right)\right)

image::forward_fft2d.svg["forward RFFT definition", align="center"]

include::{generated}/operators/RFFT2D.adoc[]

[source,c++]
----
include::{pseudocode}/operators/RFFT2D.tosac[lines=10..-1]
----

==== TRANSPOSE_CONV2D

Performs a 2D transposed convolution over the given tensor input, using the weights tensor.

include::{generated}/operators/TRANSPOSE_CONV2D.adoc[]

[source,c++]
----
include::{pseudocode}/operators/TRANSPOSE_CONV2D.tosac[lines=10..-1]
----