From 4dfbec38fc895eda5f564aff6e852dfc76643cea Mon Sep 17 00:00:00 2001 From: SRK Reddy Date: Thu, 10 Jan 2019 12:11:57 +0530 Subject: [PATCH 1/4] [RELAY] Filter PlaceholderOp from schedule. --- src/relay/backend/compile_engine.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/relay/backend/compile_engine.cc b/src/relay/backend/compile_engine.cc index 0dc9e458d7aa..d0043dc04376 100644 --- a/src/relay/backend/compile_engine.cc +++ b/src/relay/backend/compile_engine.cc @@ -83,11 +83,18 @@ class ScheduleGetter : cache_node->func_name = readable_name_stream_.str(); CachedFunc cfunc(cache_node); CHECK(master_op_.defined()); + // Filter PlacehosderOp from the outputs for schedule. + tvm::Array tensor_outs; + for (const auto& tensor : cache_node->outputs) { + if (!tensor->op.as()) { + tensor_outs.push_back(tensor); + } + } Schedule schedule; // No need to register schedule for device copy op. if (master_attrs_.as() == nullptr) { schedule = - fschedule[master_op_](master_attrs_, cache_node->outputs, target_); + fschedule[master_op_](master_attrs_, tensor_outs, target_); for (const auto& scalar : scalars_) { schedule[scalar].compute_inline(); } From 4497b316e8466f5f34f4594a2d977822624743b6 Mon Sep 17 00:00:00 2001 From: SRK Reddy Date: Mon, 14 Jan 2019 11:42:19 +0530 Subject: [PATCH 2/4] * test case --- tests/python/relay/test_backend_compile_engine.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/python/relay/test_backend_compile_engine.py b/tests/python/relay/test_backend_compile_engine.py index 568d7849e7ee..20eadff6213b 100644 --- a/tests/python/relay/test_backend_compile_engine.py +++ b/tests/python/relay/test_backend_compile_engine.py @@ -33,6 +33,17 @@ def get_func(shape): y.asnumpy(), x.asnumpy() * 3) engine.dump() +def test_compile_placeholder_bypass(): + engine = relay.backend.compile_engine.get() + x = relay.var("x", shape=(2, 3)) + y = relay.var("y", shape=(2, 3)) + z = relay.var("z", shape=(2, 3)) + result = relay.Tuple([relay.op.concatenate([y, z], axis=0)]) + #result = relay.Tuple([x, relay.op.concatenate([y, z], axis=0)]) + func = relay.Function(relay.ir_pass.free_vars(result), result) + with relay.build_config(opt_level=3): + graph, lib, params = relay.build(func, 'llvm') if __name__ == "__main__": test_compile_engine() + test_compile_placeholder_bypass() From e8517eb42444554087625a4561c3d538c7fc80b8 Mon Sep 17 00:00:00 2001 From: SRK Reddy Date: Mon, 14 Jan 2019 11:44:05 +0530 Subject: [PATCH 3/4] * test case --- src/relay/backend/compile_engine.cc | 2 +- tests/python/relay/test_backend_compile_engine.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/relay/backend/compile_engine.cc b/src/relay/backend/compile_engine.cc index d0043dc04376..7a6bcadeda72 100644 --- a/src/relay/backend/compile_engine.cc +++ b/src/relay/backend/compile_engine.cc @@ -83,7 +83,7 @@ class ScheduleGetter : cache_node->func_name = readable_name_stream_.str(); CachedFunc cfunc(cache_node); CHECK(master_op_.defined()); - // Filter PlacehosderOp from the outputs for schedule. + // Filter PlaceholderOp from the outputs for schedule. tvm::Array tensor_outs; for (const auto& tensor : cache_node->outputs) { if (!tensor->op.as()) { diff --git a/tests/python/relay/test_backend_compile_engine.py b/tests/python/relay/test_backend_compile_engine.py index 20eadff6213b..a3a3af3f94b8 100644 --- a/tests/python/relay/test_backend_compile_engine.py +++ b/tests/python/relay/test_backend_compile_engine.py @@ -38,10 +38,9 @@ def test_compile_placeholder_bypass(): x = relay.var("x", shape=(2, 3)) y = relay.var("y", shape=(2, 3)) z = relay.var("z", shape=(2, 3)) - result = relay.Tuple([relay.op.concatenate([y, z], axis=0)]) - #result = relay.Tuple([x, relay.op.concatenate([y, z], axis=0)]) + result = relay.Tuple([x, relay.op.concatenate([y, z], axis=0)]) func = relay.Function(relay.ir_pass.free_vars(result), result) - with relay.build_config(opt_level=3): + with relay.build_config(opt_level=0): graph, lib, params = relay.build(func, 'llvm') if __name__ == "__main__": From aa7715524bd9dc66b9b7e3986ae44fe759a59199 Mon Sep 17 00:00:00 2001 From: SRK Reddy Date: Tue, 15 Jan 2019 07:03:11 +0530 Subject: [PATCH 4/4] * review comments. --- src/relay/backend/compile_engine.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/relay/backend/compile_engine.cc b/src/relay/backend/compile_engine.cc index 7a6bcadeda72..73bae053cc82 100644 --- a/src/relay/backend/compile_engine.cc +++ b/src/relay/backend/compile_engine.cc @@ -83,7 +83,9 @@ class ScheduleGetter : cache_node->func_name = readable_name_stream_.str(); CachedFunc cfunc(cache_node); CHECK(master_op_.defined()); - // Filter PlaceholderOp from the outputs for schedule. + // Fusion over tupled results may leave identity relationships + // between inputs and outputs, and those should not be scheduled. + // Hence schedule only non PlaceholderOp outputs. tvm::Array tensor_outs; for (const auto& tensor : cache_node->outputs) { if (!tensor->op.as()) {