| 150 | } |
| 151 | |
| 152 | bool Run(Node* node) |
| 153 | { |
| 154 | // operator, param |
| 155 | Pooling* pooling_op = dynamic_cast<Pooling*>(node->GetOp()); |
| 156 | PoolParam* param_ = pooling_op->GetParam(); |
| 157 | |
| 158 | // input, output, shape |
| 159 | Tensor* itensor = node->GetInputTensor(0); |
| 160 | const TShape& ishape = itensor->GetShape(); |
| 161 | Tensor* otensor = node->GetOutputTensor(0); |
| 162 | TShape& oshape = otensor->GetShape(); |
| 163 | // dim=[n,h,w,c] |
| 164 | const std::vector<int>& in_dim = ishape.GetDim(); |
| 165 | const std::vector<int>& out_dim = oshape.GetDim(); |
| 166 | int in_hw = in_dim[1] * in_dim[2]; |
| 167 | int in_chw = in_dim[3] * in_hw; |
| 168 | |
| 169 | int out_hw = out_dim[1] * out_dim[2]; |
| 170 | int out_chw = out_dim[3] * out_hw; |
| 171 | // data |
| 172 | float* input_data = ( float* )get_tensor_mem(itensor); |
| 173 | float* output_data = ( float* )get_tensor_mem(otensor); |
| 174 | |
| 175 | #if 0 |
| 176 | printf("input: %d,%d,%d --> output: %d,%d \n", |
| 177 | in_dim[1], in_dim[2], in_dim[3], out_dim[2], out_dim[3]); |
| 178 | printf("kernel: %d, stride: %d, arg: %d, pad: %d,%d,%d,%d\n", |
| 179 | param_->kernel_h, param_->stride_h, param_->alg, |
| 180 | param_->pad_h0,param_->pad_w0,param_->pad_h1,param_->pad_w1); |
| 181 | #endif |
| 182 | int is_caffe = param_->caffe_flavor; |
| 183 | bool pooling_mt = exec_attr->pooling_mt; |
| 184 | int cpu_number = cpu_info->GetCPUNumber(); |
| 185 | if(in_dim[3] < 128) |
| 186 | pooling_mt = false; |
| 187 | for(int n = 0; n < in_dim[0]; n++) |
| 188 | { |
| 189 | float* in_ptr = input_data + n * in_chw; |
| 190 | float* out_ptr = output_data + n * out_chw; |
| 191 | if(!pooling_mt || cpu_number == 1) |
| 192 | { |
| 193 | kernel_run(in_ptr, out_ptr, in_dim[3], in_dim[1], in_dim[2], out_dim[1], out_dim[2], param_->kernel_h, |
| 194 | param_->kernel_w, param_->stride_h, param_->stride_w, param_->pad_h0, param_->pad_w0, |
| 195 | param_->pad_h1, param_->pad_w1, is_caffe, 0, in_dim[3]); |
| 196 | } |
| 197 | else |
| 198 | { |
| 199 | std::vector<sub_op_task> task_list; |
| 200 | std::vector<pooling_param> param_list; |
| 201 | |
| 202 | int max_thread = cpu_number; |
| 203 | int step = in_dim[3] / cpu_number; |
| 204 | if(step < 1) |
| 205 | { |
| 206 | step = 1; |
| 207 | max_thread = in_dim[3]; |
| 208 | } |
| 209 |
nothing calls this directly
no test coverage detected