-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Executor interface design and implementation #4537
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
Changes from 29 commits
540cc2c
3481bdc
e42cafb
d4be973
b630d40
39b2ff3
0950091
ce4d14b
f1c5d9e
f29a6b0
b5dbe88
023ed5e
6e2f968
1a0d8fa
e946fc1
6c4d1f5
f5e73f4
0009a30
3950515
cb198fa
fe10e86
e02cc57
3014f6a
623848a
20725f2
45c4dca
48b080d
bbceb72
39f75a1
1f5192a
ac0e382
e8a678e
d73aa87
91f5d2b
f087533
a7d700e
683ef60
b68a95f
005f15b
a67e8ea
c83ea1c
6e7666f
c93d74a
089cc11
e515571
340d21d
e655d29
932402c
1540074
7d21d8c
0e1f21a
a17442d
e3161bb
2fc7fc7
975a512
a308ff2
3f9e247
293a7d1
062ff4d
2e7cd20
436ea50
a528a97
f410622
434949c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. */ | ||
|
|
||
| #include "paddle/framework/executor.h" | ||
| #include <iostream> | ||
| #include <memory> | ||
| #include <vector> | ||
| #include "paddle/framework/lod_tensor.h" | ||
| #include "paddle/framework/op_registry.h" | ||
| #include "paddle/framework/scope.h" | ||
|
|
||
| namespace paddle { | ||
| namespace framework { | ||
|
|
||
| Executor::Executor(const std::vector<platform::Place>& places) { | ||
| device_contexts_.resize(places.size()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enforce places.size() > 0 ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| for (size_t i = 0; i < places.size(); i++) { | ||
| if (platform::is_cpu_place(places[i])) { | ||
| device_contexts_[i] = new platform::CPUDeviceContext( | ||
| boost::get<platform::CPUPlace>(places[i])); | ||
| } else if (platform::is_gpu_place(places[i])) { | ||
| #ifdef PADDLE_WITH_GPU | ||
|
||
| device_contexts_[i] = new platform::CUDADeviceContext( | ||
| boost::get<platform::GPUPlace>(places[i])); | ||
| #else | ||
| PADDLE_THROW("'GPUPlace' is not supported in CPU only device."); | ||
|
||
| #endif | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Executor::~Executor() { | ||
| for (auto& device_context : device_contexts_) { | ||
| if (device_context) { | ||
|
||
| delete device_context; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void Executor::Run(const ProgramDesc& pdesc, Scope* scope) { | ||
| // TODO(tonyyang-svail): | ||
| // - only runs the first block | ||
| // - only runs on the first device | ||
| // - test on gpu | ||
| auto& block = pdesc.blocks(0); | ||
|
||
| auto& device = device_contexts_[0]; | ||
|
|
||
| // TODO(tonyyang-svail): | ||
| // - runs on a new local scope | ||
| // Scope& local_scope = scope->NewScope(); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only runs the first block for now, will change to use multiple blocks for RNN op and Cond Op There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| for (auto& var : block.vars()) { | ||
| scope->NewVar(var.name()); | ||
| } | ||
|
|
||
| for (auto& op_desc : block.ops()) { | ||
| auto op = paddle::framework::OpRegistry::CreateOp(op_desc); | ||
| std::cout << op->DebugString() << std::endl; | ||
| op->Run(*scope, *device); | ||
| } | ||
|
|
||
| // TODO(tonyyang-svail): need to test gpu device | ||
| for (auto& device_context : device_contexts_) { | ||
| device_context->Wait(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace framework | ||
| } // namespace paddle | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "paddle/framework/framework.pb.h" | ||
| #include "paddle/framework/op_info.h" | ||
| #include "paddle/framework/scope.h" | ||
| #include "paddle/framework/tensor.h" | ||
|
|
||
| namespace paddle { | ||
| namespace framework { | ||
|
|
||
| class Executor { | ||
| public: | ||
| explicit Executor(const std::vector<platform::Place>& places); | ||
| ~Executor(); | ||
| void Run(const ProgramDesc&, Scope*); | ||
|
|
||
| private: | ||
| std::vector<platform::DeviceContext*> device_contexts_; | ||
| }; | ||
|
|
||
| } // namespace framework | ||
| } // namespace paddle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we run
cc_test(executor_test SRCS executor_test.cc DEPS executor)as well when WITH_GPU is ON?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When WITH_GPU is ON, both cpu and gpu code will be tested.