CV-CUDA icon indicating copy to clipboard operation
CV-CUDA copied to clipboard

[QUESTION] torch.as_tensor(nvcv.Tensor.cuda()) copy the data from gpu to cpu?

Open QinlongHuang opened this issue 1 year ago • 3 comments

What is your question? Great work on acceleration on CV tasks! But I find when I convert a nvcv.Tensor to torch.Tensor, it will copy the data in GPU to CPU. Is it a bug? Or any memory consideration?

a = torch.randn(10, 256, 256, 3).to('cuda')  # GPU
a_n = nvcv.as_tensor(a, 'NHWC')  # GPU
b = torch.as_tensor(a_n.cuda())  # CPU

Env Info: RTX 4090, PyTorch 2.0.1

QinlongHuang avatar Aug 24 '23 02:08 QinlongHuang

Another question, can I convert ImageBatchVatShape to nvcv.Tensor or torch.Tensor directly? As far as I know, I have to process it one by one.

QinlongHuang avatar Aug 24 '23 02:08 QinlongHuang

Another question, can I convert ImageBatchVatShape to nvcv.Tensor or torch.Tensor directly? As far as I know, I have to process it one by one.

+1

lokvke avatar Apr 25 '24 09:04 lokvke

In examples they do torch.as_tensor(a_n.cuda(), device='cuda'), but i haven't tested if that writes back to the gpu first or not

j3698w avatar Jun 18 '24 23:06 j3698w