code: def _get_gpu_affinity_table():
      """
      Generate three dict objects, gpu_cpu_affinity_map, cpu_socket_gpus_list, cpu_core_groups.
      gpu_cpu_affinity_map (dict): Key is GPU ID and value is cpu_affinity string.
      cpu_socket_gpus_list (dict): Key is cpu_affinity string and value is  a list
                                   collected all GPU IDs that affinity to this cpu socket.
      cpu_core_groups (dict):      Key is cpu_affinity string and value is cpu core groups.
                                   cpu core groups contains #GPUs groups, each group have,
                                   nearly eaual amount of cpu cores.
  
      Example:
          $nvidia-smi topo -m
              GPU0    GPU1    GPU2    GPU3    CPU Affinity    NUMA Affinity
          GPU0     X     SYS     SYS     SYS      0-9,20-29           0
          GPU1   SYS       X     SYS     SYS      0-9,20-29           0
          GPU2   SYS      SYS      X     SYS      10-19,30-39         1
          GPU3   SYS      SYS    SYS       X      10-19,30-39         1
  
          gpu_cpu_affinity_map =
              { 0: '0-9,20-29', # GPU0's cpu affninity is '0-9,20-29'
                1: '0-9,20-29', # GPU1's cpu affninity is '0-9,20-29'
                2: '10-19,30-39', # GPU2's cpu affninity is '10-19,30-39'
                3: '10-19,30-39' } # GPU3's cpu affninity is '10-19,30-39'
          cpu_socket_gpus_list =
              { '0-9,20-29': [0, 1], # There are 2 GPUs, 0 and 1, belong to cpu affinity '0-9,20-29'.
                '10-19,30-39': [2, 3] # There are 2 GPUs, 2 and 3, belong to cpu affinity '10-19,30-39'.
              }
          cpu_core_groups =
              # There are 2 GPUs belong to cpu affinity '0-9,20-29', then
              # cores [0, 1, ..., 8, 9] would be split to two groups every
              # 2-th elements
              # [0, 2, 4, 6, 8] and [1, 3, 5, 7, 9]
              # The same for cores [20, 21, ..., 28, 29].
              {'0-9,20-29': [
                                 [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]],
                                 [[20, 22, 24, 26, 28], [21, 23, 25, 27, 29]]
                                ],
              # The same as '0-9,20-29'
              '10-19,30-39': [
                              [[10, 12, 14, 16, 18], [11, 13, 15, 17, 19]],
                              [[30, 32, 34, 36, 38], [31, 33, 35, 37, 39]]
                             ]}
  
      """
      lines = os.popen("nvidia-smi topo -m").readlines()
  
      cpu_affinity_idx = -1
      titles = lines[0].split("\t")
      for idx in range(len(titles)):
          if "CPU Affinity" in titles[idx]:
              cpu_affinity_idx = idx
      assert (
          cpu_affinity_idx > 0
      ), "Can not obtain correct CPU affinity column index via nvidia-smi!"
  
      gpu_cpu_affinity_map = dict()
      cpu_socket_gpus_list = dict()
      # Skip title
      for idx in range(1, len(lines)):
          line = lines[idx]
          items = line.split("\t")
  
          if "GPU" in items[0]:
              gpu_id = int(items[0][3:])
              affinity = items[cpu_affinity_idx]
              gpu_cpu_affinity_map[gpu_id] = affinity
              if affinity in cpu_socket_gpus_list:
                  cpu_socket_gpus_list[affinity].append(gpu_id)
              else:
                  cpu_socket_gpus_list[affinity] = [gpu_id]
  
      cpu_core_groups = _group_cpu_cores(cpu_socket_gpus_list)
      return gpu_cpu_affinity_map, cpu_socket_gpus_list, cpu_core_groups
  
imports: import os
  import logging
  import paddle
label_desc: Use image node_id 1 for calling a global function with example usage: _get_gpu_affinity_table() and returns: gpu_cpu_affinity_map,  cpu_socket_gpus_list,  cpu_core_groups