From 14049ae574a44f987e72407241d60720c19a5818 Mon Sep 17 00:00:00 2001 From: chentianyu03 Date: Mon, 14 Feb 2022 19:01:59 +0800 Subject: [PATCH] [pten] add CI check for using DenseTensor::mutable_data() in pten directions (#39467) --- paddle/pten/core/dense_tensor.h | 5 +++++ paddle/pten/core/dense_tensor.inl | 5 ----- tools/check_file_diff_approvals.sh | 11 +++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/paddle/pten/core/dense_tensor.h b/paddle/pten/core/dense_tensor.h index ef8520e29c..44232930e5 100644 --- a/paddle/pten/core/dense_tensor.h +++ b/paddle/pten/core/dense_tensor.h @@ -162,6 +162,11 @@ class DenseTensor : public TensorBase, /// \return The const data pointer value of raw type. const void* data() const; + template + T* data(); + + void* data(); + private: friend class DenseTensorUtils; diff --git a/paddle/pten/core/dense_tensor.inl b/paddle/pten/core/dense_tensor.inl index d5d207aba4..4df6b2556a 100644 --- a/paddle/pten/core/dense_tensor.inl +++ b/paddle/pten/core/dense_tensor.inl @@ -53,11 +53,6 @@ DenseTensor(intrusive_ptr storage, DenseTensorMeta&& meta); inline bool IsInitialized() const { return holder_ != nullptr; } -template -T* data(); - -void* data(); - template T* mutable_data(const paddle::platform::Place& place, size_t requested_size = 0); diff --git a/tools/check_file_diff_approvals.sh b/tools/check_file_diff_approvals.sh index eb58764f7f..4fd4e809ca 100644 --- a/tools/check_file_diff_approvals.sh +++ b/tools/check_file_diff_approvals.sh @@ -262,6 +262,17 @@ if [ "${PTEN_INCLUDE_FLUID_FILES}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then echo_line="You must have one RD (chenwhql, MingMingShangTian, YuanRisheng or zyfncg) approval for the including paddle/fluid header in paddle/pten files(${PTEN_INCLUDE_FLUID_FILES}).\n" check_approval 1 chenwhql MingMingShangTian YuanRisheng zyfncg fi +PTEN_USE_MUTABLE_DATA_FILES="" +for CHANGE_FILE in ${HAS_MODIFIED_PTEN_FILES}; do + PTEN_DIR_ADDED_LINES=`git diff -U0 upstream/$BRANCH -- ${PADDLE_ROOT}/${CHANGE_FILE} | grep "^+" | grep -w "mutable_data" || true` + if [ "${PTEN_DIR_ADDED_LINES}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then + PTEN_USE_MUTABLE_DATA_FILES="${PTEN_USE_MUTABLE_DATA_FILES} ${CHANGE_FILE}" + fi +done +if [ "${PTEN_USE_MUTABLE_DATA_FILES}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then + echo_line="You can not use the DenseTensor::mutable_data() method in paddle/pten files(${PTEN_USE_MUTABLE_DATA_FILES}). If you want to alloc memory, use pten::DeviceContext::Alloc() or pten::DeviceContext::HostAlloc() instead and if you want to get mutable data, use DenseTensor::data(). If you have any questions, you can have one RD (chenwhql, Shixiaowei02, MingMingShangTian, YuanRisheng or zyfncg) review and approve.\n" + check_approval 1 chenwhql Shixiaowei02 MingMingShangTian YuanRisheng zyfncg +fi ALL_CHANGE_FILES=`git diff --numstat upstream/$BRANCH | awk '{print $3}' | grep ".py"` ALL_OPTEST_BAN_DYGRAPH_MESSAGE="" -- GitLab