Skip to content

Commit 45062fe

Browse files
authored
Feature/copytensor (#5455)
* "make global tensor function independently" * "replace functor" * "fix inline template error" * "fix tensor array with CopyFrom" * "fix other case use CopyFrom" * "move the op interface hardly" * "fix operators" * "fix typo" * "delete dynamic recurrent rnn and fix gru_unit in debugmode" * "fix unique_ptr copy" * "fix cuda copy" * "fix namespace error" * "removed nccl python test" * "fix include error" * "fix typo" * fix copy util test
1 parent 748fdbb commit 45062fe

Some content is hidden

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

57 files changed

+548
-2661
lines changed

paddle/framework/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ cc_test(ddim_test SRCS ddim_test.cc DEPS ddim)
66
nv_test(dim_test SRCS dim_test.cu DEPS ddim)
77

88
cc_library(tensor SRCS tensor.cc DEPS ddim place paddle_memory device_context)
9+
910
cc_test(tensor_test SRCS tensor_test.cc DEPS tensor)
11+
cc_test(tensor_util_test SRCS tensor_util_test.cc DEPS tensor)
12+
1013
cc_test(eigen_test SRCS eigen_test.cc DEPS tensor)
1114

1215
cc_library(lod_tensor SRCS lod_tensor.cc DEPS ddim place tensor framework_proto)
@@ -51,10 +54,6 @@ cc_library(executor SRCS executor.cc DEPS op_registry device_context scope frame
5154

5255
cc_library(prune SRCS prune.cc DEPS framework_proto)
5356
cc_test(prune_test SRCS prune_test.cc DEPS op_info prune recurrent_op device_context)
54-
55-
cc_library(tensor_array SRCS tensor_array.cc DEPS lod_tensor)
56-
cc_test(tensor_array_test SRCS tensor_array_test.cc DEPS tensor_array place)
57-
5857
cc_test(var_type_inference_test SRCS var_type_inference_test.cc DEPS op_registry
5958
proto_desc)
6059
cc_library(selected_rows SRCS selected_rows.cc DEPS tensor)

paddle/framework/backward.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include "paddle/framework/block_desc.h"
2424
#include "paddle/framework/op_registry.h"
25-
#include "paddle/operators/dynamic_recurrent_op.h"
2625
#include "paddle/operators/net_op.h"
2726

2827
namespace paddle {
@@ -218,21 +217,6 @@ static std::unique_ptr<OperatorBase> BackwardRecursive(
218217
return false;
219218
});
220219

221-
// process recurrent gradient op as a special operator.
222-
if (forwardOp.Type() == "dynamic_recurrent") {
223-
// NOTE clean up cycle call somewhere (RNN's stepnet constains itself),
224-
// or this will result in infinite loop.
225-
const auto& rnnop =
226-
*static_cast<const operators::DynamicRecurrentOp*>(&forwardOp);
227-
auto rnn_grad_op =
228-
static_cast<operators::DynamicRecurrentGradientOp*>(grad_op.get());
229-
const auto& stepnet_op =
230-
*static_cast<const OperatorBase*>(&rnnop.rnn.GetStepUnit());
231-
// create stepnet's gradient op
232-
rnn_grad_op->rnn.SetStepUnit(
233-
BackwardRecursive(stepnet_op, no_grad_names, grad_to_var, uniq_id));
234-
}
235-
236220
if (net->ops_.empty()) { // Current no aux op is added to network
237221
return grad_op;
238222
}

paddle/framework/lod_tensor.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <glog/logging.h>
2525
#include "paddle/framework/ddim.h"
2626
#include "paddle/framework/tensor.h"
27+
#include "paddle/framework/tensor_util.h"
2728
#include "paddle/platform/enforce.h"
2829
#include "paddle/platform/place.h"
2930

@@ -175,9 +176,9 @@ LoDTensor LodExpand(const LoDTensor& source, const LoD& lod, size_t level,
175176
PADDLE_ENFORCE_EQ(num_instances, lod_level.size() - 1);
176177
for (size_t ins = 0; ins < num_instances; ins++) {
177178
for (size_t elem = lod_level[ins]; elem < lod_level[ins + 1]; elem++) {
178-
tensor.Slice(elem, elem + 1)
179-
.CopyFrom(source.Slice(ins, ins + 1), platform::CPUPlace(),
180-
platform::CPUDeviceContext());
179+
auto slice = tensor.Slice(elem, elem + 1);
180+
CopyFrom(source.Slice(ins, ins + 1), platform::CPUPlace(),
181+
platform::CPUDeviceContext(), &slice);
181182
}
182183
}
183184
return tensor;

paddle/framework/tensor.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,34 +89,6 @@ class Tensor {
8989
/*! The internal of two tensors share the same memory block. */
9090
inline Tensor& ShareDataWith(const Tensor& src);
9191

92-
/**
93-
* @brief Copy the content of external tensor to a new place.
94-
*
95-
* @param[in] src The external tensor.
96-
* @param[in] dst_place The dst place.
97-
* @param[in] ctx The device context contains device resources.
98-
*
99-
* @note CopyFrom supports CPU <-> GPU, GPU <-> GPU.
100-
*/
101-
// TODO(qijun): https://github.com/PaddlePaddle/Paddle/issues/4647
102-
// Remove `CopyFrom` and `CopyFromVector` from Tensor interface
103-
// and make them global functions
104-
inline void CopyFrom(const Tensor& src, const platform::Place& dst_place,
105-
const platform::DeviceContext& ctx);
106-
107-
/**
108-
* @brief Copy the content of an external vector to a tensor.
109-
*
110-
* @param[in] src The external tensor.
111-
* @param[in] ctx The device context contains device resources.
112-
*
113-
* * @note CopyFromVector assumes that the tensor has been resized
114-
* before invoking.
115-
*/
116-
template <typename T>
117-
inline void CopyFromVector(const std::vector<T>& src,
118-
const platform::DeviceContext& ctx);
119-
12092
/**
12193
* @brief Return a sub-tensor of the given tensor.
12294
*
@@ -141,7 +113,6 @@ class Tensor {
141113

142114
size_t memory_size() const;
143115

144-
private:
145116
inline void check_memory_size() const;
146117

147118
private:

0 commit comments

Comments
 (0)