Skip to content
Permalink
Browse files

[Benchmarks] Add google benchmark submodule

Description:
This commit adds the Google benchmark library as a submodule to the Glow
project for use in runtime microbenchmarks.

Testing:
This commit adds a stub for DeviceManager benchmarks to make sure that
the submodule is set up properly.
  • Loading branch information...
SplitInfinity committed Mar 25, 2019
1 parent 49aabfa commit 123cc923aa936f66abf9c61ecb5b4fa2d838bbc4
Showing with 76 additions and 0 deletions.
  1. +3 −0 .gitmodules
  2. +6 −0 CMakeLists.txt
  3. +13 −0 tests/benchmark/CMakeLists.txt
  4. +53 −0 tests/benchmark/DeviceManagerBench.cpp
  5. +1 −0 tests/googlebenchmark
@@ -13,3 +13,6 @@
[submodule "thirdparty/foxi"]
path = thirdparty/foxi
url = https://github.com/houseroad/foxi.git
[submodule "googlebenchmark"]
path = tests/googlebenchmark
url = https://github.com/google/benchmark
@@ -96,6 +96,10 @@ message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})

if(NOT EXISTS "${GLOW_SOURCE_DIR}/tests/googlebenchmark/src")
message(FATAL_ERROR "No googlebenchmark git submodule. Run: git submodule update --init --recursive")
endif()

if(NOT EXISTS "${GLOW_SOURCE_DIR}/tests/googletest/googletest")
message(FATAL_ERROR "No googletest git submodule. Run: git submodule update --init --recursive")
endif()
@@ -130,6 +134,8 @@ if (GLOW_WITH_BUNDLES AND NOT GLOW_WITH_CPU)
endif()

if (GLOW_BUILD_TESTS)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable tests for Google benchmark" FORCE)
add_subdirectory(tests/googlebenchmark EXCLUDE_FROM_ALL)
add_subdirectory(tests/googletest EXCLUDE_FROM_ALL)
add_subdirectory(tests)

@@ -10,4 +10,17 @@ add_executable(ConvBench
target_link_libraries(ConvBench
PRIVATE
CPURuntimeNative)

add_executable(DeviceManagerBench
DeviceManagerBench.cpp)
target_link_libraries(DeviceManagerBench
PRIVATE
Backend
Backends
DeviceManager
Graph
IR
ExecutionEngine
Optimizer
benchmark)
endif()
@@ -0,0 +1,53 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* 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 "benchmark/benchmark.h"
#include "glow/Backends/DeviceManager.h"

using namespace glow;
using namespace glow::runtime;

/// Fixture class for reusing DeviceManager setup across benchmarks.
class CPUDeviceManagerBench : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State &state) {
// Create device manager.
device_.reset(DeviceManager::createDeviceManager(BackendKind::CPU));
}

// Pointer to the DeviceManager used for benchmarking.
std::unique_ptr<DeviceManager> device_;
};

// Benchmark for DeviceManager::init().
BENCHMARK_DEFINE_F(CPUDeviceManagerBench, init)(benchmark::State &state) {
// Init the DeviceManager until state requests to stop.
for (auto _ : state) {
(void)device_->init();

// Don't including stopping the DeviceManager in the timing for this
// benchmark.
state.PauseTiming();
(void)device_->stop();
state.ResumeTiming();
}
}

// Benchmark registration.
BENCHMARK_REGISTER_F(CPUDeviceManagerBench, init)->Iterations(100);

// Main.
BENCHMARK_MAIN();
Submodule googlebenchmark added at fae872

0 comments on commit 123cc92

Please sign in to comment.
You can’t perform that action at this time.