Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 879 #880

Merged
merged 2 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/graph_transpiler/webdnn/backend/webassembly/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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])

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand All @@ -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

Expand Down