Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lazylazypig opened this issue Nov 10, 2024 · 1 comment
Labels
question Further information is requested

Comments

@lazylazypig
Copy link

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?
@lazylazypig lazylazypig added the question Further information is requested label Nov 10, 2024
@sergeybayandin
Copy link

Does specify cleanup callback (TensorDataCleanupCallback) make any differences?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants