提交 247e22c7 编写于 作者: L liuqi

Refactor reshape cpu kernel without memory copy.

上级 433d74a7
......@@ -178,6 +178,18 @@ class Tensor {
}
}
inline void ResizeWithBuffer(const std::vector<index_t> &shape,
BufferBase *buffer) {
MACE_CHECK(!has_opencl_image(), "Cannot resize image, use ResizeImage.");
shape_ = shape;
image_shape_.clear();
if (buffer_ != nullptr && is_buffer_owner_) {
delete buffer_;
}
buffer_ = buffer;
is_buffer_owner_ = false;
}
inline void ResizeImage(const std::vector<index_t> &shape,
const std::vector<size_t> &image_shape) {
shape_ = shape;
......
......@@ -21,9 +21,7 @@ struct ReshapeFunctor {
const std::vector<index_t> &out_shape,
Tensor *output,
StatsFuture *future) {
output->Resize(out_shape);
// TODO(liuqi): copy on write to avoid this copy.
output->CopyBytes(input->raw_data(), input->size() * sizeof(T));
output->ResizeWithBuffer(out_shape, input->UnderlyingBuffer());
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册