Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.wait function

PyTorch torch.wait function


PyTorch torch reference manual PyTorch torch reference manual

torch.wait A function in PyTorch used for waiting, to synchronize CPU and GPU operations.

Function definition

torch.wait(tensor)


Usage examples

Example

import

torch

Create a tensor (use the GPU if CUDA is available)

if

torch.

cuda

.

is_available

(

)

:

    x

=

torch.

tensor

(

[

1

,

2

,

3

]

)

.

cuda

(

)

    torch.

wait

(

x

)

   

print

(

"Wait completed on CUDA tensor"

)

else

:

    x

=

torch.

tensor

(

[

1

,

2

,

3

]

)

    torch.

wait

(

x

)

   

print

(

"Wait completed on CPU tensor"

)


PyTorch torch reference manual PyTorch torch reference manual