forked from google/ruy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the cpuinfo library instead of our own code for CPU feature detec…
…tion. PiperOrigin-RevId: 313261629
- Loading branch information
1 parent
7b75a8b
commit 74b7491
Showing
15 changed files
with
1,018 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "ruy/cpuinfo.h" | ||
|
||
#include "ruy/platform.h" | ||
|
||
#define RUY_HAVE_CPUINFO (!RUY_PPC) | ||
|
||
#if RUY_HAVE_CPUINFO | ||
|
||
#include <cpuinfo.h> | ||
|
||
namespace ruy { | ||
|
||
CpuInfo::~CpuInfo() { | ||
if (init_status_ == InitStatus::kInitialized) { | ||
cpuinfo_deinitialize(); | ||
} | ||
} | ||
|
||
bool CpuInfo::EnsureInitialized() { | ||
if (init_status_ == InitStatus::kNotYetAttempted) { | ||
init_status_ = | ||
cpuinfo_initialize() ? InitStatus::kInitialized : InitStatus::kFailed; | ||
} | ||
return init_status_ == InitStatus::kInitialized; | ||
} | ||
|
||
bool CpuInfo::NeonDotprod() { | ||
return EnsureInitialized() && cpuinfo_has_arm_neon_dot(); | ||
} | ||
|
||
bool CpuInfo::Sse42() { | ||
return EnsureInitialized() && cpuinfo_has_x86_sse4_2(); | ||
} | ||
|
||
bool CpuInfo::Avx2() { return EnsureInitialized() && cpuinfo_has_x86_avx2(); } | ||
|
||
bool CpuInfo::Avx512() { | ||
return EnsureInitialized() && cpuinfo_has_x86_avx512f() && | ||
cpuinfo_has_x86_avx512dq() && cpuinfo_has_x86_avx512cd() && | ||
cpuinfo_has_x86_avx512bw() && cpuinfo_has_x86_avx512vl(); | ||
} | ||
|
||
bool CpuInfo::AvxVnni() { | ||
return EnsureInitialized() && cpuinfo_has_x86_avx512vnni(); | ||
} | ||
|
||
} // namespace ruy | ||
|
||
#else // not RUY_HAVE_CPUINFO | ||
|
||
namespace ruy { | ||
CpuInfo::~CpuInfo() {} | ||
} // namespace ruy | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.