class_docstr: Context-manager that captures CUDA work into a :class:`torch.cuda.CUDAGraph` object for later replay.
  
  See :ref:`CUDA Graphs <cuda-graph-semantics>` for a general introduction,
  detailed use, and constraints.
  
  Arguments:
      cuda_graph (torch.cuda.CUDAGraph): Graph object used for capture.
      pool (optional): Opaque token (returned by a call to :func:`~torch.cuda.graph_pool_handle()` or
          :meth:`other_Graph_instance.pool()<torch.cuda.CUDAGraph.pool>`) hinting this graph's capture
          may share memory from the specified pool. See :ref:`Graph memory management<graph-memory-management>`.
      stream (torch.cuda.Stream, optional): If supplied, will be set as the current stream in the context.
          If not supplied, ``graph`` sets its own internal side stream as the current stream in the context.
      capture_error_mode (str, optional): specifies the cudaStreamCaptureMode for the graph capture stream.
          Can be "global", "thread_local" or "relaxed". During cuda graph capture, some actions, such as cudaMalloc,
          may be unsafe. "global" will error on actions in other threads, "thread_local" will only error for
          actions in the current thread, and "relaxed" will not error on actions. Do NOT change this setting
          unless you're familiar with `cudaStreamCaptureMode <https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html#group__CUDART__STREAM_1g9d0535d93a214cbf126835257b16ba85>`_
  
  .. note::
      For effective memory sharing, if you pass a ``pool`` used by a previous capture and the previous capture
      used an explicit ``stream`` argument, you should pass the same ``stream`` argument to this capture.
  
  .. warning::
      This API is in beta and may change in future releases.
  
  .. _cudaStreamCaptureMode:
      https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html#group__CUDART__STREAM_1g9d0535d93a214cbf126835257b16ba85
code: def __enter__(self):
      # Free as much memory as we can for the graph
      torch.cuda.synchronize()
      gc.collect()
      torch.cuda.empty_cache()
  
      # Stackoverflow seems comfortable with this pattern
      # https://stackoverflow.com/questions/26635684/calling-enter-and-exit-manually#39172487
      self.stream_ctx.__enter__()
  
      self.cuda_graph.capture_begin(
          *self.pool, capture_error_mode=self.capture_error_mode
      )
  
imports: import gc
  import torch
  from torch.utils import _pytree
  from ._utils import _dummy_type
  from torch._C import _cuda_isCurrentStreamCapturing, _CUDAGraph, _graph_pool_handle
label_desc: Use image node_id 2 for calling the graph obj's underlying member method code with example usage: obj.__enter__() without return types