PyTorch torch.wait function
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
)
(
"Wait completed on CUDA tensor"
)
else
:
x
=
torch.
tensor
(
[
1
,
2
,
3
]
)
torch.
wait
(
x
)
(
"Wait completed on CPU tensor"
)