conv_compute_test.cc 22.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gflags/gflags.h>
#include <gtest/gtest.h>
#include "lite/core/context.h"
18
#include "lite/core/profile/timer.h"
19 20 21 22 23 24 25 26
#include "lite/operators/op_params.h"
#include "lite/tests/utils/naive_math_impl.h"
#include "lite/tests/utils/tensor_utils.h"

#ifdef LITE_WITH_ARM
#include "lite/kernels/arm/conv_compute.h"
#endif  // LITE_WITH_ARM

27 28 29 30 31 32 33
DEFINE_int32(power_mode,
             3,
             "power mode: "
             "0 for POWER_HIGH;"
             "1 for POWER_LOW;"
             "2 for POWER_FULL;"
             "3 for NO_BIND");
34 35 36
DEFINE_int32(threads, 1, "threads num");
DEFINE_int32(warmup, 0, "warmup times");
DEFINE_int32(repeats, 1, "repeats times");
37
DEFINE_bool(basic_test, true, "do all tests");
38 39 40 41 42 43 44 45 46 47 48
DEFINE_bool(check_result, true, "check the result");

DEFINE_int32(batch, 1, "batch size");
DEFINE_int32(in_channel, 32, "input channel");
DEFINE_int32(in_height, 112, "input height");
DEFINE_int32(in_width, 112, "input width");

DEFINE_int32(out_channel, 32, "output channel");
DEFINE_int32(group, 1, "group");
DEFINE_int32(kernel_h, 3, "kernel height");
DEFINE_int32(kernel_w, 3, "kernel width");
49 50 51 52
DEFINE_int32(pad_h0, 1, "pad top");
DEFINE_int32(pad_h1, 1, "pad bottom");
DEFINE_int32(pad_w0, 1, "pad left");
DEFINE_int32(pad_w1, 1, "pad right");
53 54 55 56 57
DEFINE_int32(stride_h, 1, "stride height");
DEFINE_int32(stride_w, 1, "stride width");
DEFINE_int32(dila_h, 1, "dilation height");
DEFINE_int32(dila_w, 1, "dilation width");

58 59 60 61
DEFINE_int32(flag_act,
             0,
             "do activation");  // 0-no act, 1-relu, 2-relu6, 4-leakyrelu
DEFINE_double(leakey_relu_alpha, 1.0, "leakey relu alpha");
62 63 64 65 66
DEFINE_bool(flag_bias, true, "with bias");

typedef paddle::lite::DDim DDim;
typedef paddle::lite::Tensor Tensor;
typedef paddle::lite::operators::ConvParam ConvParam;
67 68
typedef paddle::lite::operators::ActivationParam ActivationParam;

69
using paddle::lite::profile::Timer;
70 71 72 73

DDim compute_out_dim(const DDim& dim_in,
                     const paddle::lite::operators::ConvParam& param) {
  DDim dim_out = dim_in;
H
HappyAngel 已提交
74 75
  auto paddings = *param.paddings;
  auto dilations = *param.dilations;
76 77 78 79 80
  dim_out[1] = param.filter->dims()[0];
  auto kernel_h = param.filter->dims()[2];
  auto kernel_w = param.filter->dims()[3];
  auto h = dim_in[2];
  auto w = dim_in[3];
H
HappyAngel 已提交
81 82 83 84 85 86
  int dila_h = dilations[0];
  int dila_w = dilations[1];
  int pad_top = paddings[0];
  int pad_bottom = paddings[1];
  int pad_left = paddings[2];
  int pad_right = paddings[3];
87 88 89
  int stride_h = param.strides[0];
  int stride_w = param.strides[1];
  auto kernel_exten = dila_h * (kernel_h - 1) + 1;
H
HappyAngel 已提交
90
  auto hout = (h + pad_top + pad_bottom - kernel_exten) / stride_h + 1;
91
  kernel_exten = dila_w * (kernel_w - 1) + 1;
H
HappyAngel 已提交
92
  auto wout = (w + pad_left + pad_right - kernel_exten) / stride_w + 1;
93 94 95 96 97 98 99 100 101 102 103 104 105
  dim_out[2] = hout;
  dim_out[3] = wout;
  return dim_out;
}

#ifdef LITE_WITH_ARM
void test_conv_fp32(const std::vector<DDim>& input_dims,
                    const DDim& weight_dim,
                    int group,
                    const std::vector<int>& strides,
                    const std::vector<int>& pads,
                    const std::vector<int>& dilas,
                    bool flag_bias,
106
                    int flag_act,
107
                    const std::vector<int>& thread_num,
108 109
                    const std::vector<int>& power_mode,
                    const float leakey_relu_scale) {
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#ifdef LITE_WITH_ARM
  paddle::lite::DeviceInfo::Init();
#endif
  ConvParam param;
  param.x = new Tensor;
  param.x->set_precision(PRECISION(kFloat));
  param.filter = new Tensor;
  param.filter->Resize(weight_dim);
  param.filter->set_precision(PRECISION(kFloat));
  if (flag_bias) {
    param.bias = new Tensor;
    param.bias->Resize({weight_dim[0]});
    param.bias->set_precision(PRECISION(kFloat));
  }
  param.strides = strides;
H
HappyAngel 已提交
125 126
  param.paddings = std::make_shared<std::vector<int>>(pads);
  param.dilations = std::make_shared<std::vector<int>>(dilas);
127
  param.groups = group;
128 129
  const float six = 6.f;
  if (flag_act > 0) {
130 131
    ActivationParam act_param;
    act_param.has_active = true;
132 133 134 135 136 137 138 139 140
    act_param.active_type = (paddle::lite_api::ActivationType)
        flag_act;  // 1-relu, 2-relu6, 4-leakyrelu
    if (flag_act == 1) {
      param.fuse_relu = true;
    } else if (flag_act == 2) {
      act_param.Relu_clipped_coef = six;
    } else if (flag_act == 4) {
      act_param.Leaky_relu_alpha = leakey_relu_scale;
    }
141 142
    param.activation_param = act_param;
  }
143 144 145 146 147 148 149 150 151 152 153 154 155

  param.output = new Tensor;
  param.output->set_precision(PRECISION(kFloat));

  paddle::lite::fill_tensor_rand(*param.filter, -1.f, 1.f);
  //  paddle::lite::fill_tensor_const(*param.filter, 1.f);
  if (flag_bias) {
    paddle::lite::fill_tensor_rand(*param.bias, -1.f, 1.f);
    //    paddle::lite::fill_tensor_const(*param.bias, 1.f);
  }
  auto wptr = param.filter->data<float>();
  auto bias_ptr = flag_bias ? param.bias->data<float>() : nullptr;

156
  for (auto& cls : power_mode) {
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
    for (auto& th : thread_num) {
      paddle::lite::kernels::arm::ConvCompute<PRECISION(kFloat),
                                              PRECISION(kFloat)>
          conv;
      std::unique_ptr<paddle::lite::KernelContext> ctx1(
          new paddle::lite::KernelContext);
      auto& ctx = ctx1->As<paddle::lite::ARMContext>();
      ctx.SetRunMode(static_cast<paddle::lite_api::PowerMode>(cls), th);
      /// set param and context
      for (auto& dim_in : input_dims) {
        param.x->Resize(dim_in);
        DDim out_tmp_dims = compute_out_dim(dim_in, param);
        if (out_tmp_dims[2] < 1 || out_tmp_dims[3] < 1) {
          continue;
        }
        param.output->Resize(out_tmp_dims);
        break;
      }
      conv.SetParam(param);
      conv.SetContext(std::move(ctx1));
      /// prepare for run
      conv.PrepareForRun();

      for (auto& dim_in : input_dims) {
        CHECK_EQ(weight_dim[1] * group, dim_in[1])
            << "input channel must equal to weights channel";
        DDim dim_out = compute_out_dim(dim_in, param);
        if (dim_out[2] < 1 || dim_out[3] < 1) {
          continue;
        }
        param.x->Resize(dim_in);
        param.output->Resize(dim_out);

        paddle::lite::fill_tensor_rand(*param.x, -1.f, 1.f);
H
HappyAngel 已提交
191
        // paddle::lite::fill_tensor_const(*param.x, 1.f);
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
        auto din = param.x->data<float>();

        Tensor tout_basic;
        if (FLAGS_check_result) {
          tout_basic.set_precision(PRECISION(kFloat));
          tout_basic.Resize(dim_out);
          fill_tensor_const(tout_basic, 0.f);
          auto dout_basic = tout_basic.mutable_data<float>();
          conv_basic<float, float>(din,
                                   dout_basic,
                                   dim_in[0],
                                   dim_out[1],
                                   dim_out[2],
                                   dim_out[3],
                                   dim_in[1],
                                   dim_in[2],
                                   dim_in[3],
                                   wptr,
                                   bias_ptr,
                                   group,
                                   weight_dim[3],
                                   weight_dim[2],
                                   strides[1],
                                   strides[0],
                                   dilas[1],
                                   dilas[0],
H
HappyAngel 已提交
218
                                   pads[2],
219 220
                                   pads[0],
                                   flag_bias,
221 222 223
                                   flag_act,
                                   six,
                                   leakey_relu_scale);
C
chenjiaoAngel 已提交
224 225 226 227 228
        if (flag_act == 2) { // relu6
             for (int i = 0; i < dim_out.production(); i++) {
                 dout_basic_fp32[i] = dout_basic[i] > six ? six : dout_basic[i];
             }
        }
229 230 231 232 233 234
        }
        /// warm up
        for (int i = 0; i < FLAGS_warmup; ++i) {
          conv.Launch();
        }
        /// compute
235
        Timer t0;
236
        for (int i = 0; i < FLAGS_repeats; ++i) {
237
          t0.Start();
238
          conv.Launch();
239
          t0.Stop();
240 241 242 243 244
        }

        double gops = 2.0 * dim_out.production() * dim_in[1] * weight_dim[2] *
                      weight_dim[3] / param.groups;
        LOG(INFO) << "conv fp32: input shape: " << dim_in << ", output shape"
245 246
                  << dim_out << ",running time, avg: " << t0.LapTimes().Avg()
                  << ", min time: " << t0.LapTimes().Min()
247
                  << ", total GOPS: " << 1e-9 * gops
248 249
                  << " GOPS, avg GOPs: " << 1e-6 * gops / t0.LapTimes().Avg()
                  << " GOPs, max GOPs: " << 1e-6 * gops / t0.LapTimes().Min();
250 251 252 253 254 255 256 257 258 259 260

        if (FLAGS_check_result) {
          double max_ratio = 0;
          double max_diff = 0;
          tensor_cmp_host(tout_basic, *param.output, max_ratio, max_diff);
          LOG(INFO) << "compare result, max diff: " << max_diff
                    << ", max ratio: " << max_ratio;
          if (std::abs(max_ratio) > 1e-3f) {
            if (max_diff > 5e-4f) {
              LOG(WARNING) << "basic result";
              print_tensor(tout_basic);
X
Xiaoyang LI 已提交
261
              LOG(WARNING) << "lite result";
262 263 264 265 266 267 268 269 270
              print_tensor(*param.output);
              Tensor tdiff;
              tdiff.Resize(tout_basic.dims());
              tdiff.set_precision(PRECISION(kFloat));
              tensor_diff(tout_basic, *param.output, tdiff);
              print_tensor(tdiff);
              LOG(FATAL) << "test fp32 conv: input: " << dim_in
                         << ", output: " << dim_out
                         << ", weight dim: " << weight_dim
H
HappyAngel 已提交
271 272
                         << ", pad: " << pads[0] << ", " << pads[1] << ", "
                         << pads[2] << ", " << pads[3]
273 274
                         << ", stride: " << strides[0] << ", " << strides[1]
                         << ", dila_: " << dilas[0] << ", " << dilas[1]
275
                         << ", group: " << group
276
                         << ", bias: " << (flag_bias ? "true" : "false")
277 278
                         << ", act: " << flag_act << ", threads: " << th
                         << ", power_mode: " << cls << " failed!!\n";
279 280 281 282 283
            }
          }
        }
        LOG(INFO) << "test fp32 conv: input: " << dim_in
                  << ", output: " << dim_out << ", weight dim: " << weight_dim
284 285 286
                  << ", pad: " << pads[0] << ", " << pads[1] << ", " << pads[2]
                  << ", " << pads[3] << ", stride: " << strides[0] << ", "
                  << strides[1] << ", dila_: " << dilas[0] << ", " << dilas[1]
287
                  << ", group: " << group
288
                  << ", bias: " << (flag_bias ? "true" : "false")
289 290
                  << ", act: " << flag_act << ", threads: " << th
                  << ", power_mode: " << cls << " successed!!\n";
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
      }
    }
  }

  delete param.x;
  delete param.filter;
  delete param.output;
  delete param.bias;
}
#else
void test_conv_fp32(const std::vector<DDim>& input_dims,
                    const DDim& weight_dim,
                    int group,
                    const std::vector<int>& strides,
                    const std::vector<int>& pads,
                    const std::vector<int>& dilas,
                    bool flag_bias,
308
                    int flag_act,
309
                    const std::vector<int>& thread_num,
310 311
                    const std::vector<int>& power_mode,
                    const float leakey_relu_scale) {}
