ArmNN
 25.11
Loading...
Searching...
No Matches
LstmUtils.hpp File Reference
Include dependency graph for LstmUtils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void VectorBatchVectorAdd (armnn::Decoder< float > &vector, uint32_t vSize, armnn::Decoder< float > &batchVector, uint32_t nBatch, armnn::Encoder< float > &outResult)
void MeanStddevNormalization (armnn::Decoder< float > &input_vector, armnn::Encoder< float > &output_vector, uint32_t v_size, uint32_t n_batch, float normalization_epsilon)
void ZeroVector (armnn::Encoder< float > &vector, uint32_t vSize)
void MatrixBatchVectorMultiplyAccumulate (armnn::Decoder< float > &matrix, uint32_t mRows, uint32_t mCols, armnn::Decoder< float > &vector, uint32_t nBatch, armnn::Encoder< float > &outResult)
void VectorBatchVectorAssign (armnn::Decoder< float > &vector, uint32_t vSize, uint32_t nBatch, armnn::Encoder< float > &outBatchVector)
void VectorBatchVectorCwiseProductAccumulate (armnn::Decoder< float > &vector, uint32_t vSize, armnn::Decoder< float > &batchVector, uint32_t nBatch, armnn::Encoder< float > &outResult)
void VectorBatchVectorCwiseProduct (armnn::Decoder< float > &vector, uint32_t vSize, armnn::Decoder< float > &batchVector, uint32_t nBatch, armnn::Encoder< float > &outResult)
void Sub1Vector (armnn::Decoder< float > &vector, uint32_t vSize, armnn::Encoder< float > &result)
void VectorVectorCwiseProduct (armnn::Decoder< float > &vector1, armnn::Decoder< float > &vector2, uint32_t vSize, armnn::Encoder< float > &outResult)
void VectorVectorCwiseProductAccumulate (armnn::Decoder< float > &vector1, armnn::Decoder< float > &vector2, uint32_t vSize, armnn::Encoder< float > &outResult)
float Clip (float f, float absLimit)
void ClipVector (armnn::Decoder< float > &vector, uint32_t vSize, float absLimit, armnn::Encoder< float > &outResult)
void CopyVector (armnn::Decoder< float > &vector, uint32_t vSize, armnn::Encoder< float > &outResult)
void SetActivationParameters (uint32_t activation, armnn::ActivationFunction &outArmnnActivation, float &outA, float &outB)
std::unique_ptr< armnn::ScopedTensorHandleAssignScopedTensorHandle (const armnn::ConstTensorHandle *ptr)

Function Documentation

◆ AssignScopedTensorHandle()

std::unique_ptr< armnn::ScopedTensorHandle > AssignScopedTensorHandle ( const armnn::ConstTensorHandle * ptr)

Definition at line 299 of file LstmUtils.cpp.

300{
301 if (!ptr)
302 {
303 return nullptr;
304 }
305
306 return std::make_unique<armnn::ScopedTensorHandle>(*ptr);
307}

Referenced by RefLstmWorkload::RefLstmWorkload(), RefQLstmWorkload::RefQLstmWorkload(), and RefUnidirectionalSequenceLstmWorkload::RefUnidirectionalSequenceLstmWorkload().

◆ Clip()

float Clip ( float f,
float absLimit )

Definition at line 221 of file LstmUtils.cpp.

223{
224 float result = (absLimit < f) ? absLimit : f;
225 result = (-absLimit > result) ? -absLimit : result;
226 return result;
227}

Referenced by ClipVector().

◆ ClipVector()

void ClipVector ( armnn::Decoder< float > & vector,
uint32_t vSize,
float absLimit,
armnn::Encoder< float > & outResult )

Definition at line 229 of file LstmUtils.cpp.

233{
234 for (uint32_t v = 0; v < vSize; v++)
235 {
236 outResult.Set(Clip(vector.Get(), absLimit));
237 ++vector;
238 ++outResult;
239 }
240 vector -= vSize;
241 outResult -= vSize;
242}
float Clip(float f, float absLimit)
virtual IType Get() const =0
virtual void Set(IType right)=0

References Clip(), Decoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ CopyVector()

void CopyVector ( armnn::Decoder< float > & vector,
uint32_t vSize,
armnn::Encoder< float > & outResult )

Definition at line 244 of file LstmUtils.cpp.

247{
248 for (uint32_t v = 0; v < vSize; v++)
249 {
250 outResult.Set(vector.Get());
251 ++outResult;
252 ++vector;
253 }
254 outResult -= vSize;
255 vector -= vSize;
256}

References Decoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ MatrixBatchVectorMultiplyAccumulate()

