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

Method Run

executor/operator/arm32/softmax_float.cpp:179–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177 }
178 }
179 bool Run(Node* node)
180 {
181 Tensor* input_tensor = node->GetInputTensor(0);
182 Tensor* output_tensor = node->GetOutputTensor(0);
183 const std::vector<int>& dims = input_tensor->GetShape().GetDim();
184 Softmax* softmax_op = dynamic_cast<Softmax*>(node->GetOp());
185 SoftmaxParam* param_ = softmax_op->GetParam();
186
187
188 int dim_size = dims.size();
189 int axis = param_->axis;
190 if(axis > dim_size)
191 axis = dim_size - 1;
192 int out_size, in_size, on_size;
193 out_size = 1;
194 for(int i = 0; i < axis; i++)
195 {
196 out_size *= dims[i];
197 }
198 in_size = 1;
199 for(size_t i = axis + 1; i < dims.size(); i++)
200 {
201 in_size *= dims[i];
202 }
203 on_size = dims[axis];
204
205 float* input = ( float* )get_tensor_mem(input_tensor);
206 float* output = ( float* )get_tensor_mem(output_tensor);
207 float* max_array = ( float* )std::malloc(in_size * cpu_number*sizeof(float));
208 float* sum_array = ( float* )std::malloc(in_size * cpu_number*sizeof(float));
209
210 int on_in_size = on_size * in_size;
211 if(cpu_number==1)
212 {
213 for(int i = 0; i < out_size; i++)
214 {
215 /* get max */
216 int img_base = i * on_in_size;
217 GetMaxArray(input + img_base, max_array, in_size, on_size);
218 GetOutResult(input + img_base, output + img_base, max_array, sum_array, in_size, on_size);
219 }
220 }
221 else
222 {
223 MULTI_THREAD_START(cpu_number, cpu_number, tid, param_step)
224 softmax_kernel(0, tid, param_step,
225 out_size, on_in_size,in_size,on_size,input,max_array,output,sum_array);
226 MULTI_THREAD_END();
227 }
228
229
230 std::free(max_array);
231 std::free(sum_array);
232 return true;
233 }
234};
235
236NodeOps* SelectFunc(const CPUInfo* cpu_info, Node* node)

Callers

nothing calls this directly

Calls 8

get_tensor_memFunction · 0.85
GetOpMethod · 0.80
GetParamMethod · 0.80
GetMaxArrayFunction · 0.50
GetOutResultFunction · 0.50
GetInputTensorMethod · 0.45
GetOutputTensorMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected