From ed5f5866c25a1fd79bb1e5cfbdef266137defdd0 Mon Sep 17 00:00:00 2001 From: Marcin Junczys-Dowmunt Date: Fri, 25 Oct 2019 17:02:16 -0700 Subject: [PATCH] bye bye boost --- CMakeLists.txt | 23 +++++++++++++---------- src/common/timer.h | 33 +++++---------------------------- src/data/corpus.cpp | 4 ---- src/graph/auto_tuner.h | 18 +++--------------- 4 files changed, 21 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bde2f45..c8d0d352 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ option(USE_NCCL "Use NCCL library" ON) option(USE_MPI "Use MPI library" OFF) option(COMPILE_EXAMPLES "Compile examples" OFF) option(COMPILE_TESTS "Compile tests" OFF) -option(COMPILE_SERVER "Compile marian-server" ON) +option(COMPILE_SERVER "Compile marian-server" OFF) option(USE_FBGEMM "Use FBGEMM" ON) option(USE_DOXYGEN "Build documentation with Doxygen" ON) @@ -293,7 +293,7 @@ if(COMPILE_CPU) endif(MKL_FOUND) endif(COMPILE_CPU) -set(BOOST_COMPONENTS timer iostreams filesystem system chrono) +set(BOOST_COMPONENTS "") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) add_definitions(-DUSE_BOOST_REGEX=1) set(BOOST_COMPONENTS ${BOOST_COMPONENTS} regex) @@ -308,6 +308,7 @@ if(COMPILE_SERVER) message(STATUS "Found OpenSSL") include_directories(${OPENSSL_INCLUDE_DIR}) set(EXT_LIBS ${EXT_LIBS} ${OPENSSL_CRYPTO_LIBRARY}) + set(BOOST_COMPONENTS ${BOOST_COMPONENTS} system) else(OpenSSL_FOUND) message(WARNING "Cannot find OpenSSL library. Not compiling server.") set(COMPILE_SERVER "off") @@ -322,14 +323,16 @@ if(USE_STATIC_LIBS) set(Boost_USE_STATIC_LIBS ON) endif() -find_package(Boost COMPONENTS ${BOOST_COMPONENTS}) -if(Boost_FOUND) - include_directories(${Boost_INCLUDE_DIRS}) - set(EXT_LIBS ${EXT_LIBS} ${Boost_LIBRARIES}) - set(EXT_LIBS ${EXT_LIBS} ${ZLIB_LIBRARIES}) # hack for static compilation -else(Boost_FOUND) - message(SEND_ERROR "Cannot find Boost libraries. Terminating.") -endif(Boost_FOUND) +if(BOOST_COMPONENTS) + find_package(Boost COMPONENTS ${BOOST_COMPONENTS}) + if(Boost_FOUND) + include_directories(${Boost_INCLUDE_DIRS}) + set(EXT_LIBS ${EXT_LIBS} ${Boost_LIBRARIES}) + set(EXT_LIBS ${EXT_LIBS} ${ZLIB_LIBRARIES}) # hack for static compilation + else(Boost_FOUND) + message(SEND_ERROR "Cannot find Boost libraries. Terminating.") + endif(Boost_FOUND) +endif(BOOST_COMPONENTS) if(COMPILE_TESTS) enable_testing() diff --git a/src/common/timer.h b/src/common/timer.h index 649bba9d..ac83b363 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -1,25 +1,8 @@ #pragma once -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsuggest-override" -#endif -#ifndef NO_BOOST -#include -#endif -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - -#ifdef _MSC_VER -// (needed on Windows only to resolve a link error, but causes a warning on Linux) -#ifndef NO_BOOST -#include -#endif -#endif - -#include +#include #include +#include namespace marian { namespace timer { @@ -33,7 +16,6 @@ static inline std::string currentDate() { } // Timer measures elapsed time. -// This is a wrapper around std::chrono providing wall time only class Timer { protected: using clock = std::chrono::steady_clock; @@ -93,14 +75,9 @@ public: } }; -// @TODO: replace with a timer providing CPU/thread time on both Linux and Windows. This is required -// for auto-tuner. -// Check get_clocktime on Linux: https://linux.die.net/man/3/clock_gettime -// Check GetThreadTimes on Windows: -// https://docs.microsoft.com/en-gb/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getthreadtimes -#ifndef NO_BOOST -using CPUTimer = boost::timer::cpu_timer; -#endif +// std::chrono::steady_clock seems to be the right choice here. +using CPUTimer = Timer; + } // namespace timer } // namespace marian diff --git a/src/data/corpus.cpp b/src/data/corpus.cpp index 227efde1..84d5f9f4 100644 --- a/src/data/corpus.cpp +++ b/src/data/corpus.cpp @@ -190,7 +190,6 @@ void Corpus::shuffleData(const std::vector& paths) { LOG(info, "[data] Done shuffling {} sentences (cached in RAM)", numSentences); } else { -#ifndef NO_BOOST // create temp files that contain the data in randomized order tempFiles_.resize(numStreams); for(size_t i = 0; i < numStreams; ++i) { @@ -210,9 +209,6 @@ void Corpus::shuffleData(const std::vector& paths) { files_[i] = std::move(inputStream); } LOG(info, "[data] Done shuffling {} sentences to temp files", numSentences); -#else - ABORT("Shuffling to temp file is not available when compiling with NO_BOOST option. Use --shuffle-in-ram."); -#endif } pos_ = 0; } diff --git a/src/graph/auto_tuner.h b/src/graph/auto_tuner.h index 6e0fe5eb..7a248bf9 100755 --- a/src/graph/auto_tuner.h +++ b/src/graph/auto_tuner.h @@ -25,9 +25,7 @@ private: // collects the statistics. const size_t collectStatMax = 50; -#ifndef NO_BOOST UPtr timer_; -#endif // This structure holds a hash key an algorithm function (e.g. int16, packed gemm, mkl gemm) // for a specific operation size @@ -93,38 +91,28 @@ public: Return run(Args... args) { return algorithms_[choose()].algorithm(args...); } void start(size_t hash) override { -#ifndef NO_BOOST if(!timer_ && done_.count(hash) == 0) timer_.reset(new timer::CPUTimer()); -#else - hash; - LOG_ONCE(warn, "Auto-tuner not available when compiling with NO_BOOST option. Will use the first option."); -#endif } void stop(size_t hash, bool stop) override { -#ifndef NO_BOOST if(stop && done_.count(hash) == 0) { timer_->stop(); - typedef std::chrono::duration sec; - sec seconds = std::chrono::nanoseconds(timer_->elapsed().user); + auto seconds = timer_->elapsed(); auto it = stats_.find(hash); if(it != stats_.end()) { if(it->second.runs < collectStatMax) { - it->second.time += seconds.count(); + it->second.time += seconds; it->second.runs += 1; } } else { - stats_.emplace(hash, Stat({seconds.count(), 1})); + stats_.emplace(hash, Stat({seconds, 1})); } timer_.reset(nullptr); } -#else - hash; stop; -#endif } };