Tencent / Tencent/ncnn

low performance of ConvolutionDepthWise operation

Open
#2,437 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
23.8k
Forks
4.5k
Avg merge
2d 20h
Merged PRs (30d)
37

Description

i am working on using NCNN to do a simple depthwise convolution operation. To be specific, is a depthwise convolution between a 256x26x26 tensor and a 256x4x4 tensor. Here is my naive test code.

ncnn::Option opt;
opt.num_threads = 1;

ncnn::Layer* op = ncnn::create_layer("ConvolutionDepthWise");

// set param
ncnn::ParamDict pd;
pd.set(0, 256);// num_output
pd.set(1, 4);// kernel_w
pd.set(5, 0);// bias_term
pd.set(6, 256*4*4);// weight_data_size
pd.set(7, 256);// group

op->load_param(pd);

// random input
ncnn::Mat in = RandomMat(26, 26, 256);

// random weights
ncnn::Mat weights[1];
weights[0] = RandomMat(256*4*4);// weight_data

op->load_model(ncnn::ModelBinFromMatArray(weights));

op->create_pipeline(opt);

// forward
op->forward(in, out, opt);

op->destroy_pipeline(opt);

delete op;

I got two problems.

  1. The code above can not be excuted unless opt.use_packing_layout is set to be false.
  2. The computation speed is very slow on a hisilocon 3559av100 test board (~35 ms), while the speed is greatly accelerated when the kernel size is set to be 3x3 or 5x5 (~1-2 ms).

any sugestions for me to do such a 4x4 depthwise convolution with a high efficiency.
thank you very much.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the inline C++ test for a 256-channel 4x4 ConvolutionDepthWise operation on the Hisilicon 3559av100 setup, checking the use_packing_layout behavior. Compare the 4x4 timing with the reported 3x3 and 5x5 cases; done means explaining the failure and identifying an efficient supported path for the 4x4 operation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
machine-learning, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.