Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / tests / tools / nnpackage_run / src / args.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __NNPACKAGE_RUN_ARGS_H__
18 #define __NNPACKAGE_RUN_ARGS_H__
19
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 #include <boost/program_options.hpp>
24
25 #include "types.h"
26
27 namespace po = boost::program_options;
28
29 namespace nnpkg_run
30 {
31
32 using TensorShapeMap = std::unordered_map<uint32_t, TensorShape>;
33
34 #if defined(ONERT_HAVE_HDF5) && ONERT_HAVE_HDF5 == 1
35 enum class WhenToUseH5Shape
36 {
37   DO_NOT_USE, // don't use shapes in h5 file
38   PREPARE,    // read shapes in h5 file and set them as inputs' shape before calling nnfw_prepare()
39   RUN,        // read shapes in h5 file and set them as inputs' shape before calling nnfw_run()
40 };
41 #endif
42
43 class Args
44 {
45 public:
46   Args(const int argc, char **argv);
47   void print(void);
48
49   const std::string &getPackageFilename(void) const { return _package_filename; }
50 #if defined(ONERT_HAVE_HDF5) && ONERT_HAVE_HDF5 == 1
51   const std::string &getDumpFilename(void) const { return _dump_filename; }
52   const std::string &getLoadFilename(void) const { return _load_filename; }
53   WhenToUseH5Shape getWhenToUseH5Shape(void) const { return _when_to_use_h5_shape; }
54 #endif
55   const int getNumRuns(void) const { return _num_runs; }
56   const int getWarmupRuns(void) const { return _warmup_runs; }
57   const int getRunDelay(void) const { return _run_delay; }
58   std::unordered_map<uint32_t, uint32_t> getOutputSizes(void) const { return _output_sizes; }
59   const bool getGpuMemoryPoll(void) const { return _gpumem_poll; }
60   const bool getMemoryPoll(void) const { return _mem_poll; }
61   const bool getWriteReport(void) const { return _write_report; }
62   const bool printVersion(void) const { return _print_version; }
63   TensorShapeMap &getShapeMapForPrepare() { return _shape_prepare; }
64   TensorShapeMap &getShapeMapForRun() { return _shape_run; }
65   const int getVerboseLevel(void) const { return _verbose_level; }
66
67 private:
68   void Initialize();
69   void Parse(const int argc, char **argv);
70
71 private:
72   po::positional_options_description _positional;
73   po::options_description _options;
74
75   std::string _package_filename;
76 #if defined(ONERT_HAVE_HDF5) && ONERT_HAVE_HDF5 == 1
77   std::string _dump_filename;
78   std::string _load_filename;
79   WhenToUseH5Shape _when_to_use_h5_shape = WhenToUseH5Shape::DO_NOT_USE;
80 #endif
81   TensorShapeMap _shape_prepare;
82   TensorShapeMap _shape_run;
83   int _num_runs;
84   int _warmup_runs;
85   int _run_delay;
86   std::unordered_map<uint32_t, uint32_t> _output_sizes;
87   bool _gpumem_poll;
88   bool _mem_poll;
89   bool _write_report;
90   bool _print_version = false;
91   int _verbose_level;
92 };
93
94 } // end of namespace nnpkg_run
95
96 #endif // __NNPACKAGE_RUN_ARGS_H__