• 文件 >
  • CUDA 記憶體運算元
捷徑

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)

分配 at::Tensor,使用統一管理記憶體 (UVM) 或主機映射記憶體。

參數:
  • 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 – 輸入張量

回傳:

如果張量是使用 UVM 分配的非 CPU 張量,則為 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_advisecudaMemoryAdvise 列舉值,以整數形式

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) 為 true)複製到新的 CPU Tensor 中。複製操作使用單執行緒 memcpy()

參數:

self – 輸入張量

回傳:

一個包含從 UVM 張量複製的資料的新 CPU 張量

文件

存取 PyTorch 的完整開發人員文件

查看文件

教學

為初學者和進階開發人員取得深入的教學

查看教學

資源

尋找開發資源並獲得問題解答

查看資源