312 313
#endif  // LITE_WITH_ARM

314
// TODO(chenjiaoAngel): fix multi-threds, diff: 3x3 depthwise conv
H
HappyAngel 已提交
315
#if 0  // 3x3dw
316 317 318
TEST(TestConv3x3DW, test_conv3x3_depthwise) {
  if (FLAGS_basic_test) {
    for (auto& stride : {1, 2}) {
H
HappyAngel 已提交
319 320 321 322 323
      for (auto& pad_left : {0, 1, 2}) {
        for (auto& pad_right : {0, 1, 2}) {
          for (auto& pad_top : {0, 1, 2}) {
            for (auto& pad_bottom : {0, 1, 2}) {
              for (auto& flag_bias : {false, true}) {
324
                for (auto& flag_act : {0, 1, 2, 4}) {
H
HappyAngel 已提交
325 326 327 328 329 330 331 332
                  for (auto& c : {1, 3, 5, 8, 16, 32}) {
                    std::vector<DDim> dims;
                    DDim weights_dim({c, 1, 3, 3});
                    for (auto& batch : {1, 2}) {
                      for (auto& h : {1, 3, 15, 19, 28, 32, 75}) {
                        dims.push_back(DDim({batch, c, h, h}));
                      }
                    }
H
HappyAngel 已提交
333 334 335 336 337 338 339
#ifdef __aarch64__
#else
                    if (stride == 1 && (pad_bottom == 2 || pad_right == 2 ||
                                        pad_top == 2 || pad_left == 2)) {
                      continue;
                    }
#endif
340
                    const float leakey_relu_scale = 8.88;
H
HappyAngel 已提交
341 342 343 344 345 346 347
                    test_conv_fp32(dims,
                                   weights_dim,
                                   c,
                                   {stride, stride},
                                   {pad_top, pad_bottom, pad_left, pad_right},
                                   {1, 1},
                                   flag_bias,
348
                                   flag_act,
349
                                   {1},
350 351
                                   {FLAGS_power_mode},
                                   leakey_relu_scale);
H
HappyAngel 已提交
352
                  }
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
                }
              }
            }
          }
        }
      }
    }
  }
}
#endif  /// 3x3dw

#if 1  /// 5x5dw
TEST(TestConv5x5DW, test_conv5x5_depthwise) {
  if (FLAGS_basic_test) {
    for (auto& stride : {1, 2}) {
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
      for (auto& pad_left : {0, 1, 2}) {
        for (auto& pad_right : {0, 1, 2}) {
          for (auto& pad_top : {0, 1, 2}) {
            for (auto& pad_bottom : {0, 1, 2}) {
              for (auto& flag_bias : {false, true}) {
                for (auto& flag_act : {0, 1, 2, 4}) {
                  for (auto& c : {1, 15, 32}) {
                    std::vector<DDim> dims;
                    DDim weights_dim({c, 1, 5, 5});
                    for (auto& batch : {1, 2}) {
                      for (auto& h : {1, 3, 15, 56}) {
                        dims.push_back(DDim({batch, c, h, h}));
                      }
                    }
                    const float leakey_relu_scale = 8.88;
                    test_conv_fp32(dims,
                                   weights_dim,
                                   c,
                                   {stride, stride},
                                   {pad_left, pad_right, pad_top, pad_bottom},
                                   {1, 1},
                                   flag_bias,
                                   flag_act,
                                   {4},
                                   {FLAGS_power_mode},
                                   leakey_relu_scale);
                  }
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
                }
              }
            }
          }
        }
      }
    }
  }
}
#endif  /// 5x5dw

