[tflite_benchmark] Remove Boost dependency (#7751)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Thu, 26 Sep 2019 01:03:47 +0000 (10:03 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 26 Sep 2019 01:03:47 +0000 (10:03 +0900)
Accumulator is the only module that `tflite_benchmark` is depend on.
This commit introduces our own Accumulator and replace with it.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
tests/tools/tflite_benchmark/CMakeLists.txt
tests/tools/tflite_benchmark/src/tflite_benchmark.cc

index 634d451..ed51861 100644 (file)
@@ -1,10 +1,6 @@
 list(APPEND SOURCES "src/tflite_benchmark.cc")
 
-nnfw_find_package(Boost REQUIRED)
-
 add_executable(tflite_benchmark ${SOURCES})
 target_link_libraries(tflite_benchmark nnfw_lib_tflite tensorflow-lite ${LIB_PTHREAD} dl nnfw_lib_misc)
 
-target_include_directories(tflite_benchmark PRIVATE ${Boost_INCLUDE_DIRS})
-
 install(TARGETS tflite_benchmark DESTINATION bin)
index 21eee4a..0636f36 100644 (file)
 #include "tflite/Diff.h"
 #include "misc/tensor/IndexIterator.h"
 
-#include <boost/accumulators/accumulators.hpp>
-#include <boost/accumulators/statistics/stats.hpp>
-#include <boost/accumulators/statistics/min.hpp>
-#include <boost/accumulators/statistics/max.hpp>
-#include <boost/accumulators/statistics/mean.hpp>
-
 #include <chrono>
 #include <iostream>
 #include <thread>
@@ -70,6 +64,30 @@ bool checkParams(const int argc, char **argv)
   return true;
 }
 
+template <typename T> class Accumulator
+{
+public:
+  Accumulator() = default;
+
+  void operator()(T val)
+  {
+    ++_num;
+    _sum += val;
+    _min = std::min(_min, val);
+    _max = std::max(_max, val);
+  }
+
+  T mean() const { return _sum / static_cast<T>(_num); }
+  T min() const { return _min; }
+  T max() const { return _max; }
+
+private:
+  uint32_t _num = 0u;
+  T _sum = 0.0;
+  T _min = std::numeric_limits<T>::max();
+  T _max = std::numeric_limits<T>::lowest();
+};
+
 int main(const int argc, char **argv)
 {
 
@@ -227,9 +245,7 @@ int main(const int argc, char **argv)
   //
   const auto cnt = nnfw::misc::EnvVar("COUNT").asInt(1);
 
-  using namespace boost::accumulators;
-
-  accumulator_set<double, stats<tag::mean, tag::min, tag::max>> acc;
+  Accumulator<double> acc;
 
   for (int n = 0; n < cnt; ++n)
   {
@@ -256,9 +272,9 @@ int main(const int argc, char **argv)
   }
 
   std::cout << "--------" << std::endl;
-  std::cout << "Min: " << min(acc) << "ms" << std::endl;
-  std::cout << "Max: " << max(acc) << "ms" << std::endl;
-  std::cout << "Mean: " << mean(acc) << "ms" << std::endl;
+  std::cout << "Min: " << acc.min() << "ms" << std::endl;
+  std::cout << "Max: " << acc.max() << "ms" << std::endl;
+  std::cout << "Mean: " << acc.mean() << "ms" << std::endl;
 
   return 0;
 }