From 74bb0c6b3c8005d123c181821d5c0e52a30bb2b6 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Wed, 1 Nov 2017 14:04:06 -0700 Subject: [PATCH 1/2] Migrate the Interpreter into the new backends directory. --- include/glow/{ => Backends}/Interpreter/Interpreter.h | 0 src/glow/Backends/CMakeLists.txt | 3 +++ src/glow/{ => Backends}/Interpreter/CMakeLists.txt | 0 src/glow/{ => Backends}/Interpreter/Interpreter.cpp | 2 +- src/glow/{ => Backends}/Interpreter/InterpreterNodes.cpp | 2 +- src/glow/CMakeLists.txt | 2 +- src/glow/ExecutionEngine/ExecutionEngine.cpp | 2 +- 7 files changed, 7 insertions(+), 4 deletions(-) rename include/glow/{ => Backends}/Interpreter/Interpreter.h (100%) create mode 100644 src/glow/Backends/CMakeLists.txt rename src/glow/{ => Backends}/Interpreter/CMakeLists.txt (100%) rename src/glow/{ => Backends}/Interpreter/Interpreter.cpp (98%) rename src/glow/{ => Backends}/Interpreter/InterpreterNodes.cpp (99%) diff --git a/include/glow/Interpreter/Interpreter.h b/include/glow/Backends/Interpreter/Interpreter.h similarity index 100% rename from include/glow/Interpreter/Interpreter.h rename to include/glow/Backends/Interpreter/Interpreter.h diff --git a/src/glow/Backends/CMakeLists.txt b/src/glow/Backends/CMakeLists.txt new file mode 100644 index 0000000000..de07b3b079 --- /dev/null +++ b/src/glow/Backends/CMakeLists.txt @@ -0,0 +1,3 @@ + +add_subdirectory(Interpreter) + diff --git a/src/glow/Interpreter/CMakeLists.txt b/src/glow/Backends/Interpreter/CMakeLists.txt similarity index 100% rename from src/glow/Interpreter/CMakeLists.txt rename to src/glow/Backends/Interpreter/CMakeLists.txt diff --git a/src/glow/Interpreter/Interpreter.cpp b/src/glow/Backends/Interpreter/Interpreter.cpp similarity index 98% rename from src/glow/Interpreter/Interpreter.cpp rename to src/glow/Backends/Interpreter/Interpreter.cpp index d025673a74..087e458947 100644 --- a/src/glow/Interpreter/Interpreter.cpp +++ b/src/glow/Backends/Interpreter/Interpreter.cpp @@ -1,6 +1,6 @@ // Copyright 2017 Facebook Inc. All Rights Reserved. -#include "glow/Interpreter/Interpreter.h" +#include "glow/Backends/Interpreter/Interpreter.h" #include "glow/Graph/Graph.h" #include "glow/Graph/Nodes.h" #include "glow/IR/Instrs.h" diff --git a/src/glow/Interpreter/InterpreterNodes.cpp b/src/glow/Backends/Interpreter/InterpreterNodes.cpp similarity index 99% rename from src/glow/Interpreter/InterpreterNodes.cpp rename to src/glow/Backends/Interpreter/InterpreterNodes.cpp index ffecdb3784..2634ead96e 100644 --- a/src/glow/Interpreter/InterpreterNodes.cpp +++ b/src/glow/Backends/Interpreter/InterpreterNodes.cpp @@ -1,7 +1,7 @@ // Copyright 2017 Facebook Inc. All Rights Reserved. +#include "glow/Backends/Interpreter/Interpreter.h" #include "glow/IR/Instrs.h" -#include "glow/Interpreter/Interpreter.h" #include "llvm/Support/Casting.h" diff --git a/src/glow/CMakeLists.txt b/src/glow/CMakeLists.txt index 76c7b516e3..8da92e3bb0 100644 --- a/src/glow/CMakeLists.txt +++ b/src/glow/CMakeLists.txt @@ -1,10 +1,10 @@ +add_subdirectory(Backends) add_subdirectory(Base) add_subdirectory(ExecutionEngine) add_subdirectory(Graph) add_subdirectory(IR) add_subdirectory(Importer) -add_subdirectory(Interpreter) add_subdirectory(Optimizer) add_subdirectory(Support) diff --git a/src/glow/ExecutionEngine/ExecutionEngine.cpp b/src/glow/ExecutionEngine/ExecutionEngine.cpp index 5deebaed4c..778e4f7887 100644 --- a/src/glow/ExecutionEngine/ExecutionEngine.cpp +++ b/src/glow/ExecutionEngine/ExecutionEngine.cpp @@ -2,11 +2,11 @@ #include "glow/ExecutionEngine/ExecutionEngine.h" +#include "glow/Backends/Interpreter/Interpreter.h" #include "glow/Graph/Graph.h" #include "glow/IR/IR.h" #include "glow/IR/IRBuilder.h" #include "glow/IR/Instrs.h" -#include "glow/Interpreter/Interpreter.h" #include "glow/Optimizer/Optimizer.h" using namespace glow; From d0bb3ab655eb57820e2f9f9593c144f3e49449ff Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Wed, 1 Nov 2017 14:26:23 -0700 Subject: [PATCH 2/2] Backends: allow the execution engine to select the backend in the constructor. --- include/glow/ExecutionEngine/ExecutionEngine.h | 7 ++++++- src/glow/ExecutionEngine/ExecutionEngine.cpp | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/glow/ExecutionEngine/ExecutionEngine.h b/include/glow/ExecutionEngine/ExecutionEngine.h index 5897764426..9e718cf5ce 100644 --- a/include/glow/ExecutionEngine/ExecutionEngine.h +++ b/include/glow/ExecutionEngine/ExecutionEngine.h @@ -19,6 +19,11 @@ class Variable; class Tensor; class Value; +enum class ExecutorKind { + Interpreter, // Execute the network with the built-in interpreter. + None, +}; + /// This is the ExecutionEngine. It owns the Graph, the IR, and the backends. /// The Graph, Module, etc in this class are defined as pointers, in order to /// erase the type and prevent the internal types from leaking out to the @@ -34,7 +39,7 @@ class ExecutionEngine final { Trainer trainer_{}; public: - ExecutionEngine(); + ExecutionEngine(ExecutorKind execKind = ExecutorKind::Interpreter); ~ExecutionEngine(); diff --git a/src/glow/ExecutionEngine/ExecutionEngine.cpp b/src/glow/ExecutionEngine/ExecutionEngine.cpp index 778e4f7887..7350702160 100644 --- a/src/glow/ExecutionEngine/ExecutionEngine.cpp +++ b/src/glow/ExecutionEngine/ExecutionEngine.cpp @@ -11,10 +11,20 @@ using namespace glow; -ExecutionEngine::ExecutionEngine() { +ExecutionEngine::ExecutionEngine(ExecutorKind execKind) { G_ = std::unique_ptr(new Graph()); M_ = std::unique_ptr(new Module(&*G_)); - IP_ = std::unique_ptr(new Interpreter(&*M_)); + + switch (execKind) { + case ExecutorKind::Interpreter: + IP_ = std::unique_ptr(new Interpreter(&*M_)); + break; + + default: + // Unknown execution backend. + glow_unreachable(); + break; + } } ExecutionEngine::~ExecutionEngine() = default;