From dbc7037911386692a519d75dbcac3b867759d152 Mon Sep 17 00:00:00 2001 From: Yangqing Jia Date: Sat, 23 Sep 2017 16:57:32 -0700 Subject: [PATCH] Use own benchmark and not any system pre-built ones: (1) use the cmake files of the corresponding libs (2) allow static linkage of gtest and gbenchmark. (3) Helps removing the temp solution in #1112 --- CMakeLists.txt | 6 ------ caffe2/binaries/CMakeLists.txt | 4 ++++ cmake/Dependencies.cmake | 27 +++++++++++++++++++-------- third_party/benchmark | 2 +- third_party/googletest | 2 +- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dc5cdb8c24..001077a5237 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,12 +9,6 @@ set(CAFFE2_VERSION_PATCH 1) set(CAFFE2_VERSION "${CAFFE2_VERSION_MAJOR}.${CAFFE2_VERSION_MINOR}.${CAFFE2_VERSION_PATCH}") -# ---[ Do not search cmake install prefix. See the following link for details: -# https://github.com/caffe2/caffe2/commit/251d2d0c521c781276eea3748d92fc92e5dbceab -message(STATUS "Setting CMAKE_FIND_NO_INSTALL_PREFIX") -set(CMAKE_FIND_NO_INSTALL_PREFIX TRUE) - - # ---[ Options. # Note to developers: if you add an option below, make sure you also add it to # cmake/Summary.cmake so that the summary prints out the option values. diff --git a/caffe2/binaries/CMakeLists.txt b/caffe2/binaries/CMakeLists.txt index 6995ef4268e..48e4d447af6 100644 --- a/caffe2/binaries/CMakeLists.txt +++ b/caffe2/binaries/CMakeLists.txt @@ -13,6 +13,10 @@ if (USE_CUDA) caffe2_binary_target("inspect_gpus.cc") target_link_libraries(inspect_gpus ${CUDA_LIBRARIES}) caffe2_binary_target("print_core_object_sizes.cc") + + # Core overhead benchmark + caffe2_binary_target("core_overhead_benchmark.cc") + target_link_libraries(core_overhead_benchmark benchmark) endif() if (USE_ZMQ) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 29df60ec984..72dccdf0d9d 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -114,17 +114,28 @@ endif() # ---[ Googletest and benchmark if(BUILD_TEST) + set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) + # We will build gtest as static libs and embed it directly into the binary. + set(BUILD_SHARED_LIBS OFF) + # For gtest, we will simply embed it into our test binaries, so we won't + # need to install it. + set(BUILD_GTEST ON) + set(INSTALL_GTEST OFF) + # We currently don't need gmock right now. + set(BUILD_GMOCK OFF) add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/googletest) caffe2_include_directories(${PROJECT_SOURCE_DIR}/third_party/googletest/googletest/include) - find_package(Benchmark) - if(Benchmark_FOUND) - list(APPEND Caffe2_DEPENDENCY_LIBS ${Benchmark_LIBRARIES}) - caffe2_include_directories(${Benchmark_INCLUDE_DIRS}) - else() - add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/benchmark) - caffe2_include_directories(${PROJECT_SOURCE_DIR}/third_party/benchmark/include) - endif() + # We will not need to test benchmark lib itself. + set(BENCHMARK_ENABLE_TESTING OFF) + # We will not need to install benchmark. This is pending + # https://github.com/google/benchmark/pull/463 + set(INSTALL_BENCHMARK OFF) + add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/benchmark) + caffe2_include_directories(${PROJECT_SOURCE_DIR}/third_party/benchmark/include) + + # Recover the build shared libs option. + set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS}) endif() # ---[ LMDB diff --git a/third_party/benchmark b/third_party/benchmark index 4bf28e611b5..25acf220a44 160000 --- a/third_party/benchmark +++ b/third_party/benchmark @@ -1 +1 @@ -Subproject commit 4bf28e611b55de8a2d4eece3c335e014f8b0f630 +Subproject commit 25acf220a44ccc41104a690731fcf646cc3e8192 diff --git a/third_party/googletest b/third_party/googletest index 5e7fd50e17b..69e48e92de4 160000 --- a/third_party/googletest +++ b/third_party/googletest @@ -1 +1 @@ -Subproject commit 5e7fd50e17b6edf1cadff973d0ec68966cf3265e +Subproject commit 69e48e92de43960a316a826293510b7b3deb9eca