快捷方式

GdsFile

class torch.cuda.gds.GdsFile(filename, flags)[source][source]

cuFile 的包裝器。

cuFile 是 GPUDirect Storage (GDS) API 的檔案類介面。

有關更多詳細資訊,請參閱 cufile 文件

引數
  • filename (str) – 要開啟的檔名。

  • flags (int) – 開啟檔案時傳遞給 os.open 的標誌。os.O_DIRECT 將自動新增。

示例

>>> 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][source]

從 cuFile 驅動程式登出檔案描述符。

這是 cuFileHandleDeregister 的包裝器。

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

將資料從檔案載入到 storage 中。

這是 cuFileRead 的包裝器。檔案中的 storage.nbytes() 位元組資料將從 offset 處載入到 storage 中。

引數
  • storage (Storage) – 要載入資料的 storage。

  • offset (int, optional) – 檔案中開始載入的偏移量。(預設值: 0)

register_handle()[source][source]

向 cuFile 驅動程式註冊檔案描述符。

這是 cuFileHandleRegister 的包裝器。

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

將資料從 storage 儲存到檔案中。

這是 cuFileWrite 的包裝器。storage 中的所有位元組都將寫入檔案中 offset 處。

引數
  • storage (Storage) – 要從中儲存資料的 storage。

  • offset (int, optional) – 檔案中開始儲存的偏移量。(預設值: 0)

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源