Skip to content

Commit e1a46bb

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into some_small_fixes
2 parents bc9d19c + 6d6996a commit e1a46bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+986
-277
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ RUN easy_install -U pip && \
7676
pip install sphinx-rtd-theme==0.1.9 recommonmark
7777

7878
RUN pip install pre-commit 'ipython==5.3.0' && \
79-
pip install 'ipykernel==4.6.0' 'jupyter==1.0.0'
79+
pip install 'ipykernel==4.6.0' 'jupyter==1.0.0' && \
80+
pip install opencv-python
8081

8182
#For docstring checker
8283
RUN pip install pylint pytest astroid isort

cmake/external/mkldnn.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ExternalProject_Add(
5454
${EXTERNAL_PROJECT_LOG_ARGS}
5555
DEPENDS ${MKLDNN_DEPENDS}
5656
GIT_REPOSITORY "https://github.com/01org/mkl-dnn.git"
57-
GIT_TAG "db3424ad44901513c03a1ea31ccaacdf633fbe9f"
57+
GIT_TAG "a29d8487a63afca3d5b8c5bbdbb473cf8ccc6e51"
5858
PREFIX ${MKLDNN_SOURCES_DIR}
5959
UPDATE_COMMAND ""
6060
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${MKLDNN_INSTALL_DIR}

doc/v2/faq/build_and_install/index_cn.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,12 @@ virtualenv本身也是Python的一个包,可以用pip进行安装:
213213
保存并关闭文件。
214214

215215
这样,每次打开终端时就会自动启动名为‘paddle’的Python环境了。
216+
217+
10. 通过pip安装的PaddlePaddle在 :code:`import paddle.fluid` 报找不到 :code:`libmkldnn.so` 或 :code:`libmklml_intel.so`
218+
------------------------------------------------------------------------------------------
219+
出现这种问题的原因是在导入 :code:`paddle.fluid` 时需要加载 :code:`libmkldnn.so` 和 :code:`libmklml_intel.so`,
220+
但是系统没有找到该文件。一般通过pip安装PaddlePaddle时会将 :code:`libmkldnn.so` 和 :code:`libmklml_intel.so`
221+
拷贝到 :code:`/usr/local/lib` 路径下,所以解决办法是将该路径加到 :code:`LD_LIBRARY_PATH` 环境变量下,
222+
即: :code:`export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH` 。
223+
224+
**注意**:如果是在虚拟环境中安装PaddlePaddle, :code:`libmkldnn.so` 和 :code:`libmklml_intel.so` 可能不在 :code:`/usr/local/lib` 路径下。

paddle/fluid/framework/details/broadcast_op_handle.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ void BroadcastOpHandle::RunImpl() {
7373
int root_id = boost::get<platform::CUDAPlace>(in_tensor.place()).device;
7474
std::vector<std::function<void()>> broadcast_calls;
7575

76+
int type = platform::ToNCCLDataType(in_tensor.type());
77+
size_t numel = static_cast<size_t>(in_tensor.numel());
78+
7679
for (auto out_var_handle : out_var_handles) {
7780
Variable *out_var = var_scopes.at(out_var_handle->scope_idx_)
7881
->FindVar(out_var_handle->name_);
@@ -87,13 +90,11 @@ void BroadcastOpHandle::RunImpl() {
8790
send_recv_buffer = const_cast<void *>(in_tensor.data<void>());
8891
out_handle = out_var_handle;
8992
} else {
90-
send_recv_buffer =
91-
VariableVisitor::GetMutableTensor(out_var).mutable_data(
92-
out_var_handle->place_);
93+
send_recv_buffer = VariableVisitor::GetMutableTensor(out_var)
94+
.Resize(in_tensor.dims())
95+
.mutable_data(out_var_handle->place_);
9396
}
9497

95-
int type = platform::ToNCCLDataType(in_tensor.type());
96-
size_t numel = static_cast<size_t>(in_tensor.numel());
9798
broadcast_calls.emplace_back(
9899
[send_recv_buffer, numel, type, root_id, &nccl_ctx] {
99100
PADDLE_ENFORCE(platform::dynload::ncclBcast(

paddle/fluid/framework/details/multi_devices_graph_builder.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void MultiDevSSAGraphBuilder::InsertAllReduceOp(SSAGraph *result,
351351
auto &prev_grad = vars.back();
352352
op_handle->AddInput(prev_grad.get());
353353

354-
auto var = new VarHandle(vars.size() - 1, i, og, p);
354+
auto var = new VarHandle(vars.size(), i, og, p);
355355
vars.emplace_back(var);
356356
op_handle->AddOutput(var);
357357
}
@@ -447,8 +447,7 @@ VarHandle *MultiDevSSAGraphBuilder::CreateReduceOp(SSAGraph *result,
447447
op_handle->AddInput(prev_grad.get());
448448
}
449449
auto &vars = result->vars_[dst_dev_id][og];
450-
auto var =
451-
new VarHandle(vars.size() - 1, dst_dev_id, og, places_[dst_dev_id]);
450+
auto var = new VarHandle(vars.size(), dst_dev_id, og, places_[dst_dev_id]);
452451
vars.emplace_back(var);
453452
op_handle->AddOutput(var);
454453
return var;

paddle/fluid/framework/details/multi_devices_graph_builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
4747
#endif
4848

4949
std::unique_ptr<SSAGraph> Build(const ProgramDesc &program) const override;
50-
int GetVarDeviceID(const std::string &varname) const;
50+
int GetVarDeviceID(const std::string &varname) const override;
5151

5252
private:
5353
void CreateOpHandleIOs(SSAGraph *result, const OpDesc &op,

paddle/fluid/framework/details/op_handle_base.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
1514
#include "paddle/fluid/framework/details/op_handle_base.h"
15+
#include <map>
1616

1717
namespace paddle {
1818
namespace framework {
@@ -122,11 +122,16 @@ void OpHandleBase::RunAndRecordEvent(const std::function<void()> &callback) {
122122
#ifdef PADDLE_WITH_CUDA
123123
if (!events_.empty()) { // Use event
124124
std::function<void()> method = callback;
125-
125+
// NOTE(zcd): device context must be ordered here because RecordEvent
126+
// will use a mutex to ensure the safe of multi-threads.
127+
std::map<platform::DeviceContext *, platform::Place> ordered_ctxes;
126128
for (auto &p : dev_ctxes_) {
129+
ordered_ctxes.emplace(p.second, p.first);
130+
}
131+
for (auto &p : ordered_ctxes) {
127132
method = [method, p, this]() {
128-
static_cast<platform::CUDADeviceContext *>(p.second)->RecordEvent(
129-
events_.at(boost::get<platform::CUDAPlace>(p.first).device),
133+
static_cast<platform::CUDADeviceContext *>(p.first)->RecordEvent(
134+
events_.at(boost::get<platform::CUDAPlace>(p.second).device),
130135
method);
131136
};
132137
}

paddle/fluid/framework/framework.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum AttrType {
2727
BOOLEANS = 7;
2828
BLOCK = 8;
2929
LONG = 9;
30+
BLOCKS = 10;
3031
}
3132

3233
// OpDesc describes an instance of a C++ framework::OperatorBase
@@ -46,6 +47,7 @@ message OpDesc {
4647
repeated bool bools = 11;
4748
optional int32 block_idx = 12;
4849
optional int64 l = 13;
50+
repeated int32 blocks_idx = 14;
4951
};
5052

5153
message Var {

paddle/fluid/framework/lod_tensor.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ std::ostream &operator<<(std::ostream &os, const LoD &lod) {
5151
}
5252

5353
std::ostream &operator<<(std::ostream &os, const LoDTensor &t) {
54-
PADDLE_ENFORCE(t.type().hash_code() == typeid(float).hash_code());
55-
5654
if (!platform::is_cpu_place(t.place())) {
5755
LoDTensor tt;
5856
framework::TensorCopy(t, platform::CPUPlace(), &tt);
@@ -70,7 +68,13 @@ std::ostream &operator<<(std::ostream &os, const LoDTensor &t) {
7068
// only print first ten elements
7169
int64_t size = t.numel() < 10 ? t.numel() : 10;
7270
for (int64_t i = 0; i < size; ++i) {
73-
os << t.data<float>()[i] << " ";
71+
if (t.type().hash_code() == typeid(float).hash_code()) {
72+
os << t.data<float>()[i] << " ";
73+
} else if (t.type().hash_code() == typeid(int64_t).hash_code()) {
74+
os << t.data<int64_t>()[i] << " ";
75+
} else {
76+
PADDLE_THROW("LoDTensor data type not in [float, int64_t]");
77+
}
7478
}
7579

7680
return os;

paddle/fluid/framework/lod_tensor_test.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
namespace paddle {
2727
namespace framework {
2828

29+
TEST(LoD, PrintLoDTensor) {
30+
LoDTensor tensor1;
31+
tensor1.mutable_data<float>(platform::CPUPlace());
32+
tensor1.data<float>()[0] = 0.2;
33+
tensor1.data<float>()[1] = 0.5;
34+
LOG(INFO) << tensor1;
35+
36+
LoDTensor tensor2;
37+
tensor2.mutable_data<int64_t>(platform::CPUPlace());
38+
tensor2.data<int64_t>()[0] = 1;
39+
tensor2.data<int64_t>()[1] = 2;
40+
LOG(INFO) << tensor2;
41+
}
42+
2943
TEST(LoD, data) {
3044
LoD lod{{0, 1, 2}};
3145
lod.push_back({0, 2, 4, 5});
@@ -37,7 +51,7 @@ TEST(LoD, data) {
3751
}
3852
}
3953

40-
TEST(LodExpand, test) {
54+
TEST(LoD, ExpandLoD) {
4155
LoD lod{{0, 2}};
4256
LoDTensor tensor;
4357
tensor.set_lod(lod);

0 commit comments

Comments
 (0)