void MatrixBatchVectorMultiplyAccumulate ( armnn::Decoder< float > & matrix,
uint32_t mRows,
uint32_t mCols,
armnn::Decoder< float > & vector,
uint32_t nBatch,
armnn::Encoder< float > & outResult )

Definition at line 87 of file LstmUtils.cpp.

93{
94 for (uint32_t b = 0; b < nBatch; b++)
95 {
96 for (uint32_t r = 0; r < mRows; r++)
97 {
98 vector += b * mCols;
99 for (uint32_t c = 0; c < mCols; c++)
100 {
101 outResult.Set(outResult.Get() + matrix.Get() * vector.Get());
102 ++matrix;
103 ++vector;
104 }
105 outResult += 1;
106 vector -= (b+1) * mCols;
107 }
108 matrix -= (mRows * mCols);
109 }
110 outResult -= (mRows * nBatch);
111}
virtual IType Get() const =0

References Decoder< IType >::Get(), Encoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ MeanStddevNormalization()

void MeanStddevNormalization ( armnn::Decoder< float > & input_vector,
armnn::Encoder< float > & output_vector,
uint32_t v_size,
uint32_t n_batch,
float normalization_epsilon )

Definition at line 40 of file LstmUtils.cpp.

45{
46 for (uint32_t batch = 0; batch < n_batch; ++batch) {
47 float sum = 0.0f;
48 float sum_sq = 0.0f;
49 for (uint32_t i = 0; i < v_size; ++i) {
50 sum += input_vector.Get();
51 sum_sq += input_vector.Get() * input_vector.Get();
52 ++input_vector;
53 }
54 input_vector -= v_size;
55
56 const float mean = sum / static_cast<float>(v_size);
57 float stddev_inv = 0.0f;
58 const float variance = sum_sq / static_cast<float>(v_size) - mean * mean;
59 if (variance == 0) {
60 stddev_inv = 1.0f / std::sqrt(normalization_epsilon);
61 } else {
62 stddev_inv = 1.0f / std::sqrt(variance);
63 }
64
65 for (uint32_t i = 0; i < v_size; ++i) {
66 output_vector.Set((input_vector.Get() - mean) * stddev_inv);
67 ++output_vector;
68 ++input_vector;
69 }
70 // Don't reset iterator to handle next batch
71 }
72 output_vector -= v_size * n_batch;
73 input_vector -= v_size * n_batch;
74}

References Decoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ SetActivationParameters()

void SetActivationParameters ( uint32_t activation,
armnn::ActivationFunction & outArmnnActivation,
float & outA,
float & outB )

Definition at line 258 of file LstmUtils.cpp.

262{
263 switch (activation)
264 {
265 case 0: // None
266 outA = 0;
267 outB = 0;
268 return;
269
270 case 1: // Relu
271 outArmnnActivation = armnn::ActivationFunction::ReLu;
272 outA = 0;
273 outB = 0;
274 return;
275
276 case 3: // Relu6
277 outArmnnActivation = armnn::ActivationFunction::BoundedReLu;
278 outA = 6;
279 outB = 0;
280 return;
281
282 case 4: // Tanh
283 outArmnnActivation = armnn::ActivationFunction::TanH;
284 outA = 1;
285 outB = 1;
286 return;
287
288 case 6: // Sigmoid
289 outArmnnActivation = armnn::ActivationFunction::Sigmoid;
290 outA = 0;
291 outB = 0;
292 return;
293
294 default:
295 throw armnn::Exception("Unsupported activation function: " + std::to_string(activation));
296 }
297}
Base class for all ArmNN exceptions so that users can filter to just those.
@ BoundedReLu
min(a, max(b, input)) ReLu1 & ReLu6.
Definition Types.hpp:92

References armnn::BoundedReLu, armnn::ReLu, armnn::Sigmoid, and armnn::TanH.

Referenced by armnn::LstmImpl().

◆ Sub1Vector()

void Sub1Vector ( armnn::Decoder< float > & vector,
uint32_t vSize,
armnn::Encoder< float > & result )

Definition at line 173 of file LstmUtils.cpp.

176{
177 for (uint32_t v = 0; v < vSize; v++)
178 {
179 result.Set(1.0f - vector.Get());
180 ++vector;
181 ++result;
182 }
183 vector -= vSize;
184 result -= vSize;
185}

References Decoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ VectorBatchVectorAdd()

void VectorBatchVectorAdd ( armnn::Decoder< float > & vector,
uint32_t vSize,
armnn::Decoder< float > & batchVector,
uint32_t nBatch,
armnn::Encoder< float > & outResult )

