Skip to content

Commit 49a04d7

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into dev_data_balance
2 parents 4b95095 + d2ad4a5 commit 49a04d7

31 files changed

+320
-118
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![Build Status](https://travis-ci.org/PaddlePaddle/Paddle.svg?branch=develop)](https://travis-ci.org/PaddlePaddle/Paddle)
55
[![Documentation Status](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](http://www.paddlepaddle.org/docs/develop/documentation/en/getstarted/index_en.html)
66
[![Documentation Status](https://img.shields.io/badge/中文文档-最新-brightgreen.svg)](http://www.paddlepaddle.org/docs/develop/documentation/zh/getstarted/index_cn.html)
7-
[![Coverage Status](https://coveralls.io/repos/github/PaddlePaddle/Paddle/badge.svg?branch=develop)](https://coveralls.io/github/PaddlePaddle/Paddle?branch=develop)
87
[![Release](https://img.shields.io/github/release/PaddlePaddle/Paddle.svg)](https://github.com/PaddlePaddle/Paddle/releases)
98
[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](LICENSE)
109

cmake/generic.cmake

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ if(NOT APPLE AND NOT ANDROID)
9696
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -pthread -ldl -lrt")
9797
endif(NOT APPLE AND NOT ANDROID)
9898

99+
set_property(GLOBAL PROPERTY FLUID_MODULES "")
100+
# find all fluid modules is used for paddle fluid static library
101+
# for building inference libs
102+
function(find_fluid_modules TARGET_NAME)
103+
get_filename_component(__target_path ${TARGET_NAME} ABSOLUTE)
104+
string(REGEX REPLACE "^${PADDLE_SOURCE_DIR}/" "" __target_path ${__target_path})
105+
string(FIND "${__target_path}" "fluid" pos)
106+
if(pos GREATER 1)
107+
get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES)
108+
set(fluid_modules ${fluid_modules} ${TARGET_NAME})
109+
set_property(GLOBAL PROPERTY FLUID_MODULES "${fluid_modules}")
110+
endif()
111+
endfunction(find_fluid_modules)
112+
99113
function(merge_static_libs TARGET_NAME)
100114
set(libs ${ARGN})
101115
list(REMOVE_DUPLICATES libs)
@@ -250,6 +264,7 @@ function(cc_test TARGET_NAME)
250264
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
251265
if (${cc_test_SERIAL})
252266
set_property(TEST ${TARGET_NAME} PROPERTY SERIAL 1)
267+
set_property(TEST ${TARGET_NAME} PROPERTY ENVIRONMENT FLAGS_init_allocated_mem=true)
253268
endif()
254269
endif()
255270
endfunction(cc_test)
@@ -314,6 +329,7 @@ function(nv_test TARGET_NAME)
314329
add_test(${TARGET_NAME} ${TARGET_NAME})
315330
if (nv_test_SERIAL)
316331
set_property(TEST ${TARGET_NAME} PROPERTY SERIAL 1)
332+
set_property(TEST ${TARGET_NAME} PROPERTY ENVIRONMENT FLAGS_init_allocated_mem=true)
317333
endif()
318334
endif()
319335
endfunction(nv_test)
@@ -561,7 +577,7 @@ function(py_test TARGET_NAME)
561577
set(multiValueArgs SRCS DEPS ARGS ENVS)
562578
cmake_parse_arguments(py_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
563579
add_test(NAME ${TARGET_NAME}
564-
COMMAND env PYTHONPATH=${PADDLE_BINARY_DIR}/python ${py_test_ENVS}
580+
COMMAND env FLAGS_init_allocated_mem=true PYTHONPATH=${PADDLE_BINARY_DIR}/python ${py_test_ENVS}
565581
${PYTHON_EXECUTABLE} -u ${py_test_SRCS} ${py_test_ARGS}
566582
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
567583
endif()

cmake/inference_lib.cmake

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
set_property(GLOBAL PROPERTY FLUID_MODULES "")
16-
# find all fluid modules is used for paddle fluid static library
17-
function(find_fluid_modules TARGET_NAME)
18-
get_filename_component(__target_path ${TARGET_NAME} ABSOLUTE)
19-
string(REGEX REPLACE "^${PADDLE_SOURCE_DIR}/" "" __target_path ${__target_path})
20-
string(FIND "${__target_path}" "fluid" pos)
21-
if(pos GREATER 1)
22-
get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES)
23-
set(fluid_modules ${fluid_modules} ${TARGET_NAME})
24-
set_property(GLOBAL PROPERTY FLUID_MODULES "${fluid_modules}")
25-
endif()
26-
endfunction(find_fluid_modules)
27-
2815
# make package for paddle fluid shared and static library
2916
function(copy TARGET)
3017
set(options "")
@@ -163,9 +150,9 @@ if(WITH_CONTRIB)
163150
list(APPEND inference_deps contrib_anakin_inference_lib)
164151
endif()
165152

166-
copy(contrib_inference_lib DEPS paddle_inference_api
153+
copy(contrib_inference_lib DEPS paddle_inference_api paddle_inference_api_shared
167154
SRCS ${PADDLE_SOURCE_DIR}/paddle/contrib/inference/paddle_inference_api.h
168-
${PADDLE_BINARY_DIR}/paddle/contrib/inference/libpaddle_inference_api.*
155+
${PADDLE_BINARY_DIR}/paddle/contrib/inference/libpaddle_inference_api*
169156
DSTS ${contrib_dst_dir} ${contrib_dst_dir})
170157
list(APPEND inference_deps contrib_inference_lib)
171158
endif()

doc/fluid/design/multi_devices/kernel_selection.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ void OperatorWithKernel::Run(
7474
auto kernel_type_for_var = this->GetKernelTypeForVar(...);
7575
if (kernel_type_for_var.place_ != expected_kernel_key.place_) {
7676
auto* trans_var = new_scope.Var(var_name);
77-
auto* out = DataTransform(expected_kernel_key,
77+
auto* out = TransformData(expected_kernel_key,
7878
kernel_type_for_var,
7979
*tensor_in);
80-
CopyVariableWithTensor(...);
80+
SetTensorToVariable(...);
8181
}
8282
}
8383

paddle/contrib/inference/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ cc_library(paddle_inference_api
4646
SRCS paddle_inference_api.cc paddle_inference_api_impl.cc
4747
DEPS ${FLUID_CORE_MODULES} ${GLOB_OP_LIB})
4848

49+
cc_library(paddle_inference_api_shared SHARED
50+
SRCS paddle_inference_api.cc paddle_inference_api_impl.cc
51+
DEPS ${FLUID_CORE_MODULES} ${GLOB_OP_LIB})
52+
4953
cc_test(test_paddle_inference_api
5054
SRCS test_paddle_inference_api.cc
5155
DEPS paddle_inference_api)

paddle/fluid/framework/data_layout_transform.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ void TransDataLayoutFromMKLDNN(const OpKernelType& kernel_type_for_var,
147147
"Input tensor type is not supported: ", in.type().name());
148148
memory::data_type out_type = in_type;
149149

150-
auto in_format = MKLDNNFormatForSize(in_tz.size(), in.format());
150+
auto in_format = platform::MKLDNNFormatForSize(in_tz.size(), in.format());
151151
auto out_format =
152-
MKLDNNFormatForSize(in_tz.size(), ToMKLDNNFormat(out_layout));
152+
platform::MKLDNNFormatForSize(in_tz.size(), ToMKLDNNFormat(out_layout));
153153

154154
void* in_data = GetDataFromTensor(in, in_type);
155155

paddle/fluid/framework/data_layout_transform.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ inline MKLDNNDataType ToMKLDNNDataType(const std::type_index type) {
6262
return MKLDNNDataType::data_undef;
6363
}
6464

65-
inline MKLDNNFormat MKLDNNFormatForSize(size_t dims_size,
66-
MKLDNNFormat default_format) {
67-
return (dims_size == 1
68-
? mkldnn::memory::format::x
69-
: dims_size == 2 ? mkldnn::memory::format::nc : default_format);
70-
}
7165
#endif
7266

7367
void TransDataLayoutFromMKLDNN(const OpKernelType& kernel_type_for_var,

paddle/fluid/framework/data_transform.cc

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@ limitations under the License. */
1818
#include "paddle/fluid/framework/data_layout_transform.h"
1919
#include "paddle/fluid/framework/data_type_transform.h"
2020

21+
#ifdef PADDLE_WITH_MKLDNN
22+
#include "paddle/fluid/platform/mkldnn_helper.h"
23+
#endif
24+
2125
namespace paddle {
2226
namespace framework {
2327

24-
static void PassTensorData(Tensor* from, Tensor* to) {
28+
static void PassTensorData(Tensor *from, Tensor *to) {
2529
to->ShareDataWith(*from);
2630
*from = Tensor();
2731
}
2832

29-
void DataTransform(const OpKernelType& expected_kernel_type,
30-
const OpKernelType& kernel_type_for_var,
31-
const Tensor& input_tensor, Tensor* output_tensor) {
33+
void TransformData(const OpKernelType &expected_kernel_type,
34+
const OpKernelType &kernel_type_for_var,
35+
const Tensor &input_tensor, Tensor *output_tensor) {
3236
bool transformed = false;
3337
Tensor in;
3438
in.ShareDataWith(input_tensor);
@@ -48,8 +52,8 @@ void DataTransform(const OpKernelType& expected_kernel_type,
4852
// Case1 - transform from Non-MKLDNN OPKernel to MKLDNN OPKernel
4953
// Just set layout/format. No real transform occur
5054

51-
auto out_format =
52-
MKLDNNFormatForSize(in.dims().size(), ToMKLDNNFormat(lin));
55+
auto out_format = platform::MKLDNNFormatForSize(in.dims().size(),
56+
ToMKLDNNFormat(lin));
5357

5458
out.ShareDataWith(input_tensor);
5559
out.set_layout(DataLayout::kMKLDNN);
@@ -89,17 +93,17 @@ void DataTransform(const OpKernelType& expected_kernel_type,
8993
output_tensor->ShareDataWith(in);
9094
}
9195

92-
void CopyVariableWithTensor(const Variable& in_var, const Tensor& tensor,
93-
Variable* out_var) {
96+
void SetTensorToVariable(const Variable &in_var, const Tensor &tensor,
97+
Variable *out_var) {
9498
if (in_var.IsType<LoDTensor>()) {
95-
auto& in_lod_tensor = in_var.Get<LoDTensor>();
96-
auto* tran_lod_tensor = out_var->GetMutable<LoDTensor>();
99+
auto &in_lod_tensor = in_var.Get<LoDTensor>();
100+
auto *tran_lod_tensor = out_var->GetMutable<LoDTensor>();
97101
tran_lod_tensor->set_lod(in_lod_tensor.lod());
98102
tran_lod_tensor->set_layout(in_lod_tensor.layout());
99103
tran_lod_tensor->ShareDataWith(tensor);
100104
} else if (in_var.IsType<SelectedRows>()) {
101-
auto& in_selected_rows = in_var.Get<SelectedRows>();
102-
auto* trans_selected_rows = out_var->GetMutable<SelectedRows>();
105+
auto &in_selected_rows = in_var.Get<SelectedRows>();
106+
auto *trans_selected_rows = out_var->GetMutable<SelectedRows>();
103107
trans_selected_rows->set_height(in_selected_rows.height());
104108
trans_selected_rows->set_rows(in_selected_rows.rows());
105109
trans_selected_rows->mutable_value()->ShareDataWith(tensor);

paddle/fluid/framework/data_transform.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ limitations under the License. */
3030
namespace paddle {
3131
namespace framework {
3232

33-
void DataTransform(const OpKernelType& expected_kernel_type,
34-
const OpKernelType& kernel_type_for_var,
35-
const Tensor& input_tensor, Tensor* out);
36-
37-
void CopyVariableWithTensor(const Variable& in_var, const Tensor& tensor,
38-
Variable* out_var);
33+
void TransformData(const OpKernelType &expected_kernel_type,
34+
const OpKernelType &kernel_type_for_var,
35+
const Tensor &input_tensor, Tensor *out);
36+
37+
/**
38+
* Set OutVar from InVar, except the tensor is shared with `tensor`
39+
*/
40+
void SetTensorToVariable(const Variable &in_var, const Tensor &tensor,
41+
Variable *out_var);
3942

4043
} // namespace framework
4144
} // namespace paddle

paddle/fluid/framework/op_kernel_type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ inline bool NeedTransformLayout(const DataLayout& l, const DataLayout& r) {
9797
return ret;
9898
}
9999

100-
inline bool TransFromNeeded(const OpKernelType& l, const OpKernelType& r) {
100+
inline bool NeedTransform(const OpKernelType& l, const OpKernelType& r) {
101101
return (!platform::places_are_same_class(l.place_, r.place_)) ||
102102
(l.data_type_ != r.data_type_) ||
103103
NeedTransformLayout(l.data_layout_, r.data_layout_);

0 commit comments

Comments
 (0)