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

Method AllocateFrom

paddle/phi/core/string_tensor.cc:150–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150void* StringTensor::AllocateFrom(Allocator* allocator,
151 DataType dtype,
152 size_t requested_size,
153 bool fake_alloc) {
154 PADDLE_ENFORCE_NOT_NULL(
155 allocator,
156 errors::InvalidArgument(
157 "Required allocator shall not be nullptr, but received nullptr."));
158
159 size_t bytes = numel() * SizeOf(this->dtype());
160 if (fake_alloc) {
161 bytes = 0;
162 } else {
163 PADDLE_ENFORCE_EQ(
164 valid(),
165 true,
166 errors::PreconditionNotMet("The meta data must be valid when call the "
167 "mutable data function."));
168 if (requested_size) {
169 PADDLE_ENFORCE_GE(requested_size,
170 bytes,
171 errors::InvalidArgument(
172 "The reserved size %d should be enough to meet the "
173 "volume required by metadata %d.",
174 requested_size,
175 bytes));
176
177 bytes = requested_size;
178 }
179 }
180
181 if (!holder_ || holder_->size() < bytes + meta_.offset) {
182 meta_.offset = 0;
183 VLOG(10) << "Allocate string data with bytes: " << bytes;
184 holder_.reset();
185 holder_ = allocator->Allocate(bytes);
186 // Initialize the allocated bytes
187 init_holder();
188 meta_.offset = 0;
189 }
190 uintptr_t ptr = reinterpret_cast<uintptr_t>(holder_->ptr()) + meta_.offset;
191 return reinterpret_cast<void*>(ptr);
192}
193
194dtype::pstring* StringTensor::mutable_data(const Place& place,
195 size_t requested_size) {

Callers

nothing calls this directly

Calls 8

SizeOfFunction · 0.85
numelFunction · 0.70
validFunction · 0.70
dtypeMethod · 0.45
sizeMethod · 0.45
resetMethod · 0.45
AllocateMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected