From 179dda3ea41f0f603cdfd092babb3c82c6c3564e Mon Sep 17 00:00:00 2001 From: zhaojiaying01 Date: Fri, 13 Jul 2018 13:38:05 +0800 Subject: [PATCH] add openmp in gemm and test_mobilenet --- src/operators/math/gemm.cpp | 5 +++++ test/net/test_mobilenet.cpp | 1 + 2 files changed, 6 insertions(+) diff --git a/src/operators/math/gemm.cpp b/src/operators/math/gemm.cpp index d7bc60e3c8..bb91adcc4d 100644 --- a/src/operators/math/gemm.cpp +++ b/src/operators/math/gemm.cpp @@ -18,6 +18,9 @@ limitations under the License. */ #ifndef X86 #include #endif +#ifdef _OPENMP +#include +#endif namespace paddle_mobile { namespace operators { @@ -158,6 +161,7 @@ void PackMatrixB_(int k, int n, int n_tail, const float *B, int ldb, // 分块矩阵乘法 void InnerKernel(int mc, int nc, float alpha, const float *a, const float *b, float beta, float *c, float *C, int ldc, bool relu) { +#pragma omp parallel for for (int j = 0; j < nc; j += NR) { for (int i = 0; i < mc; i += MR) { // AddDot4x4(KC, a + i * KC, b + j * KC, c + i * NC + j, NC); @@ -187,6 +191,7 @@ void InnerKernel(int mc, int nc, float alpha, const float *a, const float *b, void InnerKernelWithBn(int mc, int nc, float alpha, const float *a, const float *b, float beta, float *c, float *C, int ldc, bool relu, float *new_scale, float *new_bias) { +#pragma omp parallel for for (int j = 0; j < nc; j += NR) { for (int i = 0; i < mc; i += MR) { // AddDot4x4(KC, a + i * KC, b + j * KC, c + i * NC + j, NC); diff --git a/test/net/test_mobilenet.cpp b/test/net/test_mobilenet.cpp index 1f38dc5d19..2e285695fb 100644 --- a/test/net/test_mobilenet.cpp +++ b/test/net/test_mobilenet.cpp @@ -18,6 +18,7 @@ limitations under the License. */ int main() { paddle_mobile::PaddleMobile paddle_mobile; + paddle_mobile.SetThreadNum(4); auto time1 = time(); if (paddle_mobile.Load(g_mobilenet, true)) { auto time2 = time(); -- GitLab