Example #1
0
void Topology::set_thread_cpubind(identifier_type numa_node){
#ifdef M3BP_LOCALITY_ENABLED
	const auto num_nodes = m_available_numa_nodes.size();
	assert(numa_node < num_nodes);
	hwloc_obj_t obj;
	if(num_nodes == 1){
		obj = hwloc_get_obj_by_type(m_topology, HWLOC_OBJ_MACHINE, 0);
		if(!obj){
			throw std::runtime_error(
				"An error occured on "
				"`hwloc_get_obj_by_type(HWLOC_OBJ_MACHINE)`");
		}
	}else{
		obj = hwloc_get_obj_by_type(
			m_topology, HWLOC_OBJ_NODE, m_available_numa_nodes[numa_node]);
		if(!obj){
			throw std::runtime_error(
				"An error occured on `hwloc_get_obj_by_type(HWLOC_OBJ_NODE)`");
		}
	}
	if(hwloc_set_cpubind(m_topology, obj->cpuset, HWLOC_CPUBIND_THREAD) != 0){
		throw std::runtime_error("An error occured on `hwloc_set_cpubind()`");
	}
#	ifdef M3BP_NO_THREAD_LOCAL
	g_ts_binded_node.get() = numa_node;
#	else
	g_binded_node = numa_node;
#	endif
#else
	(void)(numa_node);
#endif
}
Example #2
0
void qrm_hwloc_topo(int *nodes, int *topo)
{
  int depth, ret;
  unsigned i, n, j, ncores, nnodes, cnode;
  int topodepth, numa;
  hwloc_topology_t topology;
  hwloc_cpuset_t cpuset;
  hwloc_obj_t obj, cobj;
  hwloc_obj_type_t otype;
  
  hwloc_topology_init(&topology);
  
  hwloc_topology_load(topology);

  /* get the number os cores and NUMA nodes */
  ncores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
  printf("ncores: %d\n",ncores);

  nnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NODE);
  if(nnodes == 0){
    otype = HWLOC_OBJ_SOCKET;
    printf("grouping with sockets\n");
    nnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_SOCKET);
  } else {
    otype = HWLOC_OBJ_NODE;
    printf("grouping with NUMA nodes\n");
  }

  /* get the handle for the first NUMA node */
  obj = hwloc_get_obj_by_type(topology, otype, 0); 
  
  /* get the number of cores in one NUMA node (supposedly the same for all nodes) */
  cnode = hwloc_get_nbobjs_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE);
  
  for(i=0; i<nnodes; i++){
    /* get the handle for the first i-th node */
    obj = hwloc_get_obj_by_type(topology, otype, i);
    /* get the number of cores in i-th NUMA node (supposedly the same for all nodes) */
    cnode = hwloc_get_nbobjs_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE);

    /* get the first core in this node */
    cobj = hwloc_get_next_obj_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE, NULL);
    topo[(i*cnode)] = cobj->logical_index;
    /* printf("%2d -- group:  %2d",i,cobj->logical_index); */
    for(j=1; j<cnode; j++){
      cobj = hwloc_get_next_obj_inside_cpuset_by_type(topology, obj->cpuset, HWLOC_OBJ_CORE, cobj);
      topo[(i*cnode)+j] = cobj->logical_index;
      /* printf(" %2d",cobj->logical_index); */
    }
    /* printf("\n"); */
  }
  
  
  hwloc_topology_destroy(topology);
  return;
}
Example #3
0
signed getNodeForCore(unsigned core) {
  hwloc_topology_t topology = getHWTopology();
  unsigned nodes = getNumberOfNodes(topology);
  hwloc_obj_t core_obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, core);
  for (unsigned i = 0; i < nodes; i++) {
    hwloc_obj_t obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, i);
    if (hwloc_obj_is_in_subtree(topology, core_obj, obj)) {
      return i;
    }
  }
  return -1;
}
Example #4
0
unsigned getNodeForCore(unsigned core){
  hwloc_topology_t topology = getHWTopology();
  unsigned nodes = getNumberOfNodes(topology);
  hwloc_obj_t obj;
  hwloc_obj_t core_obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, core);
  for(unsigned i = 0; i < nodes; i++){
    obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, i);
    if (hwloc_obj_is_in_subtree(topology, core_obj, obj)){
      return i;
    }
  }
  throw std::runtime_error("expected to find node for core");
}
Example #5
0
void 
darts :: hwloc :: AbstractMachine :: discoverTopologyWithLLC(void)
{
    unsigned nbSockets = hwloc_get_nbobjs_by_type(_topology,HWLOC_OBJ_SOCKET);
    hwloc_obj_t o = hwloc_get_obj_by_type(_topology,HWLOC_OBJ_SOCKET,0);

    hwloc_obj_t obj;
    for (obj = o->first_child;
            obj && obj->type != HWLOC_OBJ_CACHE;
            obj = obj->first_child)
        ;

    _nbClusters = nbSockets;
    if (obj) {
        int n = hwloc_get_nbobjs_inside_cpuset_by_type(_topology,obj->cpuset,HWLOC_OBJ_PU);
        _nbClusters = _nbTotalUnits / n; // XXX assumes homogeneous distribution of PUs
    }
    _clusterMap = new Cluster[_nbClusters];

    // TODO Refactor this code and the next function's code into a single one 
    for (o = obj; o; o = o->next_cousin)  {
        int           nUnits = hwloc_get_nbobjs_inside_cpuset_by_type(_topology,o->cpuset,HWLOC_OBJ_PU);
        Unit *units  = new Unit[nUnits];
        for (int i = 0; i < nUnits; ++i) {
            hwloc_obj_t t = hwloc_get_obj_inside_cpuset_by_type(_topology,o->cpuset,HWLOC_OBJ_PU,i);
            Unit hwu(o->logical_index,t->logical_index,t->os_index);
            units[i] = hwu; // simple shallow copy
        }
        Cluster cluster(o->logical_index,o->logical_index,nUnits,units);
        _clusterMap[o->logical_index] = cluster; // simple shallow copy
    }
}
Example #6
0
void AbstractCoreBoundTaskQueue::launchThread(int core) {
    //get the number of cores on system
    int NUM_PROCS = getNumberOfCoresOnSystem();

    if (core < NUM_PROCS) {
        _thread = new std::thread(&AbstractTaskQueue::executeTask, this);
        hwloc_cpuset_t cpuset;
        hwloc_obj_t obj;
        hwloc_topology_t topology = getHWTopology();

        obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, core);
        // the bitmap to modify
        cpuset = hwloc_bitmap_dup(obj->cpuset);
        // remove hyperthreads
        hwloc_bitmap_singlify(cpuset);
        // bind
        if (hwloc_set_thread_cpubind(topology, _thread->native_handle(), cpuset, HWLOC_CPUBIND_STRICT | HWLOC_CPUBIND_NOMEMBIND)) {
            char *str;
            int error = errno;
            hwloc_bitmap_asprintf(&str, obj->cpuset);
            fprintf(stderr, "Couldn't bind to cpuset %s: %s\n", str, strerror(error));
            fprintf(stderr, "Continuing as normal, however, no guarantees\n");
            //throw std::runtime_error(strerror(error));
        }

        hwloc_bitmap_free(cpuset);

    } else {
        // this case should never happen, as TaskQueue is only initialized from SimpleTaskScheduler, which captures this case
        throw std::logic_error("CPU to run thread on is larger than number of total cores; seems that TaskQueue was initialized outside of SimpleTaskScheduler, which should not happen");
    }
}
Example #7
0
    std::size_t hwloc_topology::init_node_number(
        std::size_t num_thread, hwloc_obj_type_t type
        )
    { // {{{
        if (std::size_t(-1) == num_thread)
            return std::size_t(-1);

        std::size_t num_pu = num_thread % num_of_pus_;

        {
            hwloc_obj_t obj;

            {
                scoped_lock lk(topo_mtx);
                obj = hwloc_get_obj_by_type(topo, HWLOC_OBJ_PU,
                    static_cast<unsigned>(num_pu));
            }

            while (obj)
            {
                if (hwloc_compare_types(obj->type, type) == 0)
                {
                    // on Windows os_index is always -1
                    if (obj->logical_index == ~0x0u)
                        return static_cast<std::size_t>(obj->os_index);

                    return static_cast<std::size_t>(obj->logical_index);
                }
                obj = obj->parent;
            }
        }
        return 0;
    } // }}}
Example #8
0
/*
 * Get the number of net cards in a NUMA node
 */
int hw_get_nnetcards(int NUMAnode)
{
  int count, net_NUMAnode, error;
  hwloc_obj_t obj, obj_anc;

 count = 0;
 hwloc_topology_t topo_net;
 error = hwloc_topology_init(&topo_net);
 hwloc_topology_set_flags(topo_net, HWLOC_TOPOLOGY_FLAG_IO_DEVICES);
 if (!error){
    hwloc_topology_load(topo_net);
    for (obj = hwloc_get_obj_by_type(topo_net, HWLOC_OBJ_OS_DEVICE, 0);
         obj;
         obj = hwloc_get_next_osdev(topo_net,obj))
         if (obj->attr->osdev.type == HWLOC_OBJ_OSDEV_NETWORK ||
             obj->attr->osdev.type == HWLOC_OBJ_OSDEV_OPENFABRICS){
             obj_anc = hwloc_get_non_io_ancestor_obj(topo_net,obj);
             net_NUMAnode = hwloc_bitmap_first(obj_anc->nodeset);
             //only if the MPI NUMA node is equal to the found net card
               if(NUMAnode == net_NUMAnode)
                 count++;
         }        
  }         
  hwloc_topology_destroy(topo_net);

  return count;
}
Example #9
0
Topology::Topology()
	: m_topology(initialize_topology())
	, m_available_processing_units(enumerate_processing_units(m_topology))
	, m_available_numa_nodes(enumerate_numa_nodes(m_topology))
	, m_processing_units_per_node(m_available_numa_nodes.size())
{
	const auto num_nodes = m_available_numa_nodes.size();
	for(const auto pu : m_available_processing_units){
		if(num_nodes == 1){
			++m_processing_units_per_node[0];
		}else{
			auto obj = hwloc_get_obj_by_type(m_topology, HWLOC_OBJ_PU, pu);
			while(obj && obj->type != HWLOC_OBJ_NODE){ obj = obj->parent; }
			if(obj && obj->type == HWLOC_OBJ_NODE){
				const auto it = std::find(
					m_available_numa_nodes.begin(),
					m_available_numa_nodes.end(),
					obj->logical_index);
				const auto index = it - m_available_numa_nodes.begin();
				++m_processing_units_per_node[index];
			}else{
				++m_processing_units_per_node[0];
			}
		}
	}
}
Example #10
0
    mask_type hwloc_topology::init_socket_affinity_mask_from_socket(
        std::size_t num_socket
        ) const
    { // {{{
        // If we have only one or no socket, the socket affinity mask
        // spans all processors
        if (std::size_t(-1) == num_socket)
            return machine_affinity_mask_;

        hwloc_obj_t socket_obj;

        {
            scoped_lock lk(topo_mtx);
            socket_obj = hwloc_get_obj_by_type(topo,
                HWLOC_OBJ_SOCKET, static_cast<unsigned>(num_socket));
        }

        if (socket_obj)
        {
            mask_type socket_affinity_mask = 0;
            extract_node_mask(socket_obj, socket_affinity_mask);
            return socket_affinity_mask;
        }

        return machine_affinity_mask_;
    } // }}}