#if 1  /// conv1x1s1
TEST(TestConv1x1s1, test_conv1x1s1) {
  if (FLAGS_basic_test) {
    for (auto& cin : {1, 3, 8, 11, 32}) {
      for (auto& cout : {1, 5, 16, 37}) {
        for (auto& g : {1, 2}) {
          for (auto& flag_bias : {false, true}) {
413
            for (auto& flag_act : {0, 1, 2, 4}) {
414 415 416 417 418 419 420 421 422 423
              std::vector<DDim> dims;
              if (cin % g != 0 || cout % g != 0) {
                continue;
              }
              DDim weights_dim({cout, cin / g, 1, 1});
              for (auto& batch : {1, 2}) {
                for (auto& h : {1, 7, 19, 28, 32, 56, 1}) {
                  dims.push_back(DDim({batch, cin, h, h}));
                }
              }
424
              const float leakey_relu_scale = 8.88;
425 426 427 428
              test_conv_fp32(dims,
                             weights_dim,
                             g,
                             {1, 1},
H
HappyAngel 已提交
429
                             {0, 0, 0, 0},
430 431
                             {1, 1},
                             flag_bias,
432
                             flag_act,
433
                             {1, 2, 4},
434 435
                             {FLAGS_power_mode},
                             leakey_relu_scale);
436 437 438 439 440 441 442 443 444
            }
          }
        }
      }
    }
  }
}
#endif  /// conv1x1s1

445 446
// TODO(MyPandaShaoxiang): fix me, diff: 3x3s1 winograd
#if 0   /// conv3x3s1
447 448
TEST(TestConv3x3s1, test_conv_3x3s1) {
  if (FLAGS_basic_test) {
449 450 451 452 453 454
    for (auto& cin : {1, 3, 8, 8}) {
      for (auto& cout : {1, 5, 32, 48}) {
        for (auto& pad_left : {0, 1, 2}) {
          for (auto& pad_right : {0, 1, 2}) {
            for (auto& pad_top : {0, 1, 2}) {
              for (auto& pad_bottom : {0, 1, 2}) {
H
HappyAngel 已提交
455
                for (auto& flag_bias : {false, true}) {
456
                  for (auto& flag_act : {0, 1, 2, 4}) {
H
HappyAngel 已提交
457 458 459
                    std::vector<DDim> dims;
                    DDim weights_dim({cout, cin, 3, 3});
                    for (auto& batch : {1, 2}) {
460
                      for (auto& h : {1, 3, 17, 33}) {
H
HappyAngel 已提交
461 462 463
                        dims.push_back(DDim({batch, cin, h, h}));
                      }
                    }
464
                    if (cin == 1 && cout == 1) {
465 466 467
                      continue;
                    }
                    const float leakey_relu_scale = 8.88;
H
HappyAngel 已提交
468 469 470 471 472 473 474
                    test_conv_fp32(dims,
                                   weights_dim,
                                   1,
                                   {1, 1},
                                   {pad_top, pad_bottom, pad_left, pad_right},
                                   {1, 1},
                                   flag_bias,
475 476 477 478
                                   flag_act,
                                   {4},
                                   {FLAGS_power_mode},
                                   leakey_relu_scale);
H
HappyAngel 已提交
479
                  }
480 481 482 483 484 485 486 487 488 489 490 491 492 493
                }
              }
            }
          }
        }
      }
    }
  }
}
#endif  /// conv3x3s1

#if 1  /// conv3x3s2
TEST(TestConv3x3s2, test_conv_3x3s2) {
  if (FLAGS_basic_test) {
494 495 496 497 498 499
    for (auto& cin : {1, 3, 8}) {
      for (auto& cout : {1, 3, 9, 32}) {
        for (auto& pad_left : {0, 1, 2}) {
          for (auto& pad_right : {0, 1, 2}) {
            for (auto& pad_top : {0, 1, 2}) {
              for (auto& pad_bottom : {0, 1, 2}) {
H
HappyAngel 已提交
500
                for (auto& flag_bias : {false, true}) {
501
                  for (auto& flag_act : {0, 1, 2, 4}) {
H
HappyAngel 已提交
502 503 504
                    std::vector<DDim> dims;
                    DDim weights_dim({cout, cin, 3, 3});
                    for (auto& batch : {1, 2}) {
505
                      for (auto& h : {3, 7, 15, 56, 32}) {
H
HappyAngel 已提交
506 507 508
                        dims.push_back(DDim({batch, cin, h, h}));
                      }
                    }
509 510 511 512
                    if (cin == 1 && cout == 1) {
                      continue;
                    }
                    const float leakey_relu_scale = 8.88;
H
HappyAngel 已提交
513 514 515 516 517 518 519
                    test_conv_fp32(dims,
                                   weights_dim,
                                   1,
                                   {2, 2},
                                   {pad_top, pad_bottom, pad_left, pad_right},
                                   {1, 1},
                                   flag_bias,
520
                                   flag_act,
H
HappyAngel 已提交
521
                                   {1, 2, 4},
522 523
                                   {FLAGS_power_mode},
                                   leakey_relu_scale);
H
HappyAngel 已提交
524
                  }
525 526 527 528 529 530 531 532 533 534 535 536 537 538
                }
              }
            }
          }
        }
      }
    }
  }
}
#endif  /// conv3x3s2

