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

Method Run

executor/operator/arm64/batch_norm.cpp:140–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138 }
139
140 bool Run(Node* node)
141 {
142 const Tensor* input_tensor = node->GetInputTensor(0);
143 Tensor* output_tensor = node->GetOutputTensor(0);
144 const TShape& shape = input_tensor->GetShape();
145 const std::vector<int> dims = shape.GetDim();
146
147 int batch_number = dims[0];
148 int channel_num = dims[1];
149 int channel_size = dims[2] * dims[3];
150 int img_size = channel_num * channel_size;
151
152 const float* input = ( const float* )get_tensor_mem(input_tensor);
153 float* output = ( float* )get_tensor_mem(output_tensor);
154
155 float* scale_mean = any_cast<float*>(node->GetAttr("scale_mean"));
156 float* scale_var_inv = any_cast<float*>(node->GetAttr("scale_var_inv"));
157
158
159 int cpu_number = cpu_info->GetCPUNumber();
160 int block = channel_num;
161 block = block > 0 ? block : 1;
162 int num_task = cpu_number < block ? cpu_number : block;
163 int step = channel_num / num_task;
164 /* only use mean and var */
165 for(int i = 0; i < batch_number; i++)
166 {
167 const float* cur_input = input + i * img_size;
168 float* cur_output = output + i * img_size;
169
170 if(num_task == 1)
171 batchnorm_kernel( 0, 0, &step, cur_input, cur_output, scale_mean, scale_var_inv, channel_size);
172 else
173 {
174 MULTI_THREAD_START(num_task, step, p_id, p_param)
175 batchnorm_kernel( 0, p_id, p_param, cur_input, cur_output, scale_mean, scale_var_inv, channel_size);
176 MULTI_THREAD_END();
177 }
178 if(num_task * step != channel_num)
179 {
180 int offset = num_task * step;
181 int remain_num = channel_num - offset;
182 cur_input += offset * channel_size;
183 cur_output += offset * channel_size;
184 batchnorm_kernel( 0, 0, &remain_num, cur_input, cur_output, scale_mean + offset, scale_var_inv + offset, channel_size);
185 }
186 }
187
188 return true;
189 }
190
191 bool Postrun(Node* node)
192 {

Callers

nothing calls this directly

Calls 6

get_tensor_memFunction · 0.85
GetCPUNumberMethod · 0.80
batchnorm_kernelFunction · 0.70
GetInputTensorMethod · 0.45
GetOutputTensorMethod · 0.45
GetAttrMethod · 0.45

Tested by

no test coverage detected