Skip to content

Commit

Permalink
Disable cpuinfo in other build systems than Bazel unless they explcit…
Browse files Browse the repository at this point in the history
…ly opt in by defining this RUY_HAVE_CPUINFO token. That requires first porting the cpuinfo BUILD.

PiperOrigin-RevId: 314794292
  • Loading branch information
bjacob authored and copybara-github committed Jun 4, 2020
1 parent d4ddc05 commit a37cc4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 11 additions & 1 deletion ruy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,22 @@ cc_library(
# ruy_copts contains -Wundef, but cpuinfo's header warns with that.
"-Wno-undef",
],
}),
}) + select({
# This select must match the similar select in `deps`.
# We intentionally define this token in the BUILD
# file so that ports to other build-systems do not
# use cpuinfo by default - they need to port the
# cpuinfo BUILD first, then can define this token.
":ppc": [],
":fuchsia": [],
"//conditions:default": ["-DRUY_HAVE_CPUINFO"],
}),
deps = [
":platform",
":check_macros",
":cpu_cache_params",
] + select({
# This select must match the similar select in `copts`
":ppc": [],
":fuchsia": [],
"//conditions:default": ["@cpuinfo//:cpuinfo_with_unstripped_include_path"],
Expand Down
8 changes: 3 additions & 5 deletions ruy/cpuinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include "ruy/cpu_cache_params.h"
#include "ruy/platform.h"

#define RUY_HAVE_CPUINFO (!(RUY_PLATFORM_PPC || RUY_PLATFORM_FUCHSIA))

#if RUY_HAVE_CPUINFO
#ifdef RUY_HAVE_CPUINFO
#include "include/cpuinfo.h"
#endif

Expand All @@ -24,7 +22,7 @@ void MakeDummyCacheParams(CpuCacheParams* result) {
}
} // end namespace

#if RUY_HAVE_CPUINFO
#ifdef RUY_HAVE_CPUINFO

CpuInfo::~CpuInfo() {
if (init_status_ == InitStatus::kInitialized) {
Expand Down Expand Up @@ -115,7 +113,7 @@ bool CpuInfo::AvxVnni() {
return EnsureInitialized() && cpuinfo_has_x86_avx512vnni();
}

#else // not RUY_HAVE_CPUINFO
#else // not defined RUY_HAVE_CPUINFO

CpuInfo::~CpuInfo() {}
bool CpuInfo::EnsureInitialized() {
Expand Down

0 comments on commit a37cc4d

Please sign in to comment.