Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use EigenBlasGemm improve convolution computing performance in ARMv7 environment. #3549

Merged
merged 5 commits into from
Aug 21, 2017

Conversation

hedaoyuan
Copy link
Contributor

@hedaoyuan hedaoyuan commented Aug 17, 2017

In some environment, the performance of Eigen's matrix multiplication is higher than OpenBlas (like ARMv7). So add an EigenBlasGemm.

@hedaoyuan hedaoyuan changed the title Add EigenBlasGemm Use EigenBlasGemm improve convolution computing performance in ARMv7 environment. Aug 17, 2017
@hedaoyuan hedaoyuan requested a review from Xreki August 17, 2017 08:38
@@ -55,6 +55,7 @@ option(WITH_C_API "Compile PaddlePaddle with C-API(Prediction)" OFF)
option(WITH_GOLANG "Compile PaddlePaddle with GOLANG" OFF)
option(GLIDE_INSTALL "Download and install go dependencies " ON)
option(USE_NNPACK "Compile PaddlePaddle with NNPACK library" OFF)
option(USE_EIGEN_FOR_BLAS "Use matrix multiplication in Eigen" OFF)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议将USE_EIGEN_FOR_BLAS的默认值改成ON,跑一遍单测看看有没有问题。确认没有问题之后,再将默认值改回OFF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在本地ON和OFF都是测试过(x86, armv7, armv8),CI只是编译,修改过来实际也跑不了单侧。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

若设置了USE_EIGEN_FOR_BLAS,teamcity上也会编译使用Eigen计算gemm的版本,是可以跑单测的。线下我只跑了mobilenet这一个模型,不确定测试的是否全面。

@@ -4,6 +4,8 @@ file(GLOB cpp_files . *Op.cpp)
list(APPEND h_files Function.h)
list(APPEND cpp_files Function.cpp)
list(APPEND cpp_files BufferArg.cpp)
list(APPEND cpp_files GemmFunctor.cpp)
list(APPEND cpp_files EigenGemm.cpp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USE_EIGEN_FOR_BLASOFF时也要编译EigenGemm.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,这个可以去掉。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

c.device(device) += a.contract(b, dims);
} else {
c.device(device) =
c.constant(alpha) * a.contract(b, dims) + c.constant(beta) * c;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

设置了transposesize,在执行contract()时,内部就会自动transpose

c.device(device) = c.constant(alpha) * a.contract(b, dims) + c.constant(beta) * c;

不能直接用c.device(device) = alpha * a.contract(b, dims) + beta * c;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

内部就会自动transpose?

是的。

c.device(device) = alpha * a.contract(b, dims) + beta * c;

也是可以的。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

T* C,
const int ldc);
struct BlasGemm {
static void compute(const bool transA,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要换成这种static函数的定义方式呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调用的时候省去一次构造,直接BlasGemm<Device, real>::compute

Copy link
Contributor

@Xreki Xreki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

总体来说LGTM,并且我们需要这个PR来加速armv7a架构上的预测速度。

@@ -55,6 +55,7 @@ option(WITH_C_API "Compile PaddlePaddle with C-API(Prediction)" OFF)
option(WITH_GOLANG "Compile PaddlePaddle with GOLANG" OFF)
option(GLIDE_INSTALL "Download and install go dependencies " ON)
option(USE_NNPACK "Compile PaddlePaddle with NNPACK library" OFF)
option(USE_EIGEN_FOR_BLAS "Use matrix multiplication in Eigen" OFF)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

若设置了USE_EIGEN_FOR_BLAS,teamcity上也会编译使用Eigen计算gemm的版本,是可以跑单测的。线下我只跑了mobilenet这一个模型,不确定测试的是否全面。

@hedaoyuan hedaoyuan merged commit a683a56 into PaddlePaddle:develop Aug 21, 2017
@Xreki Xreki added this to Convolution Optimization in Embedded and Mobile Deployment Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Embedded and Mobile Deployment
Convolution Optimization
Development

Successfully merging this pull request may close these issues.

None yet

2 participants