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

Method Run

executor/operator/common/lrn.cpp:84–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82 name_ = "com_lrn_fp32";
83 }
84 bool Run(Node* node)
85 {
86 Tensor* input_tensor = node->GetInputTensor(0);
87 Tensor* output_tensor = node->GetOutputTensor(0);
88
89 LRN* lrn_op = dynamic_cast<LRN*>(node->GetOp());
90 LRNParam* param = lrn_op->GetParam();
91
92 float* input = ( float* )get_tensor_mem(input_tensor);
93 float* output = ( float* )get_tensor_mem(output_tensor);
94
95 const TShape& shape = input_tensor->GetShape();
96 const std::vector<int>& dims = shape.GetDim();
97
98 int n = dims[0];
99 int c = dims[1];
100 int h = dims[2];
101 int w = dims[3];
102
103 int img_size = c * h * w;
104 float alpha = param->alpha;
105 float beta = param->beta;
106 float bias = param->k;
107 int local_size = param->local_size;
108 float alpha_over_size = alpha / local_size;
109
110 float* square = ( float* )(std::malloc(img_size * sizeof(float)));
111 int cpu_number = cpu_info->GetCPUNumber();
112 int num_task = c < cpu_number ? c : cpu_number;
113 int step = c / num_task;
114
115 for(int i = 0; i < n; i++)
116 {
117 /* get square value */
118
119 float* in_base = input + i * img_size;
120 float* out_base = output + i * img_size;
121
122 if(param->norm_region != LRN_ACROSS_CHANNELS)
123 {
124 LOG_ERROR()<<"LRN Only support ACORSS_CHANNEL\n";
125 return false;
126 }
127 else
128 {
129 for(int j = 0; j < img_size; j++)
130 square[j] = in_base[j] * in_base[j] + bias;
131 }
132 if(num_task == 1)
133 {
134 lrn_kernel(0, 0, &c, in_base, out_base, square, h, w, c, local_size, alpha_over_size, beta);
135 }
136 else
137 {
138 MULTI_THREAD_START(num_task, step, id, param)
139 lrn_kernel(0, id, param, in_base, out_base, square, h, w, c, local_size, alpha_over_size, beta);
140 MULTI_THREAD_END();
141 }

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected