CUDA 記憶體操作¶
-
Tensor new_managed_tensor(const Tensor &self, const std::vector<std::int64_t> &sizes)¶
使用統一管理記憶體 (UVM) 分配一個
at::Tensor。然後將其首選儲存位置設定為 CPU(主機記憶體),並在 CUDA 裝置上建立到主機記憶體的對映。- 引數:
self – 輸入張量
sizes – 目標張量維度
- 返回:
一個由 UVM 支援的新張量
-
Tensor new_managed_tensor_meta(const Tensor &self, const std::vector<std::int64_t> &sizes)¶
用於
Meta分派鍵的佔位符操作。- 引數:
self – 輸入張量
sizes – 目標張量維度
- 返回:
一個新的空張量
-
Tensor new_host_mapped_tensor(const Tensor &self, const std::vector<std::int64_t> &sizes)¶
使用主機對映記憶體分配
at::Tensor。- 引數:
self – 輸入張量
sizes – 目標張量維度
- 返回:
一個由主機對映記憶體支援的新張量
-
Tensor new_unified_tensor(const Tensor &self, const std::vector<std::int64_t> &sizes, bool is_host_mapped)¶
使用統一管理記憶體 (UVM) 或主機對映記憶體分配
at::Tensor。- 引數:
self – 輸入張量
sizes – 目標張量維度
is_host_mapped – 是否分配 UVM 或主機對映記憶體
- 返回:
一個由 UVM 或主機對映記憶體支援的新張量,取決於
is_host_mapped的值
-
Tensor new_unified_tensor_meta(const Tensor &self, const std::vector<std::int64_t> &sizes, bool is_host_mapped)¶
用於 new_unified_tensor 的
Meta分派鍵佔位符操作- 引數:
self – 輸入張量
sizes – 目標張量維度
is_host_mapped – 是否分配 UVM 或主機對映記憶體
- 返回:
一個由 UVM 或主機對映記憶體支援的新張量,取決於
is_host_mapped的值
-
Tensor new_vanilla_managed_tensor(const Tensor &self, const std::vector<std::int64_t> &sizes)¶
使用統一管理記憶體 (UVM) 分配一個
at::Tensor,但允許其首選儲存位置自動管理。- 引數:
self – 輸入張量
sizes – 目標張量維度
- 返回:
一個由 UVM 支援的新張量
-
bool uvm_storage(const Tensor &self)¶
檢查張量是否使用 UVM 分配(無論是 CPU 張量還是 GPU 張量)。
- 引數:
self – 輸入張量
- 返回:
如果張量使用 UVM 分配,則為
true,否則為false
-
bool is_uvm_tensor(const Tensor &self)¶
檢查張量是否使用 UVM 分配,但**不是** CPU 張量。
- 引數:
self – 輸入張量
- 返回:
如果張量是非 CPU 張量且使用 UVM 分配,則為
true,否則為false
-
Tensor uvm_to_cpu(const Tensor &self)¶
將 UVM 張量轉換為 CPU 張量。
- 引數:
self – 輸入張量
- 返回:
一個新的張量,實質上是將輸入從 UVM 移動到 CPU
-
Tensor uvm_to_device(const Tensor &self, const Tensor &prototype)¶
建立一個新的 UVM 張量,該張量與
prototype共享相同的裝置和 UVM 儲存。- 引數:
self – 輸入張量
prototype – 目標張量,其裝置和 UVM 儲存將與新張量共享
- 返回:
一個新的張量,該張量與
prototype共享相同的裝置和 UVM 儲存。
-
void uvm_cuda_mem_advise(const Tensor &self, int64_t cuda_memory_advise)¶
對 UVM 張量的儲存呼叫
cudaMemAdvise()。cudaMemoryAdvise列舉在 Python 側的fbgemm_gpu.uvm名稱空間中可用;有關有效值,請參閱那裡的文件。另請參閱
有關
cudaMemoryAdvise列舉的更多資訊,請參閱此處。- 引數:
self – 輸入張量
cuda_memory_advise –
cudaMemoryAdvise列舉值,整數形式
-
void uvm_cuda_mem_prefetch_async(const Tensor &self, std::optional<Tensor> device_t)¶
對 UVM 張量的儲存呼叫
cudaMemPrefetchAsync(),將記憶體預取到目標裝置。另請參閱
有關
cudaMemPrefetchAsync()的更多資訊,請參閱此處。- 引數:
self – 輸入張量
device_t – [可選] 目標張量,其裝置將作為預取目的地
-
void uvm_mem_advice_dont_fork(const Tensor &self)¶
對 UVM 張量的儲存呼叫
madvise(...MADV_DONTFORK)。這是一個解決 UVM 核心驅動在 fork 時將 UVM 儲存頁面從頁表中解除對映,導致下次 CPU 訪問變慢的問題的臨時方案。另請參閱
有關
madvise()的更多資訊,請參閱此處。- 引數:
self – 輸入張量
-
Tensor uvm_to_cpu_clone(const Tensor &self)¶
將 UVM 張量的連續儲存(
uvm_storage(t)為真)複製到一個新的 CPU 張量中。複製操作使用單執行緒的memcpy()。- 引數:
self – 輸入張量
- 返回:
包含從 UVM 張量複製的資料的新 CPU 張量
將張量內容複製到共享記憶體。這對於強制 GPU 記憶體的初始化狀態很有用,這與測試相關。
- 引數:
self – 輸入張量
將 nan 值複製到 GPU 的共享記憶體中。這對於除錯或測試很有用。
- 引數:
self – 輸入張量