2 // Copyright (c) 2018 Intel Corporation
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 ///////////////////////////////////////////////////////////////////////////////////////////////////
19 #include "pass_manager.h"
20 #include "program_helpers.h"
23 void prepare_depthwise_sep_opt::optimize_depthwise_sep_pre(T& node) {
24 if (node.get_groups() == 1) {
25 // enable optimization only when IFM / split <= 8 (otherwise scheduling multiple opt kernels is better) and
27 if (!(node.get_dependency(0).get_output_layout().size.feature[0] / node.get_primitive()->split() <= 8) ||
28 !(node.get_primitive()->split() >= 16))
31 // make sure the weights and biases are data type and
32 // are not reused in other primitives as they will be overriden with concatenated ones
33 for (size_t i = 1; i < node.get_dependencies().size(); i++) {
34 auto& weights_or_biases = node.get_dependency(i);
35 if (weights_or_biases.get_users().size() > 1 || weights_or_biases.type() != data::type_id())
39 // enable optimization only when IFM / groups <= 8 (otherwise scheduling multiple opt kernels is better) and
41 if (!(node.get_dependency(0).get_output_layout().size.feature[0] / node.get_groups() <= 8) ||
42 !(node.get_groups() >= 16))
46 node.set_depthwise_sep_opt(true);
49 template void prepare_depthwise_sep_opt::optimize_depthwise_sep_pre<convolution_node>(convolution_node& node);
50 template void prepare_depthwise_sep_opt::optimize_depthwise_sep_pre<deconvolution_node>(deconvolution_node& node);
52 void prepare_depthwise_sep_opt::run(program_impl& p) {
53 // depthiwise separated convolution/deconvolution optimization
54 for (auto& prim : p.get_processing_order()) {
55 if (prim->type() == convolution::type_id()) {
56 optimize_depthwise_sep_pre(prim->as<convolution>());
57 } else if (prim->type() == deconvolution::type_id()) {
58 optimize_depthwise_sep_pre(prim->as<deconvolution>());