Definition at line 16 of file LstmUtils.cpp.

21{
22 for (uint32_t b = 0; b < nBatch; b++)
23 {
24 for (uint32_t v = 0; v < vSize; v++)
25 {
26 outResult.Set(batchVector.Get() + vector.Get());
27 ++outResult;
28 ++vector;
29 ++batchVector;
30 }
31 vector -= vSize;
32 }
33 batchVector -= vSize * nBatch;
34 outResult -= vSize * nBatch;
35}

References Decoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ VectorBatchVectorAssign()

void VectorBatchVectorAssign ( armnn::Decoder< float > & vector,
uint32_t vSize,
uint32_t nBatch,
armnn::Encoder< float > & outBatchVector )

Definition at line 113 of file LstmUtils.cpp.

117{
118 for (uint32_t b = 0; b < nBatch; b++)
119 {
120 for (uint32_t v = 0; v < vSize; v++)
121 {
122 outBatchVector.Set(vector.Get());
123 ++outBatchVector;
124 ++vector;
125 }
126 vector -= vSize;
127 }
128 outBatchVector -= (nBatch * vSize);
129}

References Decoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ VectorBatchVectorCwiseProduct()

void VectorBatchVectorCwiseProduct ( armnn::Decoder< float > & vector,
uint32_t vSize,
armnn::Decoder< float > & batchVector,
uint32_t nBatch,
armnn::Encoder< float > & outResult )

Definition at line 152 of file LstmUtils.cpp.

157{
158 for (uint32_t b = 0; b < nBatch; b++)
159 {
160 for (uint32_t v = 0; v < vSize; v++)
161 {
162 outResult.Set(vector.Get() * batchVector.Get());
163 ++outResult;
164 ++vector;
165 ++batchVector;
166 }
167 vector -= vSize;
168 }
169 batchVector -= vSize * nBatch;
170 outResult -= vSize * nBatch;
171}

References Decoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ VectorBatchVectorCwiseProductAccumulate()

void VectorBatchVectorCwiseProductAccumulate ( armnn::Decoder< float > & vector,
uint32_t vSize,
armnn::Decoder< float > & batchVector,
uint32_t nBatch,
armnn::Encoder< float > & outResult )

Definition at line 131 of file LstmUtils.cpp.

136{
137 for (uint32_t b = 0; b < nBatch; b++)
138 {
139 for (uint32_t v = 0; v < vSize; v++)
140 {
141 outResult.Set(outResult.Get() + vector.Get() * batchVector.Get());
142 ++outResult;
143 ++vector;
144 ++batchVector;
145 }
146 vector -= vSize;
147 }
148 batchVector -= vSize * nBatch;
149 outResult -= vSize * nBatch;
150}

References Decoder< IType >::Get(), Encoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ VectorVectorCwiseProduct()

void VectorVectorCwiseProduct ( armnn::Decoder< float > & vector1,
armnn::Decoder< float > & vector2,
uint32_t vSize,
armnn::Encoder< float > & outResult )

Definition at line 187 of file LstmUtils.cpp.

191{
192 for (uint32_t v = 0; v < vSize; v++)
193 {
194 outResult.Set(vector1.Get() * vector2.Get());
195 ++outResult;
196 ++vector1;
197 ++vector2;
198 }
199 outResult -= vSize;
200 vector1 -= vSize;
201 vector2 -= vSize;
202}

References Decoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ VectorVectorCwiseProductAccumulate()

void VectorVectorCwiseProductAccumulate ( armnn::Decoder< float > & vector1,
armnn::Decoder< float > & vector2,
uint32_t vSize,
armnn::Encoder< float > & outResult )

Definition at line 204 of file LstmUtils.cpp.

208{
209 for (uint32_t v = 0; v < vSize; v++)
210 {
211 outResult.Set(outResult.Get() + vector1.Get() * vector2.Get());
212 ++outResult;
213 ++vector1;
214 ++vector2;
215 }
216 outResult -= vSize;
217 vector1 -= vSize;
218 vector2 -= vSize;
219}

References Decoder< IType >::Get(), Encoder< IType >::Get(), and Encoder< IType >::Set().

Referenced by armnn::LstmImpl().

◆ ZeroVector()

void ZeroVector ( armnn::Encoder< float > & vector,
uint32_t vSize )

Definition at line 76 of file LstmUtils.cpp.

78{
79 for (uint32_t v = 0; v < vSize; v++)
80 {
81 vector.Set(0.0f);
82 ++vector;
83 }
84 vector -= vSize;
85}

References Encoder< IType >::Set().

Referenced by armnn::LstmImpl().