Rate this Page

GdsFile#

classtorch.cuda.gds.GdsFile(filename,flags)[source]#

Wrapper around cuFile.

cuFile is a file-like interface to the GPUDirect Storage (GDS) API.

See thecufile docsfor more details.

Parameters
  • filename (str) – Name of the file to open.

  • flags (int) – Flags to pass toos.open when opening the file.os.O_DIRECT willbe 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
deregister_handle()[source]#

Deregisters file descriptor from cuFile Driver.

This is a wrapper aroundcuFileHandleDeregister.

load_storage(storage,offset=0)[source]#

Loads data from the file into the storage.

This is a wrapper aroundcuFileRead.storage.nbytes() of datawill be loaded from the file atoffset into the storage.

Parameters
  • storage (Storage) – Storage to load data into.

  • offset (int,optional) – Offset into the file to start loading from. (Default: 0)

register_handle()[source]#

Registers file descriptor to cuFile Driver.

This is a wrapper aroundcuFileHandleRegister.

save_storage(storage,offset=0)[source]#

Saves data from the storage into the file.

This is a wrapper aroundcuFileWrite. All bytes of the storagewill be written to the file atoffset.

Parameters
  • storage (Storage) – Storage to save data from.

  • offset (int,optional) – Offset into the file to start saving to. (Default: 0)