#if 1  /// random param conv
TEST(TestConvRand, test_conv_rand) {
  if (FLAGS_basic_test) {
539 540
    for (auto& cin : {1, 3, 8}) {
      for (auto& cout : {1, 5, 16}) {
541 542 543 544
        for (auto& g : {1, 2}) {
          for (auto& kw : {1, 2, 3}) {
            for (auto& kh : {1, 2, 3}) {
              for (auto& stride : {1, 2}) {
545 546 547 548
                for (auto& pad_left : {0, 2}) {
                  for (auto& pad_right : {0, 2}) {
                    for (auto& pad_top : {0, 2}) {
                      for (auto& pad_bottom : {0, 2}) {
H
HappyAngel 已提交
549 550
                        for (auto& dila : {1, 2}) {
                          for (auto& flag_bias : {false, true}) {
551
                            for (auto& flag_act : {0, 1, 2, 4}) {
H
HappyAngel 已提交
552 553 554 555 556 557
                              if (cin % g != 0 || cout % g != 0) {
                                continue;
                              }
                              std::vector<DDim> dims;
                              DDim weights_dim({cout, cin / g, kh, kw});
                              for (auto& batch : {1, 2}) {
558
                                for (auto& h : {1, 3, 19, 32}) {
H
HappyAngel 已提交
559 560 561
                                  dims.push_back(DDim({batch, cin, h, h}));
                                }
                              }
562 563 564 565 566 567 568 569 570 571 572
                              // skip 3x3 depthwise conv
                              if (g == cin && cin == cout && kw == 3 &&
                                  kh == 3) {
                                break;
                              }
                              // skip 3x3s1 direct conv
                              if (g == 1 && (cin != 1 || cout != 1) &&
                                  kw == 3 && kh == 3 && stride == 1) {
                                break;
                              }
                              const float leakey_relu_scale = 8.88;
H
HappyAngel 已提交
573 574 575 576 577 578 579 580
                              test_conv_fp32(
                                  dims,
                                  weights_dim,
                                  g,
                                  {stride, stride},
                                  {pad_top, pad_bottom, pad_left, pad_right},
                                  {dila, dila},
                                  flag_bias,
581 582 583 584
                                  flag_act,
                                  {4},
                                  {FLAGS_power_mode},
                                  leakey_relu_scale);
H
HappyAngel 已提交
585
                            }
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
#endif  /// random param conv

#if 1  /// custom
TEST(TestConvCustom, test_conv_fp32_custom_size) {
  CHECK_EQ(FLAGS_in_channel % FLAGS_group, 0)
      << "input channel must be divided by group";
  CHECK_EQ(FLAGS_out_channel % FLAGS_group, 0)
      << "num_output must be divided by group";
  test_conv_fp32(
      {DDim({FLAGS_batch, FLAGS_in_channel, FLAGS_in_height, FLAGS_in_width})},
      DDim({FLAGS_out_channel,
            FLAGS_in_channel / FLAGS_group,
            FLAGS_kernel_h,
            FLAGS_kernel_w}),
      FLAGS_group,
      {FLAGS_stride_h, FLAGS_stride_w},
616
      {FLAGS_pad_h0, FLAGS_pad_h1, FLAGS_pad_w0, FLAGS_pad_w1},
617 618
      {FLAGS_dila_h, FLAGS_dila_w},
      FLAGS_flag_bias,
619
      FLAGS_flag_act,
620
      {FLAGS_threads},
621 622
      {FLAGS_power_mode},
      FLAGS_leakey_relu_alpha);
623 624
}
#endif  // custom