Skip to content

Commit bc14b72

Browse files
committed
patch tensorflow core platform cpu utils
allow android cpu_utils helper to be used for linux_arm and linux_arm64 as it seems suitable on these platforms for obtaining a valid cpu frequency which may be used to improve tensorflow node cost estimators and graph optimizers
1 parent a82c1dd commit bc14b72

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

WORKSPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ http_archive(
7070
# arm (32-bit) datatype sizes
7171
"//third_party/tensorflow:curl.patch",
7272
"//third_party/tensorflow:hwloc.patch",
73+
# allow android cpu helper to be used for linux_arm and linux_arm64
74+
"//third_party/tensorflow:tensorflow.patch",
7375
],
7476
sha256 = "9c94bfec7214853750c7cacebd079348046f246ec0174d01cd36eda375117628",
7577
strip_prefix = "tensorflow-582c8d236cb079023657287c318ff26adb239002",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
diff --git a/tensorflow/core/platform/profile_utils/android_armv7a_cpu_utils_helper.cc b/tensorflow/core/platform/profile_utils/android_armv7a_cpu_utils_helper.cc
2+
index d61a036181d..cd982a85e42 100644
3+
--- tensorflow/core/platform/profile_utils/android_armv7a_cpu_utils_helper.cc
4+
+++ tensorflow/core/platform/profile_utils/android_armv7a_cpu_utils_helper.cc.new
5+
@@ -15,7 +15,7 @@ limitations under the License.
6+
7+
#include "tensorflow/core/platform/profile_utils/android_armv7a_cpu_utils_helper.h"
8+
9+
-#if defined(__ANDROID__) && (__ANDROID_API__ >= 21) && \
10+
+#if (defined(__ANDROID__) && (__ANDROID_API__ >= 21)) || defined(__linux__) && \
11+
(defined(__ARM_ARCH_7A__) || defined(__aarch64__))
12+
13+
#include <asm/unistd.h>
14+
diff --git a/tensorflow/core/platform/profile_utils/android_armv7a_cpu_utils_helper.h b/tensorflow/core/platform/profile_utils/android_armv7a_cpu_utils_helper.h
15+
index 66bc0fd5928..ac2be9af930 100644
16+
--- tensorflow/core/platform/profile_utils/android_armv7a_cpu_utils_helper.h
17+
+++ tensorflow/core/platform/profile_utils/android_armv7a_cpu_utils_helper.h.new
18+
@@ -22,7 +22,7 @@ limitations under the License.
19+
#include "tensorflow/core/platform/profile_utils/i_cpu_utils_helper.h"
20+
#include "tensorflow/core/platform/types.h"
21+
22+
-#if defined(__ANDROID__) && (__ANDROID_API__ >= 21) && \
23+
+#if (defined(__ANDROID__) && (__ANDROID_API__ >= 21)) || defined(__linux__) && \
24+
(defined(__ARM_ARCH_7A__) || defined(__aarch64__))
25+
26+
struct perf_event_attr;
27+
diff --git a/tensorflow/core/platform/profile_utils/cpu_utils.cc b/tensorflow/core/platform/profile_utils/cpu_utils.cc
28+
index b76b3377397..691154eeaa1 100644
29+
--- tensorflow/core/platform/profile_utils/cpu_utils.cc
30+
+++ tensorflow/core/platform/profile_utils/cpu_utils.cc.new
31+
@@ -80,6 +80,15 @@ static ICpuUtilsHelper* cpu_utils_helper_instance_ = nullptr;
32+
// TODO(satok): do not switch by macro here
33+
#if defined(__ANDROID__)
34+
return GetCpuUtilsHelperSingletonInstance().CalculateCpuFrequency();
35+
+#elif defined(__linux__) && (defined(__ARM_ARCH_7A__) || defined(__aarch64__))
36+
+ const int64 freq_n = GetCpuUtilsHelperSingletonInstance().CalculateCpuFrequency();
37+
+ // maintain mostly consistent logging with the other linux platforms
38+
+ if (freq_n < 1) {
39+
+ LOG(WARNING) << "Failed to get CPU frequency: " << freq_n;
40+
+ return INVALID_FREQUENCY;
41+
+ }
42+
+ LOG(INFO) << "CPU Frequency: " << freq_n << " Hz";
43+
+ return freq_n;
44+
#elif defined(__linux__)
45+
// Read the contents of /proc/cpuinfo.
46+
std::ifstream cpuinfo("/proc/cpuinfo");
47+
@@ -144,7 +153,7 @@ static ICpuUtilsHelper* cpu_utils_helper_instance_ = nullptr;
48+
if (cpu_utils_helper_instance_ != nullptr) {
49+
LOG(FATAL) << "cpu_utils_helper_instance_ is already instantiated.";
50+
}
51+
-#if defined(__ANDROID__) && (__ANDROID_API__ >= 21) && \
52+
+#if (defined(__ANDROID__) && (__ANDROID_API__ >= 21)) || defined(__linux__) && \
53+
(defined(__ARM_ARCH_7A__) || defined(__aarch64__))
54+
cpu_utils_helper_instance_ = new AndroidArmV7ACpuUtilsHelper();
55+
#else

0 commit comments

Comments
 (0)