Skip to content

Commit 7594787

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into enhance_hierachical_sigmod_op
2 parents c469334 + 3c77ce3 commit 7594787

File tree

8 files changed

+53
-30
lines changed

8 files changed

+53
-30
lines changed

paddle/fluid/framework/operator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class OperatorBase;
7171
class ExecutionContext;
7272

7373
/**
74-
* OperatorBase has the basic element that Net will call to do computation.
74+
* OperatorBase has the basic elements that Net will call to do computation.
7575
* Only CreateOperator from OpRegistry will new Operator directly. User
7676
* should always construct a proto message OpDesc and call
7777
* OpRegistry::CreateOp(op_desc) to get an Operator instance.

paddle/fluid/framework/transfer_scope_cache.cc

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,16 @@
1717
namespace paddle {
1818
namespace framework {
1919

20-
// Holds all the transfer scope across the process.
2120
std::unordered_map<size_t, Scope*>& global_transfer_data_cache() {
22-
typedef std::unordered_map<size_t, Scope*> map_t;
23-
thread_local std::unique_ptr<map_t> x(new map_t);
21+
thread_local auto* x = new std::unordered_map<size_t, Scope*>;
2422
return *x;
2523
}
2624

27-
// Holds all the transfer scope for this thread.
2825
std::unordered_set<Scope*>& global_transfer_scope_cache() {
29-
typedef std::unordered_set<Scope*> set_t;
30-
thread_local std::unique_ptr<set_t> x(new set_t);
26+
thread_local auto* x = new std::unordered_set<Scope*>;
3127
return *x;
3228
}
3329

34-
// Try to create a transfer scope. If one cached scope has match the
35-
// requirement, just return that one.
36-
// Inputs:
37-
// @type0: the source kernel type.
38-
// @type1: the target kernel type.
39-
// @scope: the execution scope of this op.
40-
// Returns: A scope used to hold the transfer data across the different kernel
41-
// type.
4230
Scope* TryCreateTransferScope(OpKernelType type0, OpKernelType type1,
4331
const Scope* scope) {
4432
Scope* new_scope{nullptr};
@@ -58,5 +46,27 @@ Scope* TryCreateTransferScope(OpKernelType type0, OpKernelType type1,
5846
return new_scope;
5947
}
6048

49+
void RemoveKidsFromTransferScopeCache(Scope* scope) {
50+
auto it = global_transfer_scope_cache().find(scope);
51+
if (it != global_transfer_scope_cache().end()) {
52+
global_transfer_scope_cache().erase(it);
53+
}
54+
for (auto* s : scope->kids()) {
55+
auto it = global_transfer_scope_cache().find(s);
56+
if (it != global_transfer_scope_cache().end()) {
57+
global_transfer_scope_cache().erase(it);
58+
}
59+
}
60+
61+
// remove global transfer data cache
62+
auto& cache = global_transfer_data_cache();
63+
for (auto it = cache.begin(); it != cache.end();) {
64+
if (it->second == scope)
65+
it = cache.erase(it);
66+
else
67+
it++;
68+
}
69+
}
70+
6171
} // namespace framework
6272
} // namespace paddle

paddle/fluid/inference/analysis/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ function(inference_analysis_test TARGET)
3535
endif()
3636
endfunction(inference_analysis_test)
3737

38-
inference_analysis_test(test_analyzer SRCS analyzer_tester.cc EXTRA_DEPS reset_tensor_array paddle_inference_api)
38+
inference_analysis_test(test_analyzer SRCS analyzer_tester.cc
39+
EXTRA_DEPS reset_tensor_array paddle_inference_api)

paddle/fluid/inference/api/analysis_predictor.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ bool AnalysisPredictor::GetFetch(std::vector<PaddleTensor> *outputs,
284284
framework::GetFetchVariable(*scope, "fetch", idx);
285285
auto type = fetch.type();
286286
auto output = &(outputs->at(i));
287+
output->name = fetchs_[idx]->Input("X")[0];
287288
if (type == typeid(float)) {
288289
GetFetchOne<float>(fetch, output);
289290
output->dtype = PaddleDType::FLOAT32;

paddle/fluid/inference/api/analysis_predictor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class AnalysisPredictor : public PaddlePredictor {
109109
std::map<std::string, size_t> feed_names_;
110110
std::vector<framework::OpDesc *> fetchs_;
111111
// Memory buffer for feed inputs. The temporary LoDTensor will cause serious
112-
// concurrency problems, so cache them.
112+
// concurrency problems, wrong results and memory leak, so cache them.
113113
std::vector<framework::LoDTensor> feed_tensors_;
114114
details::TensorArrayBatchCleaner tensor_array_batch_cleaner_;
115115

paddle/fluid/inference/api/api_impl.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,12 @@ bool NativePaddlePredictor::SetFeed(const std::vector<PaddleTensor> &inputs,
185185
<< inputs.size();
186186
return false;
187187
}
188+
189+
// Cache the inputs memory for better concurrency performance.
190+
feed_tensors_.resize(inputs.size());
191+
188192
for (size_t i = 0; i < inputs.size(); ++i) {
189-
framework::LoDTensor input;
193+
auto &input = feed_tensors_[i];
190194
framework::DDim ddim = framework::make_ddim(inputs[i].shape);
191195
void *input_ptr;
192196
if (inputs[i].dtype == PaddleDType::INT64) {
@@ -261,6 +265,7 @@ bool NativePaddlePredictor::GetFetch(std::vector<PaddleTensor> *outputs,
261265
framework::GetFetchVariable(*scope, "fetch", idx);
262266
auto type = fetch.type();
263267
auto output = &(outputs->at(i));
268+
output->name = fetchs_[idx]->Input("X")[0];
264269
if (type == typeid(float)) {
265270
GetFetchOne<float>(fetch, output);
266271
output->dtype = PaddleDType::FLOAT32;

paddle/fluid/inference/api/api_impl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class NativePaddlePredictor : public PaddlePredictor {
6969
std::vector<framework::OpDesc *> feeds_;
7070
std::map<std::string, size_t> feed_names_;
7171
std::vector<framework::OpDesc *> fetchs_;
72+
// Memory buffer for feed inputs. The temporary LoDTensor will cause serious
73+
// concurrency problems, wrong results and memory leak, so cache them.
74+
std::vector<framework::LoDTensor> feed_tensors_;
7275
// Do not use unique_ptr, use parent scope to delete
7376
framework::Scope *sub_scope_{nullptr};
7477
details::TensorArrayBatchCleaner tensor_array_batch_cleaner_;

paddle/scripts/paddle_build.sh

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -469,18 +469,21 @@ function assert_api_spec_approvals() {
469469
BRANCH="develop"
470470
fi
471471

472-
API_CHANGE=`git diff --name-only upstream/$BRANCH | grep "paddle/fluid/API.spec" || true`
473-
echo "checking API.spec change, PR: ${GIT_PR_ID}, changes: ${API_CHANGE}"
474-
if [ ${API_CHANGE} ] && [ "${GIT_PR_ID}" != "" ]; then
475-
# NOTE: per_page=10000 should be ok for all cases, a PR review > 10000 is not human readable.
476-
APPROVALS=`curl -H "Authorization: token ${GITHUB_API_TOKEN}" https://api.github.com/repos/PaddlePaddle/Paddle/pulls/${GIT_PR_ID}/reviews?per_page=10000 | \
477-
python ${PADDLE_ROOT}/tools/check_pr_approval.py 2 7845005 2887803 728699 13348433`
478-
echo "current pr ${GIT_PR_ID} got approvals: ${APPROVALS}"
479-
if [ "${APPROVALS}" == "FALSE" ]; then
480-
echo "You must have at least 2 approvals for the api change!"
481-
exit 1
482-
fi
483-
fi
472+
API_FILES=("paddle/fluid/API.spec" "paddle/fluid/framework/operator.h")
473+
for API_FILE in ${API_FILES[*]}; do
474+
API_CHANGE=`git diff --name-only upstream/$BRANCH | grep "${API_FILE}" || true`
475+
echo "checking ${API_FILE} change, PR: ${GIT_PR_ID}, changes: ${API_CHANGE}"
476+
if [ ${API_CHANGE} ] && [ "${GIT_PR_ID}" != "" ]; then
477+
# NOTE: per_page=10000 should be ok for all cases, a PR review > 10000 is not human readable.
478+
APPROVALS=`curl -H "Authorization: token ${GITHUB_API_TOKEN}" https://api.github.com/repos/PaddlePaddle/Paddle/pulls/${GIT_PR_ID}/reviews?per_page=10000 | \
479+
python ${PADDLE_ROOT}/tools/check_pr_approval.py 2 7845005 2887803 728699 13348433`
480+
echo "current pr ${GIT_PR_ID} got approvals: ${APPROVALS}"
481+
if [ "${APPROVALS}" == "FALSE" ]; then
482+
echo "You must have at least 2 approvals for the api change! ${API_FILE}"
483+
exit 1
484+
fi
485+
fi
486+
done
484487
}
485488

486489

0 commit comments

Comments
 (0)