-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix some link errors about NNPACK. #2824
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,24 @@ set(NNPACK_ROOT $ENV{NNPACK_ROOT} CACHE PATH "Folder contains NNPACK") | |
| find_path(NNPACK_INC_DIR nnpack.h PATHS ${NNPACK_ROOT}/include) | ||
| find_library(NNPACK_LIB NAMES nnpack PATHS ${NNPACK_ROOT}/lib) | ||
| find_library(PTHREADPOOL_LIB NAMES pthreadpool PATHS ${NNPACK_ROOT}/lib) | ||
| find_library(NNPACK_UKERNELS_LIB NAMES nnpack_ukernels PATHS ${NNPACK_ROOT}/lib) | ||
| find_library(NNPACK_CPUFEATURES_LIB NAMES cpufeatures PATHS ${NNPACK_ROOT}/lib) | ||
|
|
||
| if(NNPACK_INC_DIR AND NNPACK_LIB AND PTHREADPOOL_LIB) | ||
| set(NNPACK_FOUND ON) | ||
| INCLUDE_DIRECTORIES(${NNPACK_INC_DIR}) | ||
|
|
||
| set(NNPACK_LIBS) | ||
| list(APPEND NNPACK_LIBS ${NNPACK_LIB} ${PTHREADPOOL_LIB}) | ||
| if (NNPACK_UKERNELS_LIB) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In what case there is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Android, the nnpack compilation generates the libnnpack_ukernels.a file. If not, there is no such file, all *.o files have been packaged into the libnnpack.a file. |
||
| list(APPEND NNPACK_LIBS ${NNPACK_UKERNELS_LIB}) | ||
| endif() | ||
| if (NNPACK_CPUFEATURES_LIB) | ||
| list(APPEND NNPACK_LIBS ${NNPACK_CPUFEATURES_LIB}) | ||
| endif() | ||
| if(NOT ANDROID) | ||
| list(APPEND NNPACK_LIBS "rt") | ||
| endif() | ||
| else() | ||
| message(FATAL_ERROR "Cannot find NNPACK in (${NNPACK_ROOT})") | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ limitations under the License. */ | |
| #include "paddle/function/ConvOp.h" | ||
|
|
||
| DEFINE_bool(nnpack_allocate_outside, | ||
| false, | ||
| true, | ||
| "Allocate and free workspace memory outside the NNPACK interface."); | ||
| DEFINE_int32(nnpack_num_threads, | ||
| 0, | ||
|
|
@@ -58,18 +58,10 @@ class NNPACKConvFunction : public ConvFunctionBase { | |
| workspaceBuffer_ = nullptr; | ||
| workspaceSize_ = 0; | ||
|
|
||
| threadpool_ = nullptr; | ||
| if (FLAGS_nnpack_num_threads) { | ||
| threadpool_ = pthreadpool_create(FLAGS_nnpack_num_threads); | ||
| VLOG(3) << "Number of threads " | ||
| << pthreadpool_get_threads_count(threadpool_); | ||
| } | ||
| create_nnpack_threadpool(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this way, we cannot destroy the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this may not very good. However, the previous version, each NNPACKConvFunction object has a threadpool_ is a bug. When the program running, it will lead to creating many of threads. So, I changed threadpool_ to a static variable.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can define threadpool like this:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is better, can you fix it?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. |
||
| } | ||
|
|
||
| ~NNPACKConvFunction() { | ||
| if (threadpool_) { | ||
| pthreadpool_destroy(threadpool_); | ||
| } | ||
| if (workspaceBuffer_) { | ||
| free(workspaceBuffer_); | ||
| } | ||
|
|
@@ -225,14 +217,25 @@ class NNPACKConvFunction : public ConvFunctionBase { | |
| } | ||
| } | ||
|
|
||
| static void create_nnpack_threadpool() { | ||
| if (FLAGS_nnpack_num_threads && threadpool_ == nullptr) { | ||
| threadpool_ = pthreadpool_create(FLAGS_nnpack_num_threads); | ||
| VLOG(3) << "Number of threads " | ||
| << pthreadpool_get_threads_count(threadpool_); | ||
| } | ||
| } | ||
|
|
||
| private: | ||
| nnp_convolution_algorithm algorithm_; | ||
| nnp_convolution_transform_strategy transform_strategy_; | ||
| void* workspaceBuffer_; | ||
| size_t workspaceSize_; | ||
| pthreadpool_t threadpool_; | ||
| static pthreadpool_t threadpool_; | ||
| }; | ||
|
|
||
| template <DeviceType Device> | ||
| pthreadpool_t NNPACKConvFunction<Device>::threadpool_ = nullptr; | ||
|
|
||
| REGISTER_TYPED_FUNC(NNPACKConv, CPU, NNPACKConvFunction); | ||
|
|
||
| } // namespace paddle | ||
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.
cpufeaturesis a library from ndk, and is special for Android. Just reminding here that we may have a better way to locate it in future.