summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
author윤지영/On-Device Lab(SR)/Staff Engineer/삼성전자 <jy910.yun@samsung.com>2019-06-04 13:57:13 +0900
committer이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>2019-06-04 13:57:13 +0900
commitca8b9e2d70be7d22351badc39d35fdd89a2c77c6 (patch)
treeb4a2b5e5c60ed628ba47cff0311cee4b59301d39 /tools
parent61eaea9096f1a6af6760280b7e02bc6de5cabdb2 (diff)
downloadnnfw-ca8b9e2d70be7d22351badc39d35fdd89a2c77c6.tar.gz
nnfw-ca8b9e2d70be7d22351badc39d35fdd89a2c77c6.tar.bz2
nnfw-ca8b9e2d70be7d22351badc39d35fdd89a2c77c6.zip
[kbenchmark] Add argument parser (#5336)
This patch adds argument parsers for kbenchmark tool. Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/kbenchmark/Args.cc105
-rw-r--r--tools/kbenchmark/Args.h53
-rw-r--r--tools/kbenchmark/CMakeLists.txt14
-rw-r--r--tools/kbenchmark/Driver.cc40
-rw-r--r--tools/kbenchmark/README.md21
5 files changed, 233 insertions, 0 deletions
diff --git a/tools/kbenchmark/Args.cc b/tools/kbenchmark/Args.cc
new file mode 100644
index 000000000..95145a84e
--- /dev/null
+++ b/tools/kbenchmark/Args.cc
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * 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 "Args.h"
+
+#include <iostream>
+#include <boost/filesystem.hpp>
+
+namespace kbenchmark
+{
+
+Args::Args(const int argc, char **argv) noexcept { Initialize(argc, argv); }
+
+void Args::Initialize(const int argc, char **argv)
+{
+ // General options
+ po::options_description general("General options");
+ // clang-format off
+ general.add_options()("help,h", "Display available options")
+ ("config,c", po::value<std::string>(&_config)->required(), "Configuration filename")
+ ("kernel,k", po::value<std::vector<std::string>>(&_kernel)->multitoken()->composing()->required(), "Kernel library name, support multiple kernel libraries")
+ ("reporter,r", po::value<std::string>(&_reporter)->default_value("standard"), "Set reporter types(standard, html, junit, csv)")
+ ("verbose,v", po::value<int>(&_verbose)->default_value(0)->implicit_value(true), "Show verbose output")
+ ("output,o", po::value<std::string>(&_output)->default_value(""), "Set additional strings for output file name")
+ ;
+ // clang-format on
+
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, general), vm);
+
+ try
+ {
+ po::notify(vm);
+ }
+ catch (const boost::program_options::required_option &e)
+ {
+ if (vm.count("help"))
+ {
+ std::cout << general << std::endl;
+ exit(0);
+ }
+ else
+ {
+ throw e;
+ }
+ }
+
+ if (vm.count("help"))
+ {
+ std::cout << general << std::endl;
+ exit(0);
+ }
+
+ if (vm.count("config"))
+ {
+ if (_config.substr(_config.find_last_of(".") + 1) != "config")
+ {
+ std::cerr << "Please specify .config file" << std::endl;
+ exit(1);
+ }
+
+ if (!boost::filesystem::exists(_config))
+ {
+ std::cerr << _config << " file not found" << std::endl;
+ exit(1);
+ }
+ }
+
+ if (vm.count("kernel"))
+ {
+ for (auto &k : _kernel)
+ {
+ if (!boost::filesystem::exists(k))
+ {
+ std::cerr << k << " file not found" << std::endl;
+ exit(1);
+ }
+ }
+ }
+
+ if (vm.count("reporter"))
+ {
+ if (_reporter != "junit" && _reporter != "csv" && _reporter != "html" &&
+ _reporter != "standard")
+ {
+ std::cerr << "Invalid reporter" << std::endl;
+ exit(1);
+ }
+ }
+}
+
+} // namespace kbenchmark
diff --git a/tools/kbenchmark/Args.h b/tools/kbenchmark/Args.h
new file mode 100644
index 000000000..b848f9579
--- /dev/null
+++ b/tools/kbenchmark/Args.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * 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.
+ */
+
+#ifndef __KBENCHMARK_ARGS_H__
+#define __KBENCHMARK_ARGS_H__
+
+#include <string>
+#include <vector>
+#include <boost/program_options.hpp>
+
+namespace po = boost::program_options;
+
+namespace kbenchmark
+{
+
+class Args
+{
+public:
+ Args(const int argc, char **argv) noexcept;
+
+ const std::string &config(void) { return _config; }
+ const std::vector<std::string> &kernel(void) { return _kernel; }
+ const std::string &reporter(void) { return _reporter; }
+ const std::string &output(void) { return _output; }
+ int verbose(void) { return _verbose; }
+
+private:
+ void Initialize(const int argc, char **argv);
+
+private:
+ std::string _config;
+ std::vector<std::string> _kernel;
+ std::string _reporter;
+ std::string _output;
+ int _verbose;
+};
+
+} // namespace kbenchmark
+
+#endif // __KBENCHMARK_ARGS_H__
diff --git a/tools/kbenchmark/CMakeLists.txt b/tools/kbenchmark/CMakeLists.txt
index 3207000b5..71881ec7b 100644
--- a/tools/kbenchmark/CMakeLists.txt
+++ b/tools/kbenchmark/CMakeLists.txt
@@ -7,3 +7,17 @@ nnfw_find_package(Nonius QUIET)
if(NOT Nonius_FOUND)
return()
endif(NOT Nonius_FOUND)
+
+nnfw_find_package(Boost QUIET)
+
+if(NOT Boost_FOUND)
+ return()
+endif(NOT Boost_FOUND)
+
+# driver
+file(GLOB_RECURSE SOURCES "*.cc")
+
+add_executable(kbenchmark ${SOURCES})
+target_include_directories(kbenchmark PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_link_libraries(kbenchmark PUBLIC pthread boost_program_options boost_system boost_filesystem)
+install(TARGETS kbenchmark DESTINATION bin)
diff --git a/tools/kbenchmark/Driver.cc b/tools/kbenchmark/Driver.cc
new file mode 100644
index 000000000..c2cc33454
--- /dev/null
+++ b/tools/kbenchmark/Driver.cc
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * 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 "Args.h"
+
+#include <iostream>
+#include <string>
+
+using namespace kbenchmark;
+
+int main(int argc, char *argv[])
+{
+ Args args(argc, argv);
+
+ // Set default test name
+ std::string config_name{args.config()};
+ config_name = config_name.substr(config_name.find_last_of("/") + 1);
+ config_name = config_name.substr(0, config_name.find_last_of("."));
+ std::string test_name{"test_benchmark_" + config_name};
+ if (!args.output().empty())
+ {
+ test_name += (std::string{"_"} + args.output());
+ }
+ std::cout << "Benchmark test name\n " << test_name << std::endl;
+
+ return 0;
+}
diff --git a/tools/kbenchmark/README.md b/tools/kbenchmark/README.md
index 0a684a80d..61c34511b 100644
--- a/tools/kbenchmark/README.md
+++ b/tools/kbenchmark/README.md
@@ -52,3 +52,24 @@ weights_type: FLOAT32
bias: [32]
```
+## kbenchmark
+
+### Available commands
+The binary takes the following required parameters:
+
+* `config`: `string` \
+ The path to the configuration file.
+* `kernel`: `string` \
+ The path to the benchmark kernel library file. It allows multiple kernel libraries either by using space or by repeatedly calling `--kernel`.
+
+and the following optional parameters:
+
+* `reporter`: `string` \
+ Set the reporter types among `standard`, `html`, `junit` or `csv`. Default reporter type is `standard`.
+* `output`: `string` \
+ Set the additional strings for output file name.
+* `help`: \
+ Display available options.
+* `verbose`: \
+ Show verbose messages.
+