2 Copyright (c) 2018-2019 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.
20 from mo.graph.graph import Node, Graph
21 from mo.middle.passes.fusing.helpers import get_value_id
24 def _check_lin_op(node: Node, layout: str):
25 lin_ops = ['Mul', 'Add']
26 if node.soft_get('op') in lin_ops:
27 weights_id = get_value_id(node)
28 if weights_id is None:
29 node.graph.node[node.id]['can_be_fused'] = False
30 log.info('[ FUSING ] Node {} wasn\'t marked as fusable (no weights, probably this is Eltwise that is not '
31 'fusable)'.format(node.id))
34 node.graph.node[node.id]['can_be_fused'] = True
35 log.info('[ FUSING ] Node {} marked as fusable'.format(node.id))
38 def mark_unfused_nodes(graph: Graph, regex_masks: str):
39 regex_masks = [] if not regex_masks else regex_masks.split(',')
40 nodes = graph.get_op_nodes()
42 if node.has_valid('can_be_fused'):
45 for mask in regex_masks:
46 res = re.findall(mask, node.name)
48 graph.node[node.id]['can_be_fused'] = False
49 log.info('[ FUSING ] Node {} wasn\'t marked as fusable (user decision {})'.format(node.id,mask))
52 _check_lin_op(node, graph.graph['layout'])