mimic_set_batch_size.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <functional>
8 #include <memory>
9 #include <numeric>
10 
11 #include <ngraph/ngraph.hpp>
12 #include <ngraph/opsets/opset1.hpp>
13 #include <ngraph/opsets/opset3.hpp>
14 #include <ngraph/opsets/opset5.hpp>
15 #include <ngraph/pattern/matcher.hpp>
16 #include <ngraph/pattern/op/wrap_type.hpp>
17 #include <ngraph/rt_info.hpp>
18 
19 #include <transformations_visibility.hpp>
20 #include <ngraph/pass/graph_rewrite.hpp>
21 
22 namespace ngraph {
23 namespace pass {
24 
25 class TRANSFORMATIONS_API MimicSetBatchSize;
26 
27 } // namespace pass
28 } // namespace ngraph
29 
30 /**
31  * @ingroup ie_transformation_common_api
32  * @brief MimicSetBatchSize transformation relaxes hard-coded output batch dimension of Reshape operation.
33  * For Reshape with input shape [in_batch, ...] and pattern value [out_batch, ...] it generates a sub-graph
34  * which basically keeps ratio of input and output batch size and performs the following calculation:
35  *
36  * scale = float(out_batch) / float(in_batch)
37  * modified_batch_dim = int(ceil(float(shape(input)[0]) * scale))
38  *
39  * This transformation should be executed only while setBatchSize method call
40  */
41 
42 class ngraph::pass::MimicSetBatchSize : public ngraph::pass::FunctionPass {
43 public:
44  NGRAPH_RTTI_DECLARATION;
45  bool run_on_function(std::shared_ptr<ngraph::Function> f) override;
46 };
MimicSetBatchSize transformation relaxes hard-coded output batch dimension of Reshape operation....
Definition: mimic_set_batch_size.hpp:42
ngraph namespace
Definition: add_fake_quantize_fusion.hpp:14