-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
@@ -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) |
There was a problem hiding this comment.
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
。
There was a problem hiding this comment.
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只是编译,修改过来实际也跑不了单侧。
There was a problem hiding this comment.
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
这一个模型,不确定测试的是否全面。
paddle/function/CMakeLists.txt
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USE_EIGEN_FOR_BLAS
为OFF
时也要编译EigenGemm.cpp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯,这个可以去掉。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
paddle/function/EigenGemm.cpp
Outdated
c.device(device) += a.contract(b, dims); | ||
} else { | ||
c.device(device) = | ||
c.constant(alpha) * a.contract(b, dims) + c.constant(beta) * c; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
设置了transpose
的size
,在执行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;
?
There was a problem hiding this comment.
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;
也是可以的。
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要换成这种static
函数的定义方式呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
调用的时候省去一次构造,直接BlasGemm<Device, real>::compute
。
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
这一个模型,不确定测试的是否全面。
In some environment, the performance of Eigen's matrix multiplication is higher than OpenBlas (like ARMv7). So add an EigenBlasGemm.