Example #11
0
    mask_type hwloc_topology::init_numa_node_affinity_mask_from_numa_node(
        std::size_t numa_node
        ) const
    { // {{{
        // If we have only one or no NUMA domain, the NUMA affinity mask
        // spans all processors
        if (std::size_t(-1) == numa_node)
        {
            return machine_affinity_mask_;
        }

        hwloc_obj_t numa_node_obj;

        {
            scoped_lock lk(topo_mtx);
            numa_node_obj = hwloc_get_obj_by_type(topo,
                HWLOC_OBJ_NODE, static_cast<unsigned>(numa_node));
        }

        if (numa_node_obj)
        {
            mask_type node_affinity_mask = 0;
            extract_node_mask(numa_node_obj, node_affinity_mask);
            return node_affinity_mask;
        }

        return machine_affinity_mask_;
    } // }}}
Example #12
0
    mask_type hwloc_topology::init_thread_affinity_mask(
        std::size_t num_thread
        ) const
    { // {{{

        if (std::size_t(-1) == num_thread)
        {
            return get_core_affinity_mask(num_thread, false);
        }

        std::size_t num_pu = num_thread % num_of_pus_;

        hwloc_obj_t obj;

        {
            scoped_lock lk(topo_mtx);
            obj = hwloc_get_obj_by_type(topo, HWLOC_OBJ_PU,
                    static_cast<unsigned>(num_pu));
        }

        if (!obj)
        {
            return get_core_affinity_mask(num_thread, false);
        }

        mask_type mask = 0x0u;

        mask |= (static_cast<mask_type>(1) << obj->os_index);

        return mask;
    } // }}}
