code: def get_device_info(dev_index: int) -> _cu_device_info:
      try:
          return _device_infos[dev_index]
      except KeyError:
          pass
  
      _init_nvml()
      if _nvml_lib is None:
          return None
      _init()
      if _init_pid is None:
          return None
  
      device = c_int()
      name_buf = create_string_buffer(100)
      cc_major = c_int()
      cc_minor = c_int()
      cores = c_int()
      threads_per_core = c_int()
  
      uuid_b = get_index_and_uuid(dev_index).uuid
      _cu_check_error(
          _cuda_lib.cuDeviceGet(byref(device), c_int(dev_index))
      )
      _cu_check_error(
          _cuda_lib.cuDeviceGetName(name_buf, len(name_buf), device)
      )
      _cu_check_error(
          _cuda_lib.cuDeviceComputeCapability(
              byref(cc_major), byref(cc_minor), device
          )
      )
      _cu_check_error(
          _cuda_lib.cuDeviceGetAttribute(
              byref(cores),
              CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
              device,
          )
      )
      _cu_check_error(
          _cuda_lib.cuDeviceGetAttribute(
              byref(threads_per_core),
              CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR,
              device,
          )
      )
  
      if "CUDA_VISIBLE_DEVICES" in os.environ:
          real_dev_index = [
              int(s)
              for s in os.environ["CUDA_VISIBLE_DEVICES"].split(",")
          ][dev_index]
      else:
          real_dev_index = dev_index
  
      info = _device_infos[dev_index] = _cu_device_info(
          index=real_dev_index,
          uuid=uuid_b,
          name=name_buf.value.decode(),
          multiprocessors=cores.value,
          cuda_cores=cores.value
          * _cu_get_processor_cores(cc_major.value, cc_minor.value),
          threads=cores.value * threads_per_core.value,
      )
      return info
  
imports: import dataclasses
  import logging
  import os
  import subprocess
  import sys
  import uuid
  from collections import namedtuple
  from ctypes import c_char, c_char_p, c_int, c_uint, c_ulonglong, byref, create_string_buffer, Structure, POINTER, CDLL
  from typing import List, Tuple, Optional, Union
  from ..utils import parse_readable_size
label_desc: Use image node_id 12 for calling a global function with example usage: get_device_info(dev_index) and returns: info, _device_infos, None, None