Skip to content

Commit

Permalink
Change QueryCacheParams to return if there was an error and handle th…
Browse files Browse the repository at this point in the history
…at during Initialize

PiperOrigin-RevId: 617949545
  • Loading branch information
Ruy Contributors authored and copybara-github committed Mar 21, 2024
1 parent 587c2cf commit c08ec52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 13 additions & 6 deletions ruy/cpuinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool CpuInfo::EnsureInitialized() {
}

namespace {
void QueryCacheParams(CpuCacheParams* cache_params) {
bool QueryCacheParams(CpuCacheParams* cache_params) {
const int processors_count = cpuinfo_get_processors_count();
RUY_DCHECK_GT(processors_count, 0);
int overall_local_cache_size = std::numeric_limits<int>::max();
Expand All @@ -57,14 +57,16 @@ void QueryCacheParams(CpuCacheParams* cache_params) {
// L2.
}
if (!cache->processor_count) {
continue; // crashes from Chrome on Android suggests that might happen?
// This may happen in a sand-boxed process, e.g.: a browser renderer.
continue;
}
const cpuinfo_processor* processor_start =
cpuinfo_get_processor(cache->processor_start);
const cpuinfo_processor* processor_end = cpuinfo_get_processor(
cache->processor_start + cache->processor_count - 1);
if (!processor_start || !processor_end) {
continue; // crashes from Chrome on Android suggests this might happen.
// This may happen in a sand-boxed process, e.g.: a browser renderer.
continue;
}
const bool is_local = processor_start->core == processor_end->core;
if (is_local) {
Expand All @@ -76,8 +78,9 @@ void QueryCacheParams(CpuCacheParams* cache_params) {
if (!local_cache_size) {
local_cache_size = last_level_cache_size;
}
RUY_DCHECK_GT(local_cache_size, 0);
RUY_DCHECK_GT(last_level_cache_size, 0);
if (local_cache_size == 0 || last_level_cache_size == 0) {
return false;
}
RUY_DCHECK_GE(last_level_cache_size, local_cache_size);
overall_local_cache_size =
std::min(overall_local_cache_size, local_cache_size);
Expand All @@ -86,6 +89,7 @@ void QueryCacheParams(CpuCacheParams* cache_params) {
}
cache_params->local_cache_size = overall_local_cache_size;
cache_params->last_level_cache_size = overall_last_level_cache_size;
return true;
}
} // end namespace

Expand All @@ -95,7 +99,10 @@ CpuInfo::InitStatus CpuInfo::Initialize() {
MakeDummyCacheParams(&cache_params_);
return InitStatus::kFailed;
}
QueryCacheParams(&cache_params_);
if (!QueryCacheParams(&cache_params_)) {
MakeDummyCacheParams(&cache_params_);
return InitStatus::kFailed;
}
return InitStatus::kInitialized;
}

Expand Down
1 change: 0 additions & 1 deletion ruy/profiler/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
#ifdef RUY_PROFILER
#include <cstdio>
#include <mutex>
#include <string>

This comment has been minimized.

Copy link
@jdapena

jdapena Mar 25, 2024

Contributor

This change removed the build fix for std::string again. I guess the fix did not make it to the upstream internal repository?

#include <vector>
#endif

Expand Down

2 comments on commit c08ec52

@talumbau
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is correct. My apologies. Can you open another PR and I will attempt to have the bot commit through the proper channels. This repo is very much in "maintenance mode" and doesn't get as much attention because of that.

@jdapena
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #354 pull request

Please sign in to comment.