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

Replace ExecutionEngine with ExecutionEngine2 [NFC] #3388

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions examples/CMakeLists.txt
Expand Up @@ -3,7 +3,7 @@ add_executable(cifar10
target_link_libraries(cifar10
PRIVATE
Backends
ExecutionEngine2
ExecutionEngine
Graph
IR
Support
Expand All @@ -14,7 +14,7 @@ add_executable(mnist
target_link_libraries(mnist
PRIVATE
Backends
ExecutionEngine2
ExecutionEngine
Graph
Importer
IR
Expand All @@ -27,7 +27,7 @@ add_executable(ptb
target_link_libraries(ptb
PRIVATE
Backends
ExecutionEngine2
ExecutionEngine
Graph
IR
Support
Expand All @@ -38,7 +38,7 @@ add_executable(char-rnn
target_link_libraries(char-rnn
PRIVATE
Backends
ExecutionEngine2
ExecutionEngine
Graph
IR
GraphOptimizer
Expand All @@ -49,7 +49,7 @@ add_executable(fr2en
target_link_libraries(fr2en
PRIVATE
Base
ExecutionEngine2
ExecutionEngine
IR
GraphOptimizer
Quantization
Expand All @@ -60,7 +60,7 @@ add_executable(lenet-loader
lenet-loader.cpp)
target_link_libraries(lenet-loader
PRIVATE
ExecutionEngine2
ExecutionEngine
Graph
Importer
Support)
Expand All @@ -70,7 +70,7 @@ if(GLOW_WITH_CPU)
resnet-verify.cpp)
target_link_libraries(resnet-verify
PRIVATE
ExecutionEngine2
ExecutionEngine
Graph
Importer)

Expand All @@ -80,7 +80,7 @@ if(GLOW_WITH_CPU)
PRIVATE
Backends
ExecutionContext
ExecutionEngine2
ExecutionEngine
HostManager
Partitioner
Graph
Expand All @@ -93,7 +93,7 @@ if(GLOW_WITH_CPU)
PRIVATE
Backend
Backends
ExecutionEngine2
ExecutionEngine
Graph
Importer
GraphOptimizer)
Expand Down
13 changes: 6 additions & 7 deletions examples/char-rnn.cpp
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "glow/ExecutionEngine/ExecutionEngine2.h"
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/IR/IR.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"
Expand Down Expand Up @@ -220,8 +220,7 @@ int main(int argc, char **argv) {
CHECK_GT(text.size(), numSteps) << "Text is too short";
TrainingConfig TC;

// ExecutionEngine2 EEI(executionBackend);
ExecutionEngine2 EET(executionBackend);
ExecutionEngine EET(executionBackend);
TC.learningRate = 0.001;
TC.momentum = 0.9;
TC.batchSize = minibatchSize;
Expand Down Expand Up @@ -252,10 +251,10 @@ int main(int argc, char **argv) {

// Train the network on the whole input.
LOG(INFO) << "Iteration " << i + 1 << "/" << numEpochs;
runBatch2(EET, trainingBindings, batchSize / minibatchSize, sampleCounter,
{XT, YT}, {&thisCharTrain, &nextCharTrain});
runBatch(EET, trainingBindings, batchSize / minibatchSize, sampleCounter,
{XT, YT}, {&thisCharTrain, &nextCharTrain});

ExecutionEngine2 EEO(executionBackend);
ExecutionEngine EEO(executionBackend);
inferBindings.clear();
auto &mod = EEO.getModule();
auto OF =
Expand Down Expand Up @@ -285,7 +284,7 @@ int main(int argc, char **argv) {
// Generate a sentence by running inference over and over again.
for (unsigned i = 0; i < generateChars; i++) {
// Generate a char:
updateInputPlaceholders2(inferBindings, {X}, {&currCharInfer});
updateInputPlaceholders(inferBindings, {X}, {&currCharInfer});
EEO.run(inferBindings);

// Pick a char at random from the softmax distribution.
Expand Down
10 changes: 5 additions & 5 deletions examples/cifar10.cpp
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "glow/ExecutionEngine/ExecutionEngine2.h"
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/Support/Support.h"

Expand Down Expand Up @@ -157,7 +157,7 @@ void testCIFAR10() {
// Construct the network:
TrainingConfig TC;

ExecutionEngine2 EE(executionBackend);
ExecutionEngine EE(executionBackend);
PlaceholderBindings bindings;

TC.learningRate = 0.001;
Expand Down Expand Up @@ -206,15 +206,15 @@ void testCIFAR10() {

// Bind the images tensor to the input array A, and the labels tensor
// to the softmax node SM.
runBatch2(EE, bindings, reportRate, sampleCounter, {A, E},
{&images, &labels}, tfName);
runBatch(EE, bindings, reportRate, sampleCounter, {A, E},
{&images, &labels}, tfName);

unsigned score = 0;

for (unsigned int i = 0; i < 100 / minibatchSize; i++) {
Tensor sample(ElemKind::FloatTy, {minibatchSize, 32, 32, 3});
sample.copyConsecutiveSlices(&images, minibatchSize * i);
updateInputPlaceholders2(bindings, {A}, {&sample});
updateInputPlaceholders(bindings, {A}, {&sample});
EE.run(bindings);

for (unsigned int iter = 0; iter < minibatchSize; iter++) {
Expand Down
7 changes: 3 additions & 4 deletions examples/fr2en.cpp
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "glow/ExecutionEngine/ExecutionEngine2.h"
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"
#include "glow/Quantization/Quantization.h"
Expand Down Expand Up @@ -126,7 +126,7 @@ void loadMatrixFromFile(llvm::StringRef filename, Tensor &result) {
/// few references to input/output Variables.
struct Model {
unsigned batchSize_;
ExecutionEngine2 EE_{ExecutionBackend};
ExecutionEngine EE_{ExecutionBackend};
Function *F_;
Vocabulary en_, fr_;
Placeholder *input_;
Expand Down Expand Up @@ -376,8 +376,7 @@ void Model::translate(const std::vector<std::string> &batch) {
(words.size() - 1) + j * MAX_LENGTH;
}

updateInputPlaceholders2(bindings, {input_, seqLength_},
{&input, &seqLength});
updateInputPlaceholders(bindings, {input_, seqLength_}, {&input, &seqLength});
EE_.run(bindings);

auto OH = bindings.get(output_)->getHandle<int64_t>();
Expand Down
6 changes: 3 additions & 3 deletions examples/lenet-loader.cpp
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "glow/Base/Image.h"
#include "glow/ExecutionEngine/ExecutionEngine2.h"
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Importer/Caffe2ModelLoader.h"
#include "glow/Support/Error.h"

Expand All @@ -24,7 +24,7 @@ using namespace glow;
/// inference.
int main() {
glow::PlaceholderBindings bindings;
glow::ExecutionEngine2 EE;
glow::ExecutionEngine EE;
auto &mod = EE.getModule();
auto *F = mod.createFunction("lenet_mnist");
auto *inputType = mod.uniqueType(glow::ElemKind::FloatTy, {1, 1, 28, 28});
Expand All @@ -50,7 +50,7 @@ int main() {

// Allocate memory for input and bind it to the placeholders.
bindings.allocate(mod.getPlaceholders());
glow::updateInputPlaceholders2(bindings, {input}, {&batch});
glow::updateInputPlaceholders(bindings, {input}, {&batch});

// Perform inference.
EE.run(bindings);
Expand Down
22 changes: 11 additions & 11 deletions examples/mnist.cpp
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "glow/Base/Image.h"
#include "glow/ExecutionEngine/ExecutionEngine2.h"
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/Importer/Caffe2ModelLoader.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"
Expand Down Expand Up @@ -82,7 +82,7 @@ unsigned loadMNIST(Tensor &imageInputs, Tensor &labelInputs) {
return numImages;
}

void createModel(ExecutionEngine2 &EE, Function *F,
void createModel(ExecutionEngine &EE, Function *F,
PlaceholderBindings &bindings, unsigned minibatchSize,
Placeholder *&inputPH, Placeholder *&outputPH,
Placeholder *&selectedPH) {
Expand All @@ -107,8 +107,8 @@ void createModel(ExecutionEngine2 &EE, Function *F,
outputPH = result->getPlaceholder();
}

void trainModel(ExecutionEngine2 &EE, PlaceholderBindings &bindings,
Function *F, unsigned minibatchSize, unsigned numIterations,
void trainModel(ExecutionEngine &EE, PlaceholderBindings &bindings, Function *F,
unsigned minibatchSize, unsigned numIterations,
Tensor &imageInputs, Tensor &labelInputs, Placeholder *inputPH,
Placeholder *selectedPH) {
llvm::Timer timer("Training", "Training");
Expand Down Expand Up @@ -141,14 +141,14 @@ void trainModel(ExecutionEngine2 &EE, PlaceholderBindings &bindings,
// On each training iteration take a slice of imageInputs and labelInputs
// and put them into variables A and B, then run forward and backward passes
// and update weights.
runBatch2(EE, bindings, numIterations, sampleCounter, {inputPH, selectedPH},
{&imageInputs, &labelInputs}, tfName);
runBatch(EE, bindings, numIterations, sampleCounter, {inputPH, selectedPH},
{&imageInputs, &labelInputs}, tfName);

timer.stopTimer();
}
}

void validateModel(ExecutionEngine2 &EE, PlaceholderBindings &bindings,
void validateModel(ExecutionEngine &EE, PlaceholderBindings &bindings,
Function *F, unsigned minibatchSize, unsigned numIterations,
Tensor &imageInputs, Tensor &labelInputs,
Placeholder *inputPH, Placeholder *outputPH,
Expand Down Expand Up @@ -215,13 +215,13 @@ void testMNIST() {
PlaceholderBindings trainingBindings, inferBindings;
Placeholder *A, *E, *selected;

ExecutionEngine2 EEI_(executionBackend);
ExecutionEngine EEI_(executionBackend);
auto &inferMod = EEI_.getModule();
Function *F = inferMod.createFunction("mnist");
createModel(EEI_, F, inferBindings, minibatchSize, A, E, selected);
inferBindings.allocate(inferMod.getPlaceholders());

ExecutionEngine2 EET_(executionBackend);
ExecutionEngine EET_(executionBackend);
auto &trainMod = EET_.getModule();
Function *TF = trainMod.createFunction("mnist");
createModel(EET_, TF, trainingBindings, minibatchSize, A, E, selected);
Expand All @@ -247,7 +247,7 @@ void testMNISTLoadAndTraining() {
imageInputsTransposed.transpose(&imageInputs, NHWC2NCHW);

PlaceholderBindings trainingBindings, inferBindings;
ExecutionEngine2 EEI_(executionBackend);
ExecutionEngine EEI_(executionBackend);
auto &inferMod = EEI_.getModule();
auto *F = inferMod.createFunction("lenet_mnist");
unsigned minibatchSize = 8;
Expand Down Expand Up @@ -280,7 +280,7 @@ void testMNISTLoadAndTraining() {

// Load the model a second time for training.
// TODO: remove once EE2 is able to compile in different modes.
ExecutionEngine2 EET_(executionBackend);
ExecutionEngine EET_(executionBackend);
auto &trainMod = EET_.getModule();
auto *TF = trainMod.createFunction("lenet_mnist_train");
glow::Caffe2ModelLoader trainingLoader("lenet_mnist/predict_net.pb",
Expand Down
8 changes: 4 additions & 4 deletions examples/ptb.cpp
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "glow/ExecutionEngine/ExecutionEngine2.h"
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/IR/IR.h"
#include "glow/Support/Support.h"
Expand Down Expand Up @@ -182,7 +182,7 @@ void testPTB() {
unsigned numWords = loadPTB(inputWords, targetWords, numSteps, vocabSize,
minibatchSize, maxNumWords);
LOG(INFO) << "Loaded " << numWords << " words.";
ExecutionEngine2 EE(executionBackend);
ExecutionEngine EE(executionBackend);
PlaceholderBindings bindings;

// Construct the network:
Expand Down Expand Up @@ -270,8 +270,8 @@ void testPTB() {
targetWordsBatch.copyConsecutiveSlices(&targetWords,
minibatchSize * batch);

runBatch2(EE, bindings, 1, sampleCounter, {X, Y},
{&inputWordsBatch, &targetWordsBatch}, tfName);
runBatch(EE, bindings, 1, sampleCounter, {X, Y},
{&inputWordsBatch, &targetWordsBatch}, tfName);
for (size_t step = 0; step < numSteps; step++) {
for (unsigned int i = 0; i < minibatchSize; i++) {
auto T =
Expand Down
6 changes: 3 additions & 3 deletions examples/resnet-runtime.cpp
Expand Up @@ -15,7 +15,7 @@
*/

#include "glow/Base/Image.h"
#include "glow/ExecutionEngine/ExecutionEngine2.h"
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/Importer/Caffe2ModelLoader.h"
#include "glow/Runtime/HostManager/HostManager.h"
Expand Down Expand Up @@ -200,8 +200,8 @@ int main(int argc, char **argv) {

context->getPlaceholderBindings()->allocate(phList);
Tensor batch = image.getUnowned(inputShape);
updateInputPlaceholders2(*(context->getPlaceholderBindings()), {input},
{&batch});
updateInputPlaceholders(*(context->getPlaceholderBindings()), {input},
{&batch});

dispatchClassify(0, hostManager.get(), std::move(path), std::move(context),
returned, finished);
Expand Down
6 changes: 3 additions & 3 deletions examples/resnet-verify.cpp
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "glow/Base/Image.h"
#include "glow/ExecutionEngine/ExecutionEngine2.h"
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Hook.h"
#include "glow/Importer/Caffe2ModelLoader.h"

Expand All @@ -27,7 +27,7 @@ const char inputName[] = "gpu_0/data";

class Tester {
PlaceholderBindings bindings, inferBindings;
ExecutionEngine2 EEI;
ExecutionEngine EEI;
std::unique_ptr<Module> mod;
Function *F;
TypeRef inputType;
Expand All @@ -49,7 +49,7 @@ class Tester {
void bindInput(Tensor *batch) {
// Allocate memory for input and bind it to the placeholders.
bindings.allocate(mod->getPlaceholders());
updateInputPlaceholders2(bindings, {input}, {batch});
updateInputPlaceholders(bindings, {input}, {batch});
}

TypeRef getInputType() const { return inputType; }
Expand Down
6 changes: 3 additions & 3 deletions examples/tracing-compare.cpp
Expand Up @@ -16,7 +16,7 @@

#include "glow/Backends/DeviceManager.h"
#include "glow/Base/Image.h"
#include "glow/ExecutionEngine/ExecutionEngine2.h"
#include "glow/ExecutionEngine/ExecutionEngine.h"
#include "glow/Graph/Graph.h"
#include "glow/Importer/Caffe2ModelLoader.h"
#include "glow/Optimizer/GraphOptimizer/GraphOptimizer.h"
Expand Down Expand Up @@ -152,8 +152,8 @@ int main(int argc, char **argv) {
context->setTraceContext(
llvm::make_unique<TraceContext>(TraceLevel::STANDARD));
context->getPlaceholderBindings()->allocate(module.getPlaceholders());
updateInputPlaceholders2(*(context->getPlaceholderBindings()), {input},
{&batch});
updateInputPlaceholders(*(context->getPlaceholderBindings()), {input},
{&batch});

devices[i]->runFunction(
"resnet50", std::move(context),
Expand Down