MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / mutable_data

Method mutable_data

paddle/phi/core/dense_tensor_impl.cc:102–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100void DenseTensor::set_type(phi::DataType type) { meta_.dtype = type; }
101
102void* DenseTensor::mutable_data(const Place& place,
103 phi::DataType type,
104 size_t requested_size) {
105 set_type(type);
106 PADDLE_ENFORCE_GE(
107 numel(),
108 0,
109 common::errors::PreconditionNotMet(
110 "The Tensor's element number must be equal or greater than zero. "
111 "The Tensor's shape is [",
112 dims(),
113 "] now"));
114 size_t size = numel() * SizeOf(dtype());
115 if (requested_size && (requested_size > size)) {
116 size = requested_size;
117 }
118
119 /* some versions of paddle::variant don't have operator!= */
120 if (holder_ == nullptr || !(holder_->place() == place) ||
121 holder_->size() < size + meta_.offset) {
122 holder_.reset();
123 holder_ = memory_utils::AllocShared(place, size);
124 meta_.offset = 0;
125 }
126 uintptr_t ptr = reinterpret_cast<uintptr_t>(holder_->ptr()) + meta_.offset;
127 return reinterpret_cast<void*>(ptr);
128}
129
130void* DenseTensor::mutable_data(const Place& place, size_t requested_size) {
131 return mutable_data(place, type(), requested_size);

Callers

nothing calls this directly

Calls 15

dimsFunction · 0.85
SizeOfFunction · 0.85
calc_stridesMethod · 0.80
numelFunction · 0.70
dtypeFunction · 0.70
AllocSharedFunction · 0.50
typeFunction · 0.50
InSameStreamFunction · 0.50
TypeEnum · 0.50
placeMethod · 0.45
sizeMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected