Skip to content

Commit

Permalink
Add fallbacks for 0 cpuinfo queries.
Browse files Browse the repository at this point in the history
Fallback to 1 thread for when cpuinfo_get_cores_count()==0 and core
count when cpuinfo_get_l2_caches_count()==0.
Issue #4654 is tracking making this better.
  • Loading branch information
benvanik committed Jan 29, 2021
1 parent d434fa9 commit 6de6fdf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions iree/task/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static iree_status_t iree_task_topology_ensure_cpuinfo_available() {
}

static bool iree_task_topology_is_cpuinfo_available() {
return cpuinfo_initialize();
return cpuinfo_initialize() && cpuinfo_get_cores_count() > 0;
}

// Returns the core of the calling thread or NULL if not supported.
Expand Down Expand Up @@ -346,8 +346,10 @@ void iree_task_topology_initialize_from_physical_cores_with_filter(

void iree_task_topology_initialize_from_unique_l2_cache_groups(
iree_host_size_t max_group_count, iree_task_topology_t* out_topology) {
if (!iree_task_topology_is_cpuinfo_available()) {
iree_task_topology_initialize_fallback(max_group_count, out_topology);
if (!iree_task_topology_is_cpuinfo_available() ||
!cpuinfo_get_l2_caches_count()) {
iree_task_topology_initialize_from_physical_cores(max_group_count,
out_topology);
return;
}

Expand Down
5 changes: 4 additions & 1 deletion iree/task/topology.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ void iree_task_topology_initialize_from_physical_cores_with_filter(
void iree_task_topology_initialize_from_unique_l2_cache_groups(
iree_host_size_t max_group_count, iree_task_topology_t* out_topology);

// TODO(benvanik): more? or just make users implement as desired? Ideas:
// TODO(#4654): more helpers and better defaults for the platforms we support.
// Users can always make their own but just using these is the common path.
// Ideas:
// - _from_unique_l2_cache_groups but with a min/max count (N% utilization)
// - cluster filtering (big/little cores on ARM)

#ifdef __cplusplus
} // extern "C"
Expand Down

0 comments on commit 6de6fdf

Please sign in to comment.