You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a CuFileDriver instance is created by the file descriptor (fd), the file descriptor needs to be closed manually.
However, if the CuFileDriver instance is created by cucim.clara.filesystem.open() method, its file descriptor needs to be closed automatically when the reference count is zero.
Steps/Code to reproduce bug
fromcucim.clara.filesystemimportCuFileDriverimportcucim.clara.filesystemasfsimportos, cupyascp, torch# Create a CuPy array with size 10 (in bytes)cp_arr=cp.ones(10, dtype=cp.uint8)
# Create a PyTorch array with size 10 (in bytes)cuda0=torch.device('cuda:0')
torch_arr=torch.ones(10, dtype=torch.uint8, device=cuda0)
# Using CuFileDriver# (Opening a file with O_DIRECT flag is required for GDS)fno=os.open("input.raw", os.O_RDONLY|os.O_DIRECT)
withCuFileDriver(fno) asfd:
# Read 8 bytes starting from file offset 0 into buffer offset 2read_count=fd.pread(cp_arr, 8, 0, 2)
# Read 10 bytes starting from file offset 3read_count=fd.pread(torch_arr, 10, 3)
os.close(fno)
# Another way of opening file with cuFilewithfs.open("output.raw", "w") asfd:
# Write 10 bytes from cp_array to file starting from offset 5write_count=fd.pwrite(cp_arr, 10, 5)
############################################## <=== file descriptor created by fs.open() is not closed when exiting the scope#############################################
Expected behavior
It should close the file descriptor.
Environment details (please complete the following information):
Environment location: Bare-metal
Method of cuCIM install: pip, from source
The text was updated successfully, but these errors were encountered:
- Close the file descriptor if the file descriptor is owned by the object.
- Update GDS example in the Jupyter notebook.
```python
from cucim.clara.filesystem import CuFileDriver
import cucim.clara.filesystem as fs
import os, cupy as cp, torch
# Create a CuPy array with size 10 (in bytes)
cp_arr = cp.ones(10, dtype=cp.uint8)
# Create a PyTorch array with size 10 (in bytes)
cuda0 = torch.device('cuda:0')
torch_arr = torch.ones(10, dtype=torch.uint8, device=cuda0)
# Using CuFileDriver
# (Opening a file with O_DIRECT flag is required for GDS)
fno = os.open("input.raw", os.O_RDONLY | os.O_DIRECT)
with CuFileDriver(fno) as fd:
# Read 8 bytes starting from file offset 0 into buffer offset 2
read_count = fd.pread(cp_arr, 8, 0, 2)
# Read 10 bytes starting from file offset 3
read_count = fd.pread(torch_arr, 10, 3)
os.close(fno)
# Another way of opening file with cuFile
with fs.open("output.raw", "w") as fd:
# Write 10 bytes from cp_array to file starting from offset 5
write_count = fd.pwrite(cp_arr, 10, 5)
#############################################
# <=== file descriptor created by fs.open() would be closed when exiting the scope
#############################################
```
Fixes#233
Authors:
- Gigon Bae (https://github.com/gigony)
Approvers:
- https://github.com/jakirkham
URL: #234
Describe the bug
If a CuFileDriver instance is created by the file descriptor (fd), the file descriptor needs to be closed manually.
However, if the CuFileDriver instance is created by cucim.clara.filesystem.open() method, its file descriptor needs to be closed automatically when the reference count is zero.
Steps/Code to reproduce bug
Expected behavior
It should close the file descriptor.
Environment details (please complete the following information):
The text was updated successfully, but these errors were encountered: