2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_RUN_ARGS_H__
18 #define __ONERT_RUN_ARGS_H__
21 #include <unordered_map>
23 #include <boost/program_options.hpp>
27 namespace po = boost::program_options;
32 using TensorShapeMap = std::unordered_map<uint32_t, TensorShape>;
34 #if defined(ONERT_HAVE_HDF5) && ONERT_HAVE_HDF5 == 1
35 enum class WhenToUseH5Shape
37 NOT_PROVIDED, // Param not provided
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()
46 Args(const int argc, char **argv);
49 const std::string &getPackageFilename(void) const { return _package_filename; }
50 const std::string &getModelFilename(void) const { return _model_filename; }
51 const bool useSingleModel(void) const { return _use_single_model; }
52 #if defined(ONERT_HAVE_HDF5) && ONERT_HAVE_HDF5 == 1
53 const std::string &getDumpFilename(void) const { return _dump_filename; }
54 const std::string &getLoadFilename(void) const { return _load_filename; }
55 WhenToUseH5Shape getWhenToUseH5Shape(void) const { return _when_to_use_h5_shape; }
57 const std::string &getDumpRawFilename(void) const { return _dump_raw_filename; }
58 const std::string &getLoadRawFilename(void) const { return _load_raw_filename; }
59 const int getNumRuns(void) const { return _num_runs; }
60 const int getWarmupRuns(void) const { return _warmup_runs; }
61 const int getRunDelay(void) const { return _run_delay; }
62 std::unordered_map<uint32_t, uint32_t> getOutputSizes(void) const { return _output_sizes; }
63 const bool getGpuMemoryPoll(void) const { return _gpumem_poll; }
64 const bool getMemoryPoll(void) const { return _mem_poll; }
65 const bool getWriteReport(void) const { return _write_report; }
66 const bool printVersion(void) const { return _print_version; }
67 TensorShapeMap &getShapeMapForPrepare() { return _shape_prepare; }
68 TensorShapeMap &getShapeMapForRun() { return _shape_run; }
69 /// @brief Return true if "--shape_run" or "--shape_prepare" is provided
70 bool shapeParamProvided();
71 const int getVerboseLevel(void) const { return _verbose_level; }
72 const std::string &getQuantize(void) const { return _quantize; }
73 const std::string &getQuantizedModelPath(void) const { return _quantized_model_path; }
77 void Parse(const int argc, char **argv);
80 po::positional_options_description _positional;
81 po::options_description _options;
83 std::string _package_filename;
84 std::string _model_filename;
85 #if defined(ONERT_HAVE_HDF5) && ONERT_HAVE_HDF5 == 1
86 std::string _dump_filename;
87 std::string _load_filename;
88 WhenToUseH5Shape _when_to_use_h5_shape = WhenToUseH5Shape::NOT_PROVIDED;
90 std::string _dump_raw_filename;
91 std::string _load_raw_filename;
92 TensorShapeMap _shape_prepare;
93 TensorShapeMap _shape_run;
97 std::unordered_map<uint32_t, uint32_t> _output_sizes;
101 bool _print_version = false;
103 bool _use_single_model = false;
104 std::string _quantize;
105 std::string _quantized_model_path;
108 } // end of namespace onert_run
110 #endif // __ONERT_RUN_ARGS_H__