PyTorch torch.cuda.synchronize 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

torch.cuda.synchronizePyTorch で CUDA 同期に使用される関数です。すべての CUDA コアが現在のタスクを完了するのを待ち、CPU と GPU の操作が同期することを保証します。

関数定義

torch.cuda.synchronize(device=None)

使用例

例

import torch
import time

# CUDA 同期の例
if torch.cuda.is_available():
    # CUDA テンソルを作成し、操作を実行します
    x = torch.randn(1000, 1000).cuda()
    y = torch.mm(x, x)

    # CUDA 操作を同期します
    torch.cuda.synchronize()

    print("CUDA operations synchronized")
else:
    print("CUDA not available")

Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

その他の拡張