File tree Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,17 @@ cc_library(
100100 ],
101101)
102102
103+ tsl_cc_test (
104+ name = "cpu_info_test" ,
105+ size = "small" ,
106+ srcs = ["cpu_info_test.cc" ],
107+ deps = [
108+ ":platform_port" ,
109+ ":test" ,
110+ ":test_main" ,
111+ ],
112+ )
113+
103114cc_library (
104115 name = "criticality" ,
105116 compatible_with = get_compatible_with_portable (),
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ limitations under the License.
2121// TODO(ahentz): This is not strictly required here but, for historical
2222// reasons, many people depend on cpu_info.h in order to use kLittleEndian.
2323#include " tsl/platform/byte_order.h"
24+ #include " tsl/platform/platform.h"
2425
2526#if defined(_MSC_VER)
2627// included so __cpuidex function is available for GETCPUID on Windows
@@ -150,6 +151,24 @@ bool TestAarch64CPU(Aarch64CPU cpu);
150151// Checks CPU registers to return hardware capabilities.
151152bool TestCPUFeature (CPUFeature feature);
152153
154+ // Checks whether the current processor is x86.
155+ constexpr bool IsX86CPU () {
156+ #ifdef PLATFORM_IS_X86
157+ return true ;
158+ #else
159+ return false ;
160+ #endif
161+ }
162+
163+ // Checks whether the current processor is aarch64.
164+ constexpr bool IsAarch64CPU () {
165+ #if defined(PLATFORM_IS_ARM64) && !defined(__APPLE__) && !defined(__OpenBSD__)
166+ return true ;
167+ #else
168+ return false ;
169+ #endif
170+ }
171+
153172// Returns CPU Vendor string (i.e. 'GenuineIntel', 'AuthenticAMD', etc.)
154173std::string CPUVendorIDString ();
155174
Original file line number Diff line number Diff line change 1+ /* Copyright 2024 The TensorFlow Authors. All Rights Reserved.
2+
3+ Licensed under the Apache License, Version 2.0 (the "License");
4+ you may not use this file except in compliance with the License.
5+ You may obtain a copy of the License at
6+
7+ http://www.apache.org/licenses/LICENSE-2.0
8+
9+ Unless required by applicable law or agreed to in writing, software
10+
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+ ==============================================================================*/
16+
17+ #include " tsl/platform/cpu_info.h"
18+
19+ #include " tsl/platform/test.h"
20+
21+ namespace tsl {
22+
23+ TEST (CPUInfo, CommonX86CPU) {
24+ // CPUs from 1999 onwards support SSE.
25+ if (port::TestCPUFeature (port::CPUFeature::SSE)) {
26+ EXPECT_TRUE (port::IsX86CPU ());
27+ }
28+ }
29+
30+ TEST (CPUInfo, Aarch64NeoverseV1CPU) {
31+ if (port::TestAarch64CPU (port::Aarch64CPU::ARM_NEOVERSE_V1)) {
32+ EXPECT_TRUE (port::IsAarch64CPU ());
33+ }
34+ }
35+
36+ } // namespace tsl
You can’t perform that action at this time.
0 commit comments