Example #13
0
/* Wrapper routines for hwloc */
void qrm_hwloc_bind(int id)
{
  int depth, ret;
  unsigned i, n;
  int topodepth;
  hwloc_topology_t topology;
  hwloc_cpuset_t cpuset;
  hwloc_obj_t obj;
  
  hwloc_topology_init(&topology);
  
  hwloc_topology_load(topology);
  
  obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, id); 
  
  ret = hwloc_set_cpubind(topology, obj->cpuset, HWLOC_CPUBIND_THREAD);
  if (ret) {
    printf("Couldn't bind to core %d\n", id); 
    assert(0);
  } else {
    printf("Bound to core %d\n", id); 
  }    
  
  hwloc_topology_destroy(topology);
  
  return;
}
Example #14
0
/*
* Set the memory policy for data allocation for a process
*/
int hw_set_mempol(int mempol, int node)
{
  int error;

  switch(mempol)
  {
   case OS:
    if (local_topo->nnodes != 0 ){
      hwloc_obj_t obj;
      obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_MACHINE,0);
      error = hwloc_set_membind_nodeset(topology,obj->nodeset,HWLOC_MEMBIND_FIRSTTOUCH,0);
     }     
   break;
   case LOCAL:
     if (local_topo->nnodes != 0 ){
      node =  hw_get_proc_node(); 
      hwloc_obj_t obj;
      obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, node);
      error = hwloc_set_membind_nodeset(topology,obj->nodeset,HWLOC_MEMBIND_BIND,0);
     }
  break;
   case INTERLEAVE:
    if (local_topo->nnodes != 0 ){
      node =  hw_get_proc_node();      
      hwloc_obj_t obj;
      obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, node);
      obj = obj->parent;
      error = hwloc_set_membind_nodeset(topology,obj->nodeset,HWLOC_MEMBIND_INTERLEAVE,0);
    }    
   break;
   case MANUAL:
     if (local_topo->nnodes != 0 ){
      if (node == -1) 
        node =  hw_get_proc_node();  
      hwloc_obj_t obj;
      obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, node);
      error = hwloc_set_membind_nodeset(topology,obj->nodeset,HWLOC_MEMBIND_BIND,0);
     }
   break;
   default:
     error = 1;
   break;
  }
 return error;
}
Example #15
0
static inline const char *get_hn (hwloc_topology_t topo)
{
    hwloc_obj_t obj;
    const char *hn = NULL;
    obj = hwloc_get_obj_by_type (topo, HWLOC_OBJ_MACHINE, 0);
    if (obj)
        hn = hwloc_obj_get_info_by_name (obj, "HostName");
    return hn;
}
Example #16
0
std::vector<unsigned> getCoresForNode(hwloc_topology_t topology, unsigned node){
  std::vector<unsigned> children;
  unsigned number_of_cores;
  // get hwloc obj for node
  hwloc_obj_t obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, node);
  // get all cores and check whether core is in subtree of node, if yes, push to vector
  // get number of cores by type
  number_of_cores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
  // iterate over cores and check whether in subtree
  hwloc_obj_t core;
  for(unsigned i = 0; i < number_of_cores; i++){
    core = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, i);
    if(hwloc_obj_is_in_subtree(topology, core, obj)){
      children.push_back(core->logical_index);
    }
  }
  return children;
}
Example #17
0
void bindCurrentThreadToNumaNode(int node) {
  hwloc_topology_t topology = getHWTopology();
  hwloc_cpuset_t cpuset;
  hwloc_obj_t obj;

  // The actual node
  obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, node);

  // obj is nullptr on non NUMA machines
  if (obj == nullptr) {
    fprintf(stderr, "Couldn't get hwloc object, bindCurrentThreadToNumaNode failed!\n");
    return;
  }

  cpuset = hwloc_bitmap_dup(obj->cpuset);
  // hwloc_bitmap_singlify(cpuset);

  // bind
  if (hwloc_set_cpubind(topology, cpuset, HWLOC_CPUBIND_STRICT | HWLOC_CPUBIND_NOMEMBIND | HWLOC_CPUBIND_THREAD)) {
    char* str;
    int error = errno;
    hwloc_bitmap_asprintf(&str, obj->cpuset);
    printf("Couldn't bind to cpuset %s: %s\n", str, strerror(error));
    free(str);
    throw std::runtime_error(strerror(error));
  }

  // free duplicated cpuset
  hwloc_bitmap_free(cpuset);

  // assuming single machine system
  obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_MACHINE, 0);
  // set membind policy interleave for this thread
  if (hwloc_set_membind_nodeset(
          topology, obj->nodeset, HWLOC_MEMBIND_INTERLEAVE, HWLOC_MEMBIND_STRICT | HWLOC_MEMBIND_THREAD) && errno != ENOSYS) {
    char* str;
    int error = errno;
    hwloc_bitmap_asprintf(&str, obj->nodeset);
    fprintf(stderr, "Couldn't membind to nodeset  %s: %s\n", str, strerror(error));
    fprintf(stderr, "Continuing as normal, however, no guarantees\n");
    free(str);
  }
}
/****** binding_support/get_number_of_cores() **************************************
*  NAME
*     get_number_of_cores() -- Get number of cores per socket.
*
*  SYNOPSIS
*     int get_number_of_cores(int socket_number)
*
*  FUNCTION
*     Returns the number of cores for a specific socket.
*
*  INPUTS
*     int socket_number - Logical socket number starting at 0.
*
*  RESULT
*     int - Amount of cores for the given socket or 0.
*
*  NOTES
*     MT-NOTE: get_number_of_cores() is MT safe
*
*******************************************************************************/
int get_number_of_cores(int socket_number)
{
#if HAVE_HWLOC
  hwloc_obj_t socket = hwloc_get_obj_by_type(sge_hwloc_topology,
                                             HWLOC_OBJ_SOCKET, socket_number);
  if (socket)
    return count_type_under(socket, HWLOC_OBJ_CORE);
  else
#endif
    return 0;
}
Example #19
0
/*
* Get the phys ids for cores
*/
void get_phys_id(hwloc_topology_t topology, int ncores,int cur_core)
{
    unsigned i;
    hwloc_obj_t obj;

    for (i = 0; i < ncores; i++){
       obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, i);
       phys_cpus[cur_core] = obj->os_index;
       cur_core++;
    }
}
inline void __pact_hwloc_init() {
    hwloc_topology_init(&__pact_topo);
      hwloc_topology_load(__pact_topo);

        hwloc_obj_t obj;
          __pact_cache_size = 0;

            for (obj = hwloc_get_obj_by_type(__pact_topo, HWLOC_OBJ_PU, 0); obj; obj = obj->parent) {
                  if (obj->type == HWLOC_OBJ_CACHE)
                          __pact_cache_size += obj->attr->cache.size;
                    }
}
void __spm_init() {
  SPMR_DEBUG(std::cout << "Runtime: initialize\n");
  hwloc_topology_init(&__spm_topo);
  hwloc_topology_load(__spm_topo);

  hwloc_obj_t obj;
  for (obj = hwloc_get_obj_by_type(__spm_topo, HWLOC_OBJ_PU, 0); obj;
       obj = obj->parent)
    if (obj->type == HWLOC_OBJ_CACHE)
      __spm_cache_size += obj->attr->cache.size;

}
Example #22
0
std::vector<unsigned> getCoresForNode(hwloc_topology_t topology, unsigned node) {
  std::vector<unsigned> children;

  // get number of cores by type
  unsigned number_of_cores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
  hwloc_obj_t obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, node);
  if (obj == nullptr) {  // in case there is no node...
    children.resize(number_of_cores);
    std::iota(children.begin(), children.end(), 0);
    return children;
  }

  // get all cores and check whether core is in subtree of node, if yes, push to vector
  // iterate over cores and check whether in subtree
  for (unsigned i = 0; i < number_of_cores; i++) {
    hwloc_obj_t core = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, i);
    if (hwloc_obj_is_in_subtree(topology, core, obj)) {
      children.push_back(core->logical_index);
    }
  }
  return children;
}
Example #23
0
std::vector<hwloc_cpuset_t> getCPUSetsForNode(hwloc_topology_t topology, unsigned node) {
  std::vector<hwloc_cpuset_t> children;

  // get number of cores by type
  unsigned number_of_cores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
  hwloc_obj_t obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NODE, node);
  if (obj == nullptr) {  // in case there is no node...
    for (unsigned i = 0; i < number_of_cores; i++) {
      hwloc_obj_t core = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, i);
      children.push_back(core->cpuset);
    }
    return children;
  }

  // get all cores and check whether core is in subtree of node, if yes, push to vector
  // iterate over cores and check whether in subtree
  for (unsigned i = 0; i < number_of_cores; i++) {
    hwloc_obj_t core = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, i);
    if (hwloc_obj_is_in_subtree(topology, core, obj)) {
      children.push_back(core->cpuset);
    }
  }
  return children;
}
Example #24
0
void hwloc_init_cpuInfo(cpu_set_t cpuSet)
{
    int i;
    hwloc_obj_t obj;

    hwloc_topology_init(&hwloc_topology);
    hwloc_topology_set_flags(hwloc_topology, HWLOC_TOPOLOGY_FLAG_WHOLE_IO );
    hwloc_topology_load(hwloc_topology);
    obj = hwloc_get_obj_by_type(hwloc_topology, HWLOC_OBJ_SOCKET, 0);

    cpuid_info.model = 0;
    cpuid_info.family = 0;
    cpuid_info.isIntel = 0;
    cpuid_info.osname = malloc(MAX_MODEL_STRING_LENGTH * sizeof(char));
    for(i=0;i<obj->infos_count;i++)
    {
        if (strcmp(obj->infos[i].name ,"CPUModelNumber") == 0)
        {
            cpuid_info.model = atoi(hwloc_obj_get_info_by_name(obj, "CPUModelNumber"));
        }
        else if (strcmp(obj->infos[i].name, "CPUFamilyNumber") == 0)
        {
            cpuid_info.family = atoi(hwloc_obj_get_info_by_name(obj, "CPUFamilyNumber"));
        }
        else if (strcmp(obj->infos[i].name, "CPUVendor") == 0 &&
                strcmp(hwloc_obj_get_info_by_name(obj, "CPUVendor"), "GenuineIntel") == 0)
        {
            cpuid_info.isIntel = 1;
        }
        else if (strcmp(obj->infos[i].name ,"CPUModel") == 0)
        {
            strcpy(cpuid_info.osname, obj->infos[i].value);
        }
    }
    cpuid_topology.numHWThreads = hwloc_get_nbobjs_by_type(hwloc_topology, HWLOC_OBJ_PU);
    cpuid_info.stepping = get_stepping();
    DEBUG_PRINT(DEBUGLEV_DEVELOP, HWLOC CpuInfo Family %d Model %d Stepping %d isIntel %d numHWThreads %d activeHWThreads %d,
                            cpuid_info.family,
                            cpuid_info.model,
                            cpuid_info.stepping,
                            cpuid_info.isIntel,
                            cpuid_topology.numHWThreads,
                            cpuid_topology.activeHWThreads)
    return;
}
Example #25
0
/*
 * Make a layout string of all available sockets and cores.  Note that
 * this is *everything* -- not just the ones that are available to
 * this process.
 *
 * Example: [../..]
 * Key:  [] - signifies socket
 *        / - signifies core
 *        . - signifies PU
 */
static int get_layout_exists(char str[OMPI_AFFINITY_STRING_MAX])
{
    int core_index, pu_index;
    int len = OMPI_AFFINITY_STRING_MAX;
    hwloc_obj_t socket, core, pu;

    str[0] = '\0';

    /* Iterate over all existing sockets */
    for (socket = hwloc_get_obj_by_type(opal_hwloc_topology,
                                        HWLOC_OBJ_SOCKET, 0);
         NULL != socket;
         socket = socket->next_cousin) {
        strncat(str, "[", len - strlen(str));

        /* Iterate over all existing cores in this socket */
        core_index = 0;
        for (core = hwloc_get_obj_inside_cpuset_by_type(opal_hwloc_topology,
                                                        socket->cpuset,
                                                        HWLOC_OBJ_CORE, core_index);
             NULL != core;
             core = hwloc_get_obj_inside_cpuset_by_type(opal_hwloc_topology,
                                                        socket->cpuset,
                                                        HWLOC_OBJ_CORE, ++core_index)) {
            if (core_index > 0) {
                strncat(str, "/", len - strlen(str));
            }

            /* Iterate over all existing PUs in this core */
            pu_index = 0;
            for (pu = hwloc_get_obj_inside_cpuset_by_type(opal_hwloc_topology,
                                                          core->cpuset,
                                                          HWLOC_OBJ_PU, pu_index);
                 NULL != pu;
                 pu = hwloc_get_obj_inside_cpuset_by_type(opal_hwloc_topology,
                                                          core->cpuset,
                                                          HWLOC_OBJ_PU, ++pu_index)) {
                strncat(str, ".", len - strlen(str));
            }
        }
        strncat(str, "]", len - strlen(str));
    }

    return OMPI_SUCCESS;
}
Example #26
0
/*
*Get the direct siblings of a core - it is allways considering cache sharing
* index:     the logical id of the core
* myid:      the physical id of the core
* obj:       the HWLOC representation of the core
* nsiblings: the number of siblings of the core 
*/
void set_phys_siblings(int index, unsigned myid, hwloc_obj_t obj, int ncores, int nsiblings,int type)
{
  int i,j = 0;
  hwloc_obj_t obj2, ant;

  for(i = 0; i< ncores && nsiblings > 0 ; i++)
   {
         obj2 = hwloc_get_obj_by_type(topology,type,i);
         ant =  hwloc_get_common_ancestor_obj(topology,obj,obj2);       

         if(ant->type == HWLOC_OBJ_CACHE && obj2->os_index != myid)
         {
            machine_cores[index].siblings_id[j] = obj2->os_index;
            j++; nsiblings--;
            ant = NULL;
	 }  
   }
}
Example #27
0
void 
darts :: hwloc :: AbstractMachine :: discoverTopology(void)
{
    _nbClusters   = hwloc_get_nbobjs_by_type(_topology,HWLOC_OBJ_SOCKET);
    _clusterMap   = new Cluster[_nbClusters];
    hwloc_obj_t o = hwloc_get_obj_by_type(_topology,HWLOC_OBJ_SOCKET,0);
    // TODO Refactor this code and the previous function's code into a single one
    for (; o; o = o->next_cousin)  {
        int           nUnits = hwloc_get_nbobjs_inside_cpuset_by_type(_topology,o->cpuset,HWLOC_OBJ_PU);
        Unit *units  = new Unit[nUnits];
        for (int i = 0; i < nUnits; ++i) {
            hwloc_obj_t t = hwloc_get_obj_inside_cpuset_by_type(_topology,o->cpuset,HWLOC_OBJ_PU,i);
            Unit hwu(o->logical_index,t->logical_index,t->os_index);
            units[i] = hwu; // simple shallow copy
        }
        Cluster cluster(o->logical_index,o->logical_index,nUnits,units);
        _clusterMap[o->logical_index] = cluster; // simple shallow copy
    }
}
Example #28
0
    mask_type hwloc_topology::init_machine_affinity_mask() const
    { // {{{
        mask_type machine_affinity_mask = 0;

        hwloc_obj_t machine_obj;
        {
            scoped_lock lk(topo_mtx);
            machine_obj = hwloc_get_obj_by_type(topo, HWLOC_OBJ_MACHINE, 0);
        }
        if (machine_obj)
        {
            extract_node_mask(machine_obj, machine_affinity_mask);
            return machine_affinity_mask;
        }

        HPX_THROW_EXCEPTION(kernel_error
          , "hpx::threads::hwloc_topology::init_machine_affinity_mask"
          , "failed to initialize machine affinity mask");
        return 0;
    } // }}}
Example #29
0
    std::size_t hwloc_topology::get_number_of_numa_node_cores(
        std::size_t numa_node
        ) const
    {
        hwloc_obj_t node_obj;

        {
            scoped_lock lk(topo_mtx);
            node_obj = hwloc_get_obj_by_type(topo,
                HWLOC_OBJ_NODE, static_cast<unsigned>(numa_node));
        }

        if (node_obj)
        {
            std::size_t pu_count = 0;
            return extract_node_count(node_obj, HWLOC_OBJ_CORE, pu_count);
        }

        return hwloc_get_nbobjs_by_type(topo, HWLOC_OBJ_CORE);
    }
Example #30
0
    std::size_t hwloc_topology::get_number_of_socket_pus(
        std::size_t num_socket
        ) const
    {
        hwloc_obj_t socket_obj;

        {
            scoped_lock lk(topo_mtx);
            socket_obj = hwloc_get_obj_by_type(topo,
                HWLOC_OBJ_SOCKET, static_cast<unsigned>(num_socket));
        }

        if (socket_obj)
        {
            std::size_t pu_count = 0;
            return extract_node_count(socket_obj, HWLOC_OBJ_PU, pu_count);
        }

        return hwloc_get_nbobjs_by_type(topo, HWLOC_OBJ_PU);
    }