Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

Add mkldnn related unit-tests

Open luotao1 opened this issue 7 years ago • 28 comments

To improve the code (line+function) coverage, please add mkldnn related unit-tests: http://ce.paddlepaddle.org:8080/viewLog.html?buildId=21110&buildTypeId=PaddlePaddleFramework_TestCoverage_TestCoverage&tab=report_project15_C___Coverage

  • framework/ir/mkldnn image
  • operators/elementwise/mkldnn image image image image image image

luotao1 avatar Jan 31 '19 04:01 luotao1

We reproduced your results with coverage testing tool.

  • cmake .. -DWITH_GPU=OFF -DWITH_PROFILER=ON -DWITH_STYLE_CHECK=OFF -DWITH_MKLDNN=ON -DWITH_TESTING=ON -DWITH_COVERAGE=ON
  • lcov --capture --directory . --output-file coverage.info
  • genhtml coverage.info --output-directory out

We will add missing tests.

image image image

kbinias avatar Feb 07 '19 10:02 kbinias

@luotao1 Whether it is possible to run more than 1 iteration in a single unit test for forward and backward phases ? We need to cover the part of the code responsible for reuse MKL-DNN primitives in backward (e.g. activation_mkldnn_op.cc::eltwise_grad function line 276-287). We have to run more than one iteration to enter this section of code.

kbinias avatar Feb 15 '19 06:02 kbinias

Whether it is possible to run more than 1 iteration in a single unit test for forward and backward phases?

I think it's OK to run more than 1 iterations in elementwise_xxx_mkldnn unit-tests. However, if you add many more iterations, does the elasped time of unit-tests become larger?

luotao1 avatar Feb 15 '19 07:02 luotao1

Not many, 2 iterations will be enough. Is there any unit test in PaddlePaddle which more than 1 iteration is started ?

kbinias avatar Feb 15 '19 07:02 kbinias

@kbinias There is no 2 iterations unitest using OpTest. Maybe you should implement yourselves, and refer to test_batch_norm_op.py.

luotao1 avatar Feb 18 '19 03:02 luotao1

@luotao1 Thanks for you answer. What do you think about creating new test based on test_imperative_resnet.py with use_mkldnn equals to True ? It will cover batch_norm, conv, pool and activations.

kbinias avatar Feb 18 '19 16:02 kbinias

What do you think about creating a new test based on test_imperative_resnet.py with use_mkldnn equals to True?

@kbinias I think it's OK.

luotao1 avatar Feb 19 '19 03:02 luotao1

@luotao1 What do you think about closing this PR ? The problem with function coverage is IMO related to lcov tool.

image image

kbinias avatar Mar 07 '19 10:03 kbinias

The Functions coverage is less than 80% in operators/mkldnn. You can add the unit-tests for activation_mkldnn_op.cc, conv_mkldnn_op.cc and transpose_mkldnn_op.cc when you are convenient. @kbinias

luotao1 avatar Mar 07 '19 11:03 luotao1

@luotao1 Coverage feature in GCC doesn't support virtual destructors correctly. There is no way to cover tests in 100% if test uses Inheritance. You can find out more details below with good explanation: https://stackoverflow.com/questions/25662174/is-there-a-way-to-call-the-deleting-destructor-of-a-pure-virtual-class.

One of potential workaround might be post-processing and remove all destructors from tests, we could consider that it’s a noise. The destructors should not be a part of final calculation.

kbinias avatar Mar 13 '19 12:03 kbinias

Got it. Both @tensor-tang and I think destructors are normal. However, the current coverage by May 12th is http://ce.paddlepaddle.org:8080/viewLog.html?buildId=31464&buildTypeId=PaddlePaddleFramework_TestCoverage_TestCoverage&tab=report_project15_C___Coverage image Why the coverage of batch_norm_mkldnn_op and lrn_mkldnn_op cut down that before?

luotao1 avatar Mar 13 '19 13:03 luotao1

我们的结果完全不一样,lrn应该是100%的,您可以用下面的编译指令重新生成一下吗 @luotao1 谢谢 ⦁        cmake .. -DWITH_GPU=OFF -DWITH_PROFILER=ON -DWITH_STYLE_CHECK=OFF -DWITH_MKLDNN=ON -DWITH_TESTING=ON -DWITH_COVERAGE=ON  ⦁        make -j 12 ⦁        ctest -R mkldnn ⦁        lcov --capture --directory . --output-file coverage.info  ⦁        genhtml --demangle-cpp coverage.info --output-directory out

lidanqing-vv avatar Mar 14 '19 11:03 lidanqing-vv

我是CI上的结果。

luotao1 avatar Mar 14 '19 11:03 luotao1

Could you please tell how to reproduce it with commands ? It seems we have different procedure... 请问怎么reproduce呢,可以有什么指令吗? 非常感谢!

lidanqing-vv avatar Mar 14 '19 11:03 lidanqing-vv

We are checking build log, hope we could find something. Thanks. If you have any further information, please inform us. Thanks

lidanqing-vv avatar Mar 14 '19 11:03 lidanqing-vv

Macro REGISTER_OP_KERNEL is not able to set correct handle for all grad functions such TouchOpKernelRegistrar_transpose_grad_MKLDNN_DEFAULT_TYPE(). Due to missed registration, we can’t cover all functions in tests. The issue is globally, moreover practical working example how to register kernel and enforce touchopkernelregistrar_grad correctly doesn’t exist. The open question is - do we really should care about it?

pawelpiotrowicz avatar Mar 19 '19 10:03 pawelpiotrowicz

@luotao1 What do you think about above problem ?

kbinias avatar Mar 19 '19 21:03 kbinias

do you mean paddle can't register some kernel or paddle can't select some registered kernels?

can you search REGISTER_OP_KERNEL_WITH_CUSTOM_TYPE and see if it works for you?

panyx0718 avatar Mar 20 '19 03:03 panyx0718

@shanyi15 Could you help to update How to add new op to introduce so many different REGISTER MACRO?

luotao1 avatar Mar 20 '19 03:03 luotao1

@luotao1 About batch_norm_mkldnn and lrn_mkldnn line coverages, I have some idea and made some fix locally. I could build and make with docker[latest-dev], but I don't know what is the building and testing script. Something like ./paddle_build_cov.sh. I also don't know what main cov means in the build log on TeamCity. Could you share build script with me? This will speed up the work. Thank you!

danqing-li avatar Mar 20 '19 09:03 danqing-li