forked from BVLC/caffe
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The approach is pretty straightforward and very similar to the CuDNN integration: - Add some CMake magic to detect NNPACK if it's installed on the user's system. - Add some Makefile.config options - Add some thread-local state (a threadpool for NNPACK to caffe::Caffe). - Add an NNPACK `Engine` parameter to Convolution/Pooling/InnerProduct layers. - In LayerFactory, ifdef around whether NNPACK is enabled and dispatch to NNPACK*Layer or *Layer depending on the Engine parameter. - In NNPACK*Layer, ensure the NNPACK preconditions hold and call the appropriate nnpack_* function, otherwise fall back to *Layer. I'm not sure how common it is to be running CNN inference on Haswell and beyond CPUs for Caffe users, but if it is it might be a nice boost for them.
- Loading branch information
Showing
21 changed files
with
892 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
SET(NNPACK_INCLUDE_SEARCH_PATHS | ||
/usr/include | ||
/usr/local/include | ||
/opt/NNPACK/include | ||
$ENV{NNPACK_ROOT} | ||
$ENV{NNPACK_ROOT}/include | ||
) | ||
|
||
SET(NNPACK_LIB_SEARCH_PATHS | ||
/lib/ | ||
/lib64/ | ||
/usr/lib | ||
/usr/lib64 | ||
/usr/local/lib | ||
/usr/local/lib64 | ||
/opt/NNPACK/lib | ||
$ENV{NNPACK_ROOT} | ||
$ENV{NNPACK_ROOT}/lib | ||
) | ||
|
||
FIND_PATH(NNPACK_INCLUDE_DIR NAMES nnpack.h PATHS ${NNPACK_INCLUDE_SEARCH_PATHS}) | ||
FIND_LIBRARY(NNPACK_LIB NAMES nnpack PATHS ${NNPACK_LIB_SEARCH_PATHS}) | ||
|
||
SET(NNPACK_FOUND ON) | ||
|
||
# Check include files | ||
IF(NOT NNPACK_INCLUDE_DIR) | ||
SET(NNPACK_FOUND OFF) | ||
MESSAGE(STATUS "Could not find NNPACK include. Turning NNPACK_FOUND off") | ||
ENDIF() | ||
|
||
# Check libraries | ||
IF(NOT NNPACK_LIB) | ||
SET(NNPACK_FOUND OFF) | ||
MESSAGE(STATUS "Could not find NNPACK lib. Turning NNPACK_FOUND off") | ||
ENDIF() | ||
|
||
IF (NNPACK_FOUND) | ||
add_definitions(-DUSE_NNPACK) | ||
IF (NOT NNPACK_FIND_QUIETLY) | ||
MESSAGE(STATUS "Found NNPACK libraries: ${NNPACK_LIB}") | ||
MESSAGE(STATUS "Found NNPACK include: ${NNPACK_INCLUDE_DIR}") | ||
ENDIF (NOT NNPACK_FIND_QUIETLY) | ||
ELSE (NNPACK_FOUND) | ||
IF (NNPACK_FIND_REQUIRED) | ||
MESSAGE(FATAL_ERROR "Could not find NNPACK") | ||
ENDIF (NNPACK_FIND_REQUIRED) | ||
ENDIF (NNPACK_FOUND) | ||
|
||
MARK_AS_ADVANCED( | ||
NNPACK_INCLUDE_DIR | ||
NNPACK_LIB | ||
NNPACK | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include <boost/noncopyable.hpp> | ||
|
||
#include "nnpack.h" | ||
|
||
namespace caffe { | ||
class NNPACKPool : public boost::noncopyable { | ||
public: | ||
NNPACKPool() { | ||
#ifdef USE_MKL | ||
const size_t num_mkl_threads = mkl_get_max_threads(); | ||
#else | ||
// Can we do better here? | ||
const size_t num_mkl_threads = 1; | ||
#endif | ||
if (num_mkl_threads > 1) { | ||
pool_ = pthreadpool_create(num_mkl_threads); | ||
} else { | ||
pool_ = NULL; | ||
} | ||
|
||
} | ||
~NNPACKPool() { | ||
if (pool_) { | ||
pthreadpool_destroy(pool_); | ||
} | ||
pool_ = NULL; | ||
} | ||
|
||
pthreadpool_t pool() { return pool_; }; | ||
|
||
private: | ||
pthreadpool_t pool_; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.