class_docstr: The class that represents a stream pool associated with a GPU.
  
  When multistream is enabled, we will allocate a pool of streams for each
  GPU, and get available stream from this pool when a collective kernel is
  initialized. This enables overlapping computation/communication kernels
  using multiple CUDA streams, given that the streams a appropriately
  synchronized. The class is thread-safe.
  
  
  Args:
      device_idx: the absolute index of the device for this pool.
class_docstr_tok: ["The","class","that","represents","a","stream","pool","associated","with","a","GPU",".","When","multistream","is","enabled",",","we","will","allocate","a","pool","of","streams","for","each","GPU",",","and","get","available","stream","from","this","pool","when","a","collective","kernel","is","initialized",".","This","enables","overlapping","computation\/communication","kernels","using","multiple","CUDA","streams",",","given","that","the","streams","a","appropriately","synchronized",".","The","class","is","thread-safe",".","Args",":","device_idx",":","the","absolute","index","of","the","device","for","this","pool","."]
docstr: Get an available stream from the pool.
  
  The function locks the stream pool and releases the lock before
  returning.
  
  Returns:
      stream (cupy.cuda.Stream): the returned stream from pool.
docstr_tok: ["Get","an","available","stream","from","the","pool",".","The","function","locks","the","stream","pool","and","releases","the","lock","before","returning",".","Returns",":","stream","(","cupy.cuda.Stream",")",":","the","returned","stream","from","pool","."]
code: def get_stream(self):
      """Get an available stream from the pool.
  
      The function locks the stream pool and releases the lock before
      returning.
  
      Returns:
          stream (cupy.cuda.Stream): the returned stream from pool.
      """
  
      # check the flag
      self._initialized_lock.acquire()
      if not self._initialized:
          self._init_once()
      self._initialized_lock.release()
  
      # Get the stream from the pool.
      self._pool_lock.acquire()
      stream = self._pool[self._counter]
      self._counter = (self._counter + 1) % NCCL_STREAM_POOL_SIZE
      self._pool_lock.release()
      return stream
  
file_path: ray/python/ray/util/collective/collective_group/cuda_stream.py
imports: import logging
  import threading
  import cupy
  from ray.util.collective.collective_group import nccl_util
  from ray.util.collective.const import ENV
label_desc: Use image node_id 2 for calling the StreamPool obj's underlying member method code with example usage: obj.get_stream() and returns: stream