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

Method AttachBuffer

dali/c_api_2/data_objects.h:437–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435 }
436
437 void AttachBuffer(
438 int num_samples,
439 int ndim,
440 const int64_t *shapes,
441 daliDataType_t dtype,
442 const char *layout,
443 void *data,
444 const ptrdiff_t *sample_offsets,
445 daliDeleter_t deleter) override {
446 ValidateShape(num_samples, ndim, shapes);
447 Validate(dtype);
448
449 if (!data && num_samples > 0) {
450 for (int i = 0; i < num_samples; i++) {
451 auto sample_shape = make_cspan(&shapes[i*ndim], ndim);
452
453 if (volume(sample_shape) > 0)
454 throw std::invalid_argument(
455 "The pointer to the data buffer must not be null for a non-empty tensor list.");
456
457 if (sample_offsets && sample_offsets[i])
458 throw std::invalid_argument(
459 "All sample_offsets must be zero when the data pointer is NULL.");
460 }
461 }
462
463 TensorLayout new_layout = {};
464
465 if (!layout) {
466 if (ndim == tl_->sample_dim())
467 new_layout = tl_->GetLayout();
468 } else {
469 new_layout = layout;
470 Validate(new_layout, ndim);
471 }
472
473 tl_->Reset();
474 tl_->SetSize(num_samples);
475 tl_->set_sample_dim(ndim);
476 tl_->SetLayout(new_layout);
477 tl_->set_type(dtype);
478 ptrdiff_t next_offset = 0;
479 auto type_info = TypeTable::GetTypeInfo(dtype);
480 auto element_size = type_info.size();
481
482 std::shared_ptr<void> buffer;
483 if (!deleter.delete_buffer && !deleter.destroy_context) {
484 buffer = std::shared_ptr<void>(data, [](void *){});
485 } else {
486 buffer = std::shared_ptr<void>(data, BufferDeleter{deleter, tl_->order()});
487 }
488
489 bool is_contiguous = true;
490 if (sample_offsets) {
491 for (int i = 0; i < num_samples; i++) {
492 if (sample_offsets[i] != next_offset) {
493 is_contiguous = false;
494 break;

Callers

nothing calls this directly

Calls 15

ValidateShapeFunction · 0.85
ValidateFunction · 0.85
make_cspanFunction · 0.85
volumeFunction · 0.85
GetTypeInfoFunction · 0.85
SetSizeMethod · 0.80
SetSampleMethod · 0.80
sample_dimMethod · 0.45
GetLayoutMethod · 0.45
ResetMethod · 0.45
set_sample_dimMethod · 0.45
SetLayoutMethod · 0.45

Tested by

no test coverage detected