Changeset 5709

Show
Ignore:
Timestamp:
11/05/09 13:36:19 (3 weeks ago)
Author:
mercierg
Message:

New binding file for hwloc: matches Hydra's new data structure

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • mpich2/trunk/src/pm/hydra/tools/bind/hwloc/bind_hwloc.c

    r5631 r5709  
    1616HYD_status HYDT_bind_hwloc_init(HYDT_bind_support_level_t * support_level) 
    1717{ 
     18    int node,sock,core,proc,thread; 
     19 
    1820    hwloc_obj_t    obj_sys; 
    1921    hwloc_obj_t    obj_node; 
     
    2123    hwloc_obj_t    obj_core; 
    2224    hwloc_obj_t    obj_proc; 
    23     hwloc_obj_t    prev_obj; 
    24     hwloc_cpuset_t cpuset_sys; 
    25     hwloc_cpuset_t cpuset_node; 
    26     hwloc_cpuset_t cpuset_sock; 
    27     hwloc_cpuset_t cpuset_core; 
    2825 
    29     int node,sock,core,proc,thread; 
    30     int bound,bound2,bound3; 
     26    struct HYDT_topo_obj *node_ptr, *sock_ptr, *core_ptr, *thread_ptr; 
    3127 
    3228    HYD_status status = HYD_SUCCESS;     
     
    3935 
    4036    /* Get the max number of processing elements */ 
    41     HYDT_bind_info.num_procs = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_PROC);    
     37    HYDT_bind_info.total_proc_units = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_PROC);    
    4238 
    43     HYDU_MALLOC(HYDT_bind_info.topology, struct HYDT_topology *, 
    44                 HYDT_bind_info.num_procs * sizeof(struct HYDT_topology), status); 
    45     for (proc = 0; proc < HYDT_bind_info.num_procs; proc++) { 
    46         HYDT_bind_info.topology[proc].processor_id = -1; 
    47         HYDT_bind_info.topology[proc].socket_rank  = -1; 
    48         HYDT_bind_info.topology[proc].socket_id    = -1; 
    49         HYDT_bind_info.topology[proc].core_rank    = -1; 
    50         HYDT_bind_info.topology[proc].core_id      = -1; 
    51         HYDT_bind_info.topology[proc].thread_rank  = -1; 
    52         HYDT_bind_info.topology[proc].thread_id    = -1; 
    53     } 
    54  
    55     proc     = 0; 
    56     prev_obj = NULL; 
    57     while(obj_proc = hwloc_get_next_obj_by_type(topology,HWLOC_OBJ_PROC,prev_obj)) 
    58         { 
    59             HYDT_bind_info.topology[proc].processor_id = obj_proc->os_index; 
    60             prev_obj = obj_proc; 
    61             proc++; 
    62         } 
    63     assert(proc == HYDT_bind_info.num_procs); 
    64      
    6539    /* We have qualified for basic binding support level */ 
    6640    *support_level = HYDT_BIND_BASIC; 
     41    
     42   /* Setup the machine level */    
     43   /* get the System object */ 
     44   obj_sys = hwloc_get_system_obj(topology); 
     45   /* init Hydra structure */ 
     46   HYDT_bind_info.machine.type         = HYDT_TOPO_MACHINE; 
     47   HYDT_bind_info.machine.os_index     = -1; /* This is a set, not a single unit */ 
     48   HYDT_bind_info.machine.parent       = NULL; 
     49   HYDT_bind_info.machine.num_children = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_NODE); 
     50   /* There is no real node, consider there is one */ 
     51   if (!HYDT_bind_info.machine.num_children) 
     52     HYDT_bind_info.machine.num_children = 1; 
     53   HYDU_MALLOC(HYDT_bind_info.machine.children, struct HYDT_topo_obj *, 
     54               sizeof(struct HYDT_topo_obj), status); 
     55   HYDT_bind_info.machine.shared_memory_depth = NULL; 
     56    
     57   /* Setup the nodes levels */ 
     58   for(node = 0 ; node < HYDT_bind_info.machine.num_children ; node++) 
     59     {   
     60        node_ptr         = &HYDT_bind_info.machine.children[node];       
     61        node_ptr->type   =  HYDT_TOPO_NODE;    
     62        node_ptr->parent = &HYDT_bind_info.machine; 
     63        obj_node = hwloc_get_obj_inside_cpuset_by_type(topology,obj_sys->cpuset,HWLOC_OBJ_NODE,node); 
    6764 
    68     /* get the System object */ 
    69     obj_sys = hwloc_get_system_obj(topology); 
    70     cpuset_sys = obj_sys->cpuset; 
     65        if(!obj_node) 
     66          obj_node = obj_sys; 
     67        node_ptr->os_index     = obj_node->os_index;; 
     68        node_ptr->num_children =  hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_node->cpuset,HWLOC_OBJ_SOCKET); 
    7169 
    72     /* Compute the number of sockets per NUMA Node */ 
    73    /* FIX ME : We assume that the number of sockets is the same for each node (e.g node 0)!*/ 
    74    obj_node = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sys,HWLOC_OBJ_NODE,0); 
    75    if(obj_node) 
    76      HYDT_bind_info.num_sockets = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_node->cpuset,HWLOC_OBJ_SOCKET); 
    77    else 
    78      HYDT_bind_info.num_sockets = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_SOCKET); 
    79     
    80    /* Compute the number of cores per socket */ 
    81    /* FIX ME : We assume that the number of CORES is the same for each SOCKET (e.g sock 0)!*/ 
    82    obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,0);       
    83    if(obj_node) 
    84      HYDT_bind_info.num_cores = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE);     
    85    else 
    86      HYDT_bind_info.num_cores = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_CORE); 
    87      
    88     HYDT_bind_info.num_threads = (HYDT_bind_info.num_procs/(hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_CORE)));  
     70        /* In case there is no socket! */ 
     71        if(!node_ptr->num_children) 
     72          node_ptr->num_children = 1; 
     73         
     74        HYDU_MALLOC(node_ptr->children, struct HYDT_topo_obj *, 
     75                    sizeof(struct HYDT_topo_obj) * node_ptr->num_children, status); 
     76        node_ptr->shared_memory_depth = NULL; 
     77                 
     78        /* Setup the socket level */ 
     79        for (sock = 0; sock < node_ptr->num_children ; sock++)  
     80          { 
     81             sock_ptr           = &node_ptr->children[sock]; 
     82             sock_ptr->type     = HYDT_TOPO_SOCKET;           
     83             sock_ptr->parent   = node_ptr; 
     84         
     85             obj_sock = hwloc_get_obj_inside_cpuset_by_type(topology,obj_node->cpuset,HWLOC_OBJ_SOCKET,sock); 
     86             if(!obj_sock) 
     87               obj_sock = obj_node; 
     88              
     89             sock_ptr->os_index     = obj_sock->os_index;          
     90             sock_ptr->num_children = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE); 
     91              
     92             /* In case there is no core! */ 
     93             if(!sock_ptr->num_children) 
     94                 sock_ptr->num_children = 1; 
    8995 
    90     bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_NODE); 
    91     for (proc = 0; proc < HYDT_bind_info.num_procs; proc++) 
    92         { 
    93            if (bound == 0) 
    94              { 
    95                 for(sock = 0, bound2 = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_SOCKET) ;  
    96                     sock < bound2 ;  
    97                     sock++) 
    98                   { 
    99                      obj_sock = obj_sock = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,sock); 
    100                      cpuset_sock  = obj_sock->cpuset; 
    101                       
    102                      if(hwloc_cpuset_isset (cpuset_sock, HYDT_bind_info.topology[proc].processor_id)) 
    103                        { 
    104                           for(core = 0, bound3 = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE) ;  
    105                               core < bound3;  
    106                               core++) 
    107                             { 
    108                                obj_core = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sock,HWLOC_OBJ_CORE,core); 
    109                                cpuset_core  = obj_core->cpuset; 
    110                                 
    111                                if (hwloc_cpuset_isset (cpuset_core, HYDT_bind_info.topology[proc].processor_id)) 
    112                                  { 
    113                                     int j; 
    114                                     /* HYDT_bind_info.topology[proc].node_id   = obj_node->os_index;*/ 
    115                                     HYDT_bind_info.topology[proc].socket_id = obj_sock->os_index; 
    116                                     HYDT_bind_info.topology[proc].core_id   = obj_core->os_index; 
    117                                      
    118                                     thread = -1; 
    119                                     for (j = 0; j < proc; j++) 
    120                                       { 
    121                                          /*  if ((HYDT_bind_info.topology[j].node_id   == obj_node->os_index) &&  
    122                                           (HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) && 
    123                                           (HYDT_bind_info.topology[j].core_id   == obj_core->os_index)) 
    124                                           */ 
    125                                          if ((HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) && 
    126                                              (HYDT_bind_info.topology[j].core_id   == obj_core->os_index)) 
    127                                            thread = HYDT_bind_info.topology[j].thread_id; 
    128                                       } 
    129                                     thread++; 
    130                                     HYDT_bind_info.topology[proc].thread_id   = thread; 
    131                                     HYDT_bind_info.topology[proc].thread_rank = thread; 
    132                                      
    133                                     break; 
    134                                  } 
    135                             } 
    136                        } 
    137                   } 
    138              } 
    139            else 
    140              {           
    141                 for(node = 0;  node < bound ; node++) 
    142                   { 
    143                      obj_node = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sys,HWLOC_OBJ_NODE,node); 
    144                      cpuset_node = obj_node->cpuset; 
    145                       
    146                      if(hwloc_cpuset_isset (cpuset_node, HYDT_bind_info.topology[proc].processor_id)) 
    147                        { 
    148                           for(sock = 0, bound2 = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_node->cpuset,HWLOC_OBJ_SOCKET) ; sock < bound2 ; sock++) 
    149                             { 
    150                                obj_sock = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_node,HWLOC_OBJ_SOCKET,sock); 
    151                                cpuset_sock  = obj_sock->cpuset; 
    152                                 
    153                                if(hwloc_cpuset_isset (cpuset_sock, HYDT_bind_info.topology[proc].processor_id)) 
    154                                  { 
    155                                     for(core = 0, bound3 = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE) ; core < bound3; core+\ 
    156 +) 
    157                                       { 
    158                                          obj_core = hwloc_get_obj_inside_cpuset_by_type(topology,cpuset_sock,HWLOC_OBJ_CORE,core); 
    159                                          cpuset_core  = obj_core->cpuset; 
    160                                           
    161                                          if (hwloc_cpuset_isset (cpuset_core, HYDT_bind_info.topology[proc].processor_id)) 
    162                                            { 
    163                                               int j; 
    164                                               /* HYDT_bind_info.topology[proc].node_id   = obj_node->os_index;*/ 
    165                                               HYDT_bind_info.topology[proc].socket_id = obj_sock->os_index; 
    166                                               HYDT_bind_info.topology[proc].core_id   = obj_core->os_index; 
    167  
    168                                               thread = -1; 
    169                                               for (j = 0; j < proc; j++) 
    170                                                 { 
    171                                                    /*  if ((HYDT_bind_info.topology[j].node_id   == obj_node->os_index) &&  
    172                                                     (HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) && 
    173                                                     (HYDT_bind_info.topology[j].core_id   == obj_core->os_index)) 
    174                                                     */ 
    175                                                    if ((HYDT_bind_info.topology[j].socket_id == obj_sock->os_index) && 
    176                                                        (HYDT_bind_info.topology[j].core_id   == obj_core->os_index)) 
    177                                                      thread = HYDT_bind_info.topology[j].thread_id; 
    178                                                 } 
    179                                               thread++; 
    180                                               HYDT_bind_info.topology[proc].thread_id   = thread; 
    181                                               HYDT_bind_info.topology[proc].thread_rank = thread; 
    182                                                
    183                                               break; 
    184                                            } 
    185                                       } 
    186                                  } 
    187                             } 
    188                            
    189                        } 
    190                   } 
    191              } 
    192         } 
    193     
    194     
    195    /* Get the rank of each node ID */ 
    196    /* 
    197     for(node = 0, bound  = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_NODE) ; node < bound ; node++) 
    198     { 
    199     obj_node  = hwloc_get_obj_by_type(topology,HWLOC_OBJ_NODE,node); 
    200     for (proc = 0; proc < HYDT_bind_info.num_procs; proc++) 
    201     if (HYDT_bind_info.topology[proc].node_id == obj_node->os_index) 
    202                     HYDT_bind_info.topology[proc].node_rank = node; 
    203     } 
    204     */ 
    205     
    206    /* Get the rank of each socket ID */ 
    207    for(sock = 0, bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_SOCKET) ; sock < bound; sock++) 
    208      { 
    209         obj_sock  = hwloc_get_obj_by_type(topology,HWLOC_OBJ_SOCKET,sock); 
    210         for (proc = 0; proc < HYDT_bind_info.num_procs; proc++)  
    211           if (HYDT_bind_info.topology[proc].socket_id == obj_sock->os_index) 
    212             HYDT_bind_info.topology[proc].socket_rank = sock; 
    213      } 
    214     
    215    /* Find the rank of each core ID */ 
    216    for (core = 0, bound = hwloc_get_nbobjs_by_type(topology,HWLOC_OBJ_CORE); core < bound ; core++)  
    217      { 
    218         obj_core  = hwloc_get_obj_by_type(topology,HWLOC_OBJ_CORE,core); 
    219         for (proc = 0; proc < HYDT_bind_info.num_procs; proc++)  
    220           if (HYDT_bind_info.topology[proc].core_id == obj_core->os_index) 
    221             HYDT_bind_info.topology[proc].core_rank = core; 
     96             HYDU_MALLOC(sock_ptr->children, struct HYDT_topo_obj *, 
     97                         sizeof(struct HYDT_topo_obj) * sock_ptr->num_children, status); 
     98             sock_ptr->shared_memory_depth = NULL; 
     99              
     100             /* setup the core level */ 
     101             for (core = 0; core < sock_ptr->num_children; core++)  
     102               {              
     103                  core_ptr               = &sock_ptr->children[core]; 
     104                  core_ptr->type         = HYDT_TOPO_CORE; 
     105                  core_ptr->parent       = sock_ptr; 
     106                   
     107                  obj_core = hwloc_get_obj_inside_cpuset_by_type(topology,obj_sock->cpuset,HWLOC_OBJ_CORE,core);                   
     108                  if(!obj_core) 
     109                    obj_core = obj_sock; 
     110                   
     111                  core_ptr->os_index     = obj_core->os_index;     
     112                  core_ptr->num_children = hwloc_get_nbobjs_inside_cpuset_by_type(topology,obj_core->cpuset,HWLOC_OBJ_PROC); 
     113                                   
     114                  HYDU_MALLOC(core_ptr->children, struct HYDT_topo_obj *, 
     115                              sizeof(struct HYDT_topo_obj) * core_ptr->num_children, status); 
     116                  core_ptr->shared_memory_depth = NULL; 
     117                   
     118                  /* setup the thread level */ 
     119                  for (thread = 0; thread < core_ptr->num_children; thread++)  
     120                    {                   
     121                        obj_proc = hwloc_get_obj_inside_cpuset_by_type(topology,obj_core->cpuset,HWLOC_OBJ_PROC,thread);                   
     122                        thread_ptr                      = &core_ptr->children[thread]; 
     123                        thread_ptr->type                = HYDT_TOPO_THREAD; 
     124                        thread_ptr->os_index            = obj_proc->os_index; 
     125                        thread_ptr->parent              = core_ptr; 
     126                        thread_ptr->num_children        = 0; 
     127                        thread_ptr->children            = NULL; 
     128                        thread_ptr->shared_memory_depth = NULL; 
     129                        
     130                       /* 
     131                        fprintf(stdout," thread id %i | Core id %i | Socket id %i | Node id %i \n", 
     132                        obj_proc->os_index,obj_core->os_index,obj_sock->os_index,obj_node->os_index); 
     133                        */  
     134                    } 
     135                   
     136               } 
     137          } 
    222138     } 
    223139    
    224140   /* We have qualified for topology-aware binding support level */ 
    225141   *support_level = HYDT_BIND_TOPO; 
    226     
     142 
    227143   fn_exit: 
    228144   HYDU_FUNC_EXIT(); 
     
    256172    
    257173  fn_exit: 
    258    hwloc_cpuset_free(cpuset); 
     174    hwloc_cpuset_free(cpuset); 
    259175    HYDU_FUNC_EXIT(); 
    260176    return status;