code: def _group_cpu_cores(cpu_socket_gpus_list):
      """
      Generate a dictionary that 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.
      The grouping way is collect cpu cores every #GPUs-th elements, due to index of hyperthreading.
      For examle, 4 physical cores, 8 cores with hyperthreading. The CPU indices [0, 1, 2, 3] is
      physical cores, and [4, 5, 6, 7] is hyperthreading. In this case, distributing physical cores
      first, then hyperthreading would reach better performance.
      Args:
          cpu_socket_gpus_list (dict): a dict that map cpu_affinity_str to all GPUs that belong to it.
      Return:
          cpu_core_groups (dict): a dict that map cpu_affinity_str to cpu core groups.
      Example:
          cpu_socket_gpus_list = { '0-9,20-29': [0, 1], '10-19,30-39': [2, 3] },
          which means there are 2 GPUs, 0 and 1, belong to '0-9,20-29' and
          2 GPUs, 2 and 3, belong to '10-19,30-39'
          therefore, cpu_core_groups =
                  {'0-9,20-29': [
                                 [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]],
                                 [[20, 22, 24, 26, 28], [21, 23, 25, 27, 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]]
                                  ]}
  
      """
      cpu_core_groups = dict()
      for cpu_socket in cpu_socket_gpus_list:
          cpu_core_groups[cpu_socket] = list()
          gpu_count = len(cpu_socket_gpus_list[cpu_socket])
          cores = cpu_socket.split(",")
          for core in cores:
              core_indices = _get_core_indices(core)
              core_group = list()
              for i in range(gpu_count):
                  start = i % len(core_indices)
                  sub_core_set = core_indices[start::gpu_count]
                  core_group.append(sub_core_set)
              cpu_core_groups[cpu_socket].append(core_group)
      return cpu_core_groups
  
imports: import os
  import logging
  import paddle
label_desc: Use image node_id 2 for calling a global function with example usage: _group_cpu_cores(cpu_socket_gpus_list) and returns: cpu_core_groups