MCPcopy Create free account
hub / github.com/OAID/Tengine / Run

Method Run

executor/operator/common/arm/lrn_arm.cpp:238–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236 }
237
238 bool Run(Node* node)
239 {
240 Tensor* input_tensor = node->GetInputTensor(0);
241 Tensor* output_tensor = node->GetOutputTensor(0);
242
243 LRN* lrn_op = dynamic_cast<LRN*>(node->GetOp());
244 LRNParam* param = lrn_op->GetParam();
245
246 const float* input = ( float* )get_tensor_mem(input_tensor);
247 float* output = ( float* )get_tensor_mem(output_tensor);
248
249 float* square = ( float* )(std::malloc(input_tensor->GetTotalSize()));
250
251 const TShape& shape = input_tensor->GetShape();
252 const std::vector<int>& dims = shape.GetDim();
253
254 int n = dims[0];
255 int c = dims[1];
256 int h = dims[2];
257 int w = dims[3];
258
259 int img_size = c * h * w;
260 int channel_size = h * w;
261 float alpha = param->alpha;
262 float beta = param->beta;
263 float bias = param->k;
264 int local_size = param->local_size;
265
266 int cpu_number = cpu_info->GetCPUNumber();
267 int num_task = c < cpu_number ? c : cpu_number;
268 int step = c / num_task;
269 for(int i = 0; i < n; i++)
270 {
271 /* get square value */
272 const float* img_base = input + i * img_size;
273 float* out_base = output + i * img_size;
274
275 int j = 0;
276 for(j = 0; j < (img_size & -4); j+=4)
277 {
278 float32x4_t in = vld1q_f32(img_base + j);
279 in = vmulq_f32(in, in);
280 vst1q_f32(square + j, in);
281 }
282 for(; j < img_size; j++)
283 square[j] = img_base[j] * img_base[j];
284
285 if(param->norm_region != LRN_ACROSS_CHANNELS)
286 {
287 std::free(square);
288 LOG_ERROR() << "LRN: Only support Across_channels\n";
289 return false;
290 }
291 if(num_task == 1)
292 {
293 lrn_kernel(0, 0, &step, img_base, out_base, square, alpha, beta, bias,
294 local_size, channel_size, c);
295 }

Callers

nothing calls this directly

Calls 8

get_tensor_memFunction · 0.85
lrn_kernelFunction · 0.85
GetOpMethod · 0.80
GetParamMethod · 0.80
GetTotalSizeMethod · 0.80
GetCPUNumberMethod · 0.80
GetInputTensorMethod · 0.45
GetOutputTensorMethod · 0.45

Tested by

no test coverage detected