未验证 提交 4d72fe6e 编写于 作者: D dolphin8 提交者: GitHub

Merge pull request #370 from dolphin8/develop

fix #371 add openmp support (disabled by default)
......@@ -29,6 +29,12 @@ file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h)
include_directories(src/)
option(USE_OPENMP "openmp support" OFF)
if(USE_OPENMP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
add_definitions(-DPADDLE_MOBILE_USE_OPENMP)
endif()
if (googlenet)
add_definitions(-DCONCAT_OP)
add_definitions(-DCONV_OP)
......
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#ifdef PADDLE_MOBILE_USE_OPENMP
/**
* android-ndk-r17 has a problem when linking with openmp.
* if paddle-mobile enables -fopenmp, but didn't use those omp_* functions,
* after linking another binary with libpaddle-mobile.so, the omp_get_thread_num
* will not work. see test/common/test_openmp.cc the detailed reason is still
* unclear, but this trick will work. a better solution is hacking the linker,
* try some flags to make it link omp_* functions, but I didn't find out how to
* make it work.
*/
#include <omp.h>
static int _ = omp_get_num_procs();
#endif
......@@ -41,7 +41,9 @@ void sigmoid(const Tensor *X, Tensor *Y) {
int out_size = paddle_mobile::framework::product(outer_ddim);
int inner_size = paddle_mobile::framework::product(inner_ddim);
#pragma omp parallel for
DLOG << "outsize=" << out_size;
DLOG << "innersize=" << inner_size;
#pragma omp parallel for
for (int i = 0; i < out_size; ++i) {
const float *input_outer_ptr = input + i * inner_size;
float *output_outer_ptr = output + i * inner_size;
......
......@@ -59,7 +59,7 @@ class PoolFunctor<CPU, PoolProcess, T> {
T *output_data = output->mutable_data<T>();
for (int i = 0; i < batch_size; i++) {
#pragma omp parallel for
#pragma omp parallel for
for (int c = 0; c < output_channels; ++c) {
for (int ph = 0; ph < output_height; ++ph) {
int hstart = ph * stride_height - padding_height;
......
......@@ -121,6 +121,14 @@ else ()
ADD_EXECUTABLE(test-enforce common/test_enforce.cpp)
target_link_libraries(test-enforce paddle-mobile)
# gen test - test if openmp works
ADD_EXECUTABLE(test-openmp common/test_openmp.cc test_helper.h test_include.h executor_for_test.h)
target_link_libraries(test-openmp paddle-mobile)
# gen test
ADD_EXECUTABLE(test-yolo net/test_yolo.cpp test_helper.h test_include.h executor_for_test.h)
target_link_libraries(test-yolo paddle-mobile)
# gen test
ADD_EXECUTABLE(test-mobilenetssd net/test_mobilenet+ssd.cpp test_helper.h test_include.h executor_for_test.h)
target_link_libraries(test-mobilenetssd paddle-mobile)
......
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <omp.h>
#include <iostream>
int main(void) {
#pragma omp parallel num_threads(2)
{
int thread_id = omp_get_thread_num();
int nthreads = omp_get_num_threads();
std::cout << "Hello, OMP " << thread_id << "/" << nthreads << "\n";
}
return 0;
}
......@@ -12,4 +12,8 @@ if ! [[ $version == *"$VERSION"* ]]; then
exit -1
fi
clang-format $@
# https://medicineyeh.wordpress.com/2017/07/13/clang-format-with-pragma/
shift
perl -i -pe 's|#pragma\s+omp|// <TRICKY-CLANG-FORMAT-PRAGMA-FIX> #pragma omp|' "$@"
clang-format -i $@
perl -i -pe 's|// <TRICKY-CLANG-FORMAT-PRAGMA-FIX> ||' "$@"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册