Skip to content

[QUESTION]Does the tensor created by nvcv::TensorWrapData take the ownship of external memory? #215

Open
@lazylazypig

Description

Does the tensor created by nvcv::TensorWrapData take the ownship of external memory?
the codes 'samples\classification\Main.cpp' make me confused:

// Allocating memory for input image batch
nvcv::TensorDataStridedCuda::Buffer inBuf;
...
CHECK_CUDA_ERROR(cudaMallocAsync(&inBuf.basePtr, batchSize * inBuf.strides[0], stream));

nvcv::Tensor::Requirements inReqs
    = nvcv::Tensor::CalcRequirements(batchSize, {maxImageWidth, maxImageHeight}, nvcv::FMT_RGB8);

nvcv::TensorDataStridedCuda inData(nvcv::TensorShape{inReqs.shape, inReqs.rank, inReqs.layout},
                                   nvcv::DataType{inReqs.dtype}, inBuf);

nvcv::Tensor inTensor = TensorWrapData(inData);
...

as shown above, we use cudaMallocAsync to malloc external memory and bind to inBuf.basePtr. but finally, we can't see any cudaFree/cudaFreeAsync to free the allocated memory.

  1. so, does it mean that the tensor created by TensorWrapData(...) takes the ownship of the external allocated memory? or it was just a little mistake that you forgot to call cudaFree/cudaFreeAsync?
  2. if it's real that tensor takes the ownship of the external allocated memory, what can i do to avoid that? in other words, how can i wrap the external allocated memory to a tensor without lost the ownship?

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions