From 78c0ba9761775e8171a0d50de1d1fea930728317 Mon Sep 17 00:00:00 2001 From: Masatoshi Hidaka Date: Tue, 21 Aug 2018 18:49:36 +0900 Subject: [PATCH 1/2] support emscripten v1.38.1 --- src/graph_transpiler/webdnn/backend/webassembly/generator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/graph_transpiler/webdnn/backend/webassembly/generator.py b/src/graph_transpiler/webdnn/backend/webassembly/generator.py index 5dfcd3030..fbe1190bb 100644 --- a/src/graph_transpiler/webdnn/backend/webassembly/generator.py +++ b/src/graph_transpiler/webdnn/backend/webassembly/generator.py @@ -86,6 +86,8 @@ def _compile_fallback_asmjs(self, dirname: str): args.append( "EXPORTED_FUNCTIONS=['_run','_init','_get_static_buffer','_allocate_dynamic_buffer','_get_dynamic_buffer','_set_placeholder_value']") args.append("-s") + args.append("WASM=0") + args.append("-s") args.append(f"TOTAL_MEMORY={self.descriptor.required_heap}") args.append("-s") args.append(f"LEGACY_VM_SUPPORT=1") # polyfills Math.imul, which is needed in IE11 (since emscripten v1.37.23) From 67eef1d32c0d45a116fae5cf8749e596c864d18b Mon Sep 17 00:00:00 2001 From: Masatoshi Hidaka Date: Tue, 21 Aug 2018 20:36:35 +0900 Subject: [PATCH 2/2] Use ConstantFolding for Transpose in webgl backend even optimize is turned off --- .../optimize_rules/split_texture/split_variable.py | 10 ++++++++++ .../webdnn/optimizer/sub_rules/constant_folding.py | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/graph_transpiler/webdnn/backend/webgl/optimize_rules/split_texture/split_variable.py b/src/graph_transpiler/webdnn/backend/webgl/optimize_rules/split_texture/split_variable.py index 1a63ed6c1..ed565daef 100644 --- a/src/graph_transpiler/webdnn/backend/webgl/optimize_rules/split_texture/split_variable.py +++ b/src/graph_transpiler/webdnn/backend/webgl/optimize_rules/split_texture/split_variable.py @@ -25,9 +25,11 @@ from webdnn.graph.operators.reshape import Reshape from webdnn.graph.operators.split_axis import SplitAxis from webdnn.graph.operators.tensordot import Tensordot +from webdnn.graph.operators.transpose import Transpose from webdnn.graph.optimize_rule import OptimizeRule from webdnn.graph.variable import Variable from webdnn.graph.variables.constant_variable import ConstantVariable +from webdnn.optimizer.sub_rules.constant_folding import ConstantFolding from webdnn.util import console from webdnn.util.misc import mul @@ -42,6 +44,14 @@ class SplitVariable(OptimizeRule): def optimize(self, graph: Graph): flag_changed = False + """ + Some operators does not support splitting, but only appear as constant. + Workaround for such case, use ConstantFolding for limited operators even if it is turned off. + """ + cf = ConstantFolding() + graph, flag_changed_in_cf = cf.optimize(graph, (Transpose,)) + flag_changed |= flag_changed_in_cf + c_before = traverse.filter_nodes(traverse.listup_variables(graph), ConstantVariable) c_size_before = sum([c.size for c in c_before]) diff --git a/src/graph_transpiler/webdnn/optimizer/sub_rules/constant_folding.py b/src/graph_transpiler/webdnn/optimizer/sub_rules/constant_folding.py index 0fb582dce..fd377e3ca 100644 --- a/src/graph_transpiler/webdnn/optimizer/sub_rules/constant_folding.py +++ b/src/graph_transpiler/webdnn/optimizer/sub_rules/constant_folding.py @@ -1,4 +1,4 @@ -from typing import Tuple +from typing import Tuple, Optional, Type from webdnn.graph import traverse from webdnn.graph.graph import Graph @@ -19,7 +19,7 @@ def flags(self): flags.optimize.CONSTANT_FOLDING ] - def optimize(self, graph: Graph) -> Tuple[Graph, bool]: + def optimize(self, graph: Graph, target_ops: Optional[Tuple[Type[Operator]]] = None) -> Tuple[Graph, bool]: flag_changed = False for op in traverse.listup_operators(graph): @@ -28,6 +28,8 @@ def optimize(self, graph: Graph) -> Tuple[Graph, bool]: continue if all(isinstance(v, ConstantVariable) for v in op.inputs.values()): + if target_ops is not None and not isinstance(op, target_ops): + continue op.fold_constance(graph) flag_changed = True