MCPcopy Create free account
hub / github.com/NVIDIA/DALI / AttachBuffer

Method AttachBuffer

dali/c_api_2/data_objects.h:247–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245 }
246
247 void AttachBuffer(
248 int ndim,
249 const int64_t *shape,
250 daliDataType_t dtype,
251 const char *layout,
252 void *data,
253 daliDeleter_t deleter) override {
254 ValidateShape(ndim, shape);
255 Validate(dtype);
256 if (layout)
257 Validate(TensorLayout(layout), ndim);
258
259 TensorShape<> tshape(make_cspan(shape, ndim));
260 size_t num_elements = volume(tshape);
261 if (num_elements > 0 && !data)
262 throw std::invalid_argument("The data buffer must not be NULL for a non-empty tensor.");
263
264 TensorLayout new_layout = {};
265
266 if (!layout) {
267 if (ndim == t_->ndim())
268 new_layout = t_->GetLayout();
269 } else {
270 new_layout = layout;
271 Validate(new_layout, ndim);
272 }
273
274 t_->Reset();
275 auto type_info = TypeTable::GetTypeInfo(dtype);
276 auto element_size = type_info.size();
277
278 std::shared_ptr<void> buffer;
279 if (!deleter.delete_buffer && !deleter.destroy_context) {
280 buffer = std::shared_ptr<void>(data, [](void *){});
281 } else {
282 buffer = std::shared_ptr<void>(data, BufferDeleter{deleter, t_->order()});
283 }
284
285 t_->ShareData(
286 std::move(buffer),
287 num_elements * element_size,
288 t_->is_pinned(),
289 tshape,
290 dtype,
291 t_->device_id(),
292 t_->order());
293
294 if (layout)
295 t_->SetLayout(new_layout);
296 }
297
298 daliBufferPlacement_t GetBufferPlacement() const override {
299 daliBufferPlacement_t placement;

Callers 2

daliTensorAttachBufferFunction · 0.45

Calls 13

ValidateShapeFunction · 0.85
ValidateFunction · 0.85
make_cspanFunction · 0.85
volumeFunction · 0.85
GetTypeInfoFunction · 0.85
TensorLayoutClass · 0.50
ndimMethod · 0.45
GetLayoutMethod · 0.45
ResetMethod · 0.45
sizeMethod · 0.45
ShareDataMethod · 0.45
device_idMethod · 0.45

Tested by

no test coverage detected