_await.py 852 B

123456789101112131415161718192021222324252627
  1. # mypy: allow-untyped-defs
  2. import torch
  3. from torch._jit_internal import _Await
  4. from torch.jit._builtins import _register_builtin
  5. from torch.utils import set_module
  6. set_module(_Await, "torch.jit")
  7. def _awaitable(func, *args, **kwargs):
  8. r"""Create Await object that will call specified functioni with specified args, when it is requested for the result."""
  9. return torch._C._awaitable(func, *args, **kwargs)
  10. def _awaitable_wait(aw):
  11. r"""Request await the result of execution, if Await is not completed yet, the func will be called immediately."""
  12. return torch._C._awaitable_wait(aw)
  13. def _awaitable_nowait(o):
  14. r"""Create completed Await with specified result."""
  15. return torch._C._awaitable_nowait(o)
  16. _register_builtin(_awaitable_wait, "prim::awaitable_wait")
  17. _register_builtin(_awaitable_nowait, "prim::awaitable_nowait")