Compute Library
 21.02
graph_edsr.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
26 
29 #include "utils/Utils.h"
30 
31 #include "graph_edsr.h"
32 
33 using namespace arm_compute::graph;
34 using namespace arm_compute::utils;
35 
36 class GraphEdsrExample : public Example
37 {
38 public:
39  GraphEdsrExample()
40  : cmd_parser(), common_opts(cmd_parser), common_params()
41  {
42  expected_output_filename = cmd_parser.add_option<SimpleOption<std::string>>("expected-output-filename", "");
43  expected_output_filename->set_help("Name of npy file containing the expected output to validate the graph output.");
44  }
45 
46  GraphEdsrExample(const GraphEdsrExample &) = delete;
47  GraphEdsrExample &operator=(const GraphEdsrExample &) = delete;
48  ~GraphEdsrExample() override = default;
49 
50  bool do_setup(int argc, char **argv) override
51  {
52  // Parse arguments
53  cmd_parser.parse(argc, argv);
54  cmd_parser.validate();
55 
56  // Consume common parameters
57  common_params = consume_common_graph_parameters(common_opts);
58 
59  // Return when help menu is requested
60  if(common_params.help)
61  {
62  cmd_parser.print_help(argv[0]);
63  return false;
64  }
65 
66  ARM_COMPUTE_EXIT_ON_MSG(common_params.data_type != DataType::QASYMM8, "Only QASYMM8 is supported for this graph example");
67 
68  // Print parameter values
69  std::cout << common_params << std::endl;
70 
71  model.setup(common_params, *expected_output_filename);
72 
73  GraphConfig config;
74  config.num_threads = common_params.threads;
75  config.use_tuner = common_params.enable_tuner;
76  config.tuner_mode = common_params.tuner_mode;
77  config.tuner_file = common_params.tuner_file;
78  config.mlgo_file = common_params.mlgo_file;
79 
80  context.set_config(config);
81 
82  auto pass_manager = create_default_pass_manager(common_params.target, config);
83  manager.finalize_graph(model.graph(), context, pass_manager, common_params.target);
84 
85  return true;
86  }
87 
88  void do_run() override
89  {
90  manager.execute_graph(model.graph());
91  }
92 
93 private:
94  CommandLineParser cmd_parser;
95  CommonGraphOptions common_opts;
96  CommonGraphParams common_params;
97 
98  GraphContext context{};
99  GraphManager manager{};
100 
101  SimpleOption<std::string> *expected_output_filename{ nullptr };
102 
103  GraphEdsr model{};
104 };
105 
106 /** Internal implementation of UINT8 EDSR with some modifications from the paper.
107  * The sub-pixel convolution has been replaced with a deconvolution layer. This
108  * operation is mathematically the same.
109  *
110  * Convolution replaced by deconvolution:
111  * https://arxiv.org/abs/1609.07009
112  * "Is the deconvolution layer the same as a convolutional layer?"
113  * Wenzhe Shi, Jose Caballero, Lucas Theis, Ferenc Huszar, Andrew Aitken, Christian Ledig, Zehan Wang
114  *
115  * Original model is:
116  * https://arxiv.org/abs/1707.02921
117  * "Enhanced Deep Residual Networks for Single Image Super-Resolution"
118  * Bee Lim, Sanghyun Son, Heewon Kim, Seungjun Nah, Kyoung Mu Lee
119  *
120  * @note To list all the possible arguments execute the binary appended with the --help option
121  *
122  * @param[in] argc Number of arguments
123  * @param[in] argv Arguments
124  *
125  * @return Return code
126  */
127 int main(int argc, char **argv)
128 {
129  return run_example<GraphEdsrExample>(argc, argv);
130 }
Graph configuration structure Device target types.
Definition: Types.h:80
CLTunerMode tuner_mode
Tuner mode to be used by the CL tuner.
Definition: Types.h:87
void consume_common_graph_parameters(CommonGraphValidateOptions &options, CommonParams &common_params)
Consumes the consume_common_graph_parameters graph options and creates a structure containing any inf...
Common command line options used to configure the graph examples.
Class to parse command line arguments.
int main(int argc, char **argv)
Internal implementation of UINT8 EDSR with some modifications from the paper.
Definition: graph_edsr.cpp:127
std::string mlgo_file
Filename to load MLGO heuristics from.
Definition: Types.h:90
std::string tuner_file
File to load/store tuning values from.
Definition: Types.h:89
#define ARM_COMPUTE_EXIT_ON_MSG(cond, msg)
If the condition is true, the given message is printed and program exits.
Definition: Error.h:379
quantized, asymmetric fixed-point 8-bit number unsigned
Abstract Example class.
Definition: Utils.h:78
Graph manager class.
Definition: GraphManager.h:45
Structure holding all the common graph parameters.
bool use_tuner
Use a tuner in tunable backends.
Definition: Types.h:85
PassManager create_default_pass_manager(Target target, const GraphConfig &cfg)
Creates a default PassManager.
Definition: Utils.cpp:77
int num_threads
Number of threads to use (thread capable backends), if 0 the backend will auto-initialize, if -1 the backend will stay as it is.
Definition: Types.h:88
void set_help(std::string help)
Set the help message for the option.
Definition: Option.h:125