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
Make DALI array_interface memory writable #4800
Conversation
!build |
@@ -63,7 +63,7 @@ def test_dlpack_tensor_list_gpu_to_cpu(): | |||
|
|||
|
|||
def check_dlpack_types_gpu(t): | |||
arr = torch.tensor([[-0.39, 1.5], [-1.5, 0.33]], device="cuda", dtype=t) | |||
arr = torch.tensor([[0.39, 1.5], [1.5, 0.33]], device="cuda", dtype=t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest torch complains value cannot be converted to type uint8 without overflow
.
@@ -149,7 +149,7 @@ def create_tmp(idx): | |||
|
|||
|
|||
def check_dlpack_types_cpu(t): | |||
arr = torch.tensor([[-0.39, 1.5], [-1.5, 0.33]], device="cpu", dtype=t) | |||
arr = torch.tensor([[0.39, 1.5], [1.5, 0.33]], device="cpu", dtype=t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest torch complains value cannot be converted to type uint8 without overflow
.
CI MESSAGE: [8039230]: BUILD STARTED |
CI MESSAGE: [8039230]: BUILD PASSED |
Shouldn't it be "writable" in the title? |
- marking DALI memory shared by array_interface read-only prevents it from sharing directly with Torch and possibly other libraries. This PR makes it writable. - memory can be shared anyway but it requires an intermediate step through cupy which makes the memory writable Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
d0be253
to
106cc0d
Compare
Fixed |
Just a question: when converting form one Tensor type to another, like when we do TensorList -> Tensor, we typically pack the shared_ptr to the memory somewhere. Here, I don't think there is even Python object reference to the original tensor. Wouldn't it crash in an iteration or two in most cases? |
I don't think the pipeline exposes a non-continuous tensor as the output. In the general case, it may not work, in most cases, we just expose the pointer to the underlying, continuous memory, so the tensor itself doesn't have to live long. |
The problem I'm referring to is specifically how long the allocation is valid. But thinking about it, the array interface is just a property of the object, and accessing it doesn't impact the lifetime of the original object. So the user of array interface must take lifetimes into account and keep the original object alive as long as they are using the raw pointer that they obtain. I think we should be fine, until someone keeps this pointer for too long thinking it contents won't change. I don't know what Pytorch may do with such memory. |
Yes, that is what I had in mind. I think PyTorch just wraps the memory up and does nothing with it. After all, it was possible already but with cupy in the middle. |
Also, reading the docs of array_interface:
I think it solves my issues. |
I guess that we want to use the new interface at some point. |
from sharing directly with Torch and possibly other libraries.
This PR makes it writable.
through cupy which makes the memory writable
Category:
Other*/Breaking change(I hope not)
Description:
from sharing directly with Torch and possibly other libraries.
This PR makes it writable.
through cupy which makes the memory writable
Additional information:
Affected modules and functionalities:
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A