GdsFile
- class torch.cuda.gds.GdsFile(filename, flags)
Wrapper around cuFile.
cuFile is a file-like interface to the GPUDirect Storage (GDS) API.
See the cufile docs for more details.
- Parameters:
filename () – Name of the file to open.
Wrapper around cuFile.
cuFile is a file-like interface to the GPUDirect Storage (GDS) API.
See the cufile docs for more details.
filename () – Name of the file to open.
flags (int) – Flags to pass to os.open when opening the file. os.O_DIRECT will
be added automatically.
Example:
>>> src1 = torch.randn(1024, device="cuda")
>>> src2 = torch.randn(2, 1024, device="cuda")
>>> file = torch.cuda.gds.GdsFile(f, os.O_CREAT | os.O_RDWR)
>>> file.save_storage(src1.untyped_storage(), offset=0)
>>> file.save_storage(src2.untyped_storage(), offset=src1.nbytes)
>>> dest1 = torch.empty(1024, device="cuda")
>>> dest2 = torch.empty(2, 1024, device="cuda")
>>> file.load_storage(dest1.untyped_storage(), offset=0)
>>> file.load_storage(dest2.untyped_storage(), offset=src1.nbytes)
>>> torch.equal(src1, dest1)
True
>>> torch.equal(src2, dest2)
True
Deregisters file descriptor from cuFile Driver.
This is a wrapper around cuFileHandleDeregister.
Loads data from the file into the storage.
This is a wrapper around cuFileRead. storage.nbytes() of data
will be loaded from the file at offset into the storage.
storage (Storage) – Storage to load data into.
offset (int, optional) – Offset into the file to start loading from. (Default: 0)
Registers file descriptor to cuFile Driver.
This is a wrapper around cuFileHandleRegister.
Saves data from the storage into the file.
This is a wrapper around cuFileWrite. All bytes of the storage
will be written to the file at offset.
storage (Storage) – Storage to save data from.
offset (int, optional) – Offset into the file to start saving to. (Default: 0)