-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle file descriptor ownership and update documents for GDS (#234)
- 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
- Loading branch information
Showing
5 changed files
with
81 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters