Skip to content

Commit

Permalink
Make the code portable to hwloc 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
fireice-uk committed Jul 10, 2017
1 parent 62a5dcf commit d3150bf
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions autoAdjustHwloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class autoAdjust
tlcs.reserve(16);
results.reserve(16);

findChildrenByType(hwloc_get_root_obj(topology), HWLOC_OBJ_CACHE,
findChildrenCaches(hwloc_get_root_obj(topology),
[&tlcs](hwloc_obj_t found) { tlcs.emplace_back(found); } );

if(tlcs.size() == 0)
Expand Down Expand Up @@ -87,6 +87,27 @@ class autoAdjust
}
}

inline bool isCacheObject(hwloc_obj_t obj)
{
#if HWLOC_API_VERSION >= 0x20000
return hwloc_obj_type_is_cache(obj->type);
#else
return obj->type == HWLOC_OBJ_CACHE;
#endif // HWLOC_API_VERSION
}

template<typename func>
inline void findChildrenCaches(hwloc_obj_t obj, func lambda)
{
for(size_t i=0; i < obj->arity; i++)
{
if(isCacheObject(obj->children[i]))
lambda(obj->children[i]);
else
findChildrenCaches(obj->children[i], lambda);
}
}

inline bool isCacheExclusive(hwloc_obj_t obj)
{
const char* value = hwloc_obj_get_info_by_name(obj, "Inclusive");
Expand All @@ -110,7 +131,7 @@ class autoAdjust
if(obj->attr->cache.size == 0)
{
//We will always have one child if PUs > 0
if(obj->children[0]->type != HWLOC_OBJ_CACHE)
if(!isCacheObject(obj->children[0]))
throw(std::runtime_error("The CPU doesn't seem to have a cache."));

//Try our luck with lower level caches
Expand All @@ -126,7 +147,7 @@ class autoAdjust
{
hwloc_obj_t l2obj = obj->children[i];
//If L2 is exclusive and greater or equal to 2MB add room for one more hash
if(l2obj->type == HWLOC_OBJ_CACHE && l2obj->attr != nullptr && l2obj->attr->cache.size >= hashSize)
if(isCacheObject(l2obj) && l2obj->attr != nullptr && l2obj->attr->cache.size >= hashSize)
cacheSize += hashSize;
}
}
Expand Down

0 comments on commit d3150bf

Please sign in to comment.