code: def query_nvidia_smi(device_ids: List[int], result_queue: multiprocessing.Queue) -> None:
      
      device_id_strs = [str(device_id) for device_id in device_ids]
      query = "--query-gpu=index,memory.used,memory.total"
      format_arg = "--format=csv,noheader,nounits"
      try:
          sp = subprocess.Popen(['nvidia-smi', query, format_arg, "-i", ",".join(device_id_strs)],
                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
          result = sp.communicate()[0].decode("utf-8").rstrip().split("\n")
      except OSError:
          logger.exception("Failed calling nvidia-smi to query memory usage.")
          result_queue.put({})
          return
      try:
          memory_data = {}
          for line in result:
              gpu_id, mem_used, mem_total = line.split(",")
              memory_data[int(gpu_id)] = (int(mem_used), int(mem_total))
  
          result_queue.put(memory_data)
      except:
          logger.exception("Failed parsing nvidia-smi output %s", "\n".join(result))
          result_queue.put({})
docs: Runs nvidia-smi to determine the memory usage.
  
      :param device_ids: A list of devices for which the the memory usage will be queried.
      :param result_queue: The queue to which the result dictionary of device id mapping to a tuple of
      (memory used, memory total) is added.