MCPcopy Create free account
hub / github.com/KomputeProject/kompute / destroy

Method destroy

src/Tensor.cpp:507–590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

505}
506
507void
508Tensor::destroy()
509{
510 KP_LOG_DEBUG("Kompute Tensor started destroy()");
511
512 // Setting raw data to null regardless whether device is available to
513 // invalidate Tensor
514 this->mRawData = nullptr;
515 this->mSize = 0;
516 this->mDataTypeMemorySize = 0;
517
518 if (!this->mDevice) {
519 KP_LOG_WARN(
520 "Kompute Tensor destructor reached with null Device pointer");
521 return;
522 }
523
524 // Unmap the current memory data
525 if (this->tensorType() != Tensor::TensorTypes::eStorage) {
526 this->unmapRawData();
527 }
528
529 if (this->mFreePrimaryBuffer) {
530 if (!this->mPrimaryBuffer) {
531 KP_LOG_WARN("Kompose Tensor expected to destroy primary buffer "
532 "but got null buffer");
533 } else {
534 KP_LOG_DEBUG("Kompose Tensor destroying primary buffer");
535 this->mDevice->destroy(
536 *this->mPrimaryBuffer,
537 (vk::Optional<const vk::AllocationCallbacks>)nullptr);
538 this->mPrimaryBuffer = nullptr;
539 this->mFreePrimaryBuffer = false;
540 }
541 }
542
543 if (this->mFreeStagingBuffer) {
544 if (!this->mStagingBuffer) {
545 KP_LOG_WARN("Kompose Tensor expected to destroy staging buffer "
546 "but got null buffer");
547 } else {
548 KP_LOG_DEBUG("Kompose Tensor destroying staging buffer");
549 this->mDevice->destroy(
550 *this->mStagingBuffer,
551 (vk::Optional<const vk::AllocationCallbacks>)nullptr);
552 this->mStagingBuffer = nullptr;
553 this->mFreeStagingBuffer = false;
554 }
555 }
556
557 if (this->mFreePrimaryMemory) {
558 if (!this->mPrimaryMemory) {
559 KP_LOG_WARN("Kompose Tensor expected to free primary memory but "
560 "got null memory");
561 } else {
562 KP_LOG_DEBUG("Kompose Tensor freeing primary memory");
563 this->mDevice->freeMemory(
564 *this->mPrimaryMemory,

Callers 7

~TensorMethod · 0.95
rebuildMethod · 0.95
test_sequenceFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45

Calls 2

tensorTypeMethod · 0.95
unmapRawDataMethod · 0.95

Tested by 5

test_sequenceFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36