[relay] Small refactor for context (#4091)
authorZhi <5145158+zhiics@users.noreply.github.com>
Wed, 9 Oct 2019 16:19:56 +0000 (09:19 -0700)
committerTianqi Chen <tqchen@users.noreply.github.com>
Wed, 9 Oct 2019 16:19:56 +0000 (09:19 -0700)
src/relay/backend/build_module.cc
src/relay/backend/vm/compiler.cc

index 20e760f..4cf13a3 100644 (file)
@@ -328,10 +328,9 @@ class RelayBuildModule : public runtime::ModuleNode {
     // Create a sequential pass and perform optimizations.
     transform::Pass seq = transform::Sequential(pass_seqs);
     if (targets.size() == 1) {
-      for (const auto& kv : targets) {
-        With<Target> tctx(kv.second);
-        relay_module = seq(relay_module);
-      }
+      const auto& it = targets.begin();
+      With<Target> tctx((*it).second);
+      relay_module = seq(relay_module);
     } else {
       relay_module = seq(relay_module);
     }
index 49079fb..013d8b0 100644 (file)
@@ -897,10 +897,9 @@ Module VMCompiler::OptimizeModule(const Module& mod, const TargetsMap& targets)
   // TODO(wweic): Support heterogenous execution
   tvm::With<relay::transform::PassContext> ctx(pass_ctx);
   if (targets.size() == 1) {
-    for (const auto& kv : targets) {
-      With<Target> tctx(kv.second);
-      return seq(mod);
-    }
+    const auto& it = targets.begin();
+    With<Target> tctx((*it).second);
+    return seq(mod);
   }
   return seq(mod);
 }