Merge changes from topic "nnapi-cherrypick-from-master-to-aosp"
* changes:
Properly guard newly added APIs in P
Openmp blocktime 1->20ms to keep cores enabled
Add asan library dependency for CI
diff --git a/nn/common/CpuExecutor.cpp b/nn/common/CpuExecutor.cpp
index 0c62193..8f87067 100644
--- a/nn/common/CpuExecutor.cpp
+++ b/nn/common/CpuExecutor.cpp
@@ -1536,7 +1536,7 @@
ScopedOpenmpSettings::ScopedOpenmpSettings() {
mBlocktimeInitial = kmp_get_blocktime();
- kmp_set_blocktime(1); // ms
+ kmp_set_blocktime(20); // ms, see b/109645291
#if NNAPI_LIMIT_CPU_THREADS
// Code not yet enabled. Choosing the number of threads to be based on
diff --git a/nn/common/include/CpuExecutor.h b/nn/common/include/CpuExecutor.h
index 64a46b6..78b8910 100644
--- a/nn/common/include/CpuExecutor.h
+++ b/nn/common/include/CpuExecutor.h
@@ -142,9 +142,9 @@
//
// Currently sets a low blocktime: the time OpenMP threads busy-wait for more
// work before going to sleep. See b/79159165, https://reviews.llvm.org/D18577.
-// The default is 200ms, we set to 1ms here. This should allow for the threads
-// to not sleep before the next operation, but release CPU to other work
-// quickly.
+// The default is 200ms, we set to 20ms here, see b/109645291. This keeps the
+// cores enabled throughout inference computation without too much extra power
+// consumption afterwards.
//
// The OpenMP settings are thread-local (applying only to worker threads formed
// from that thread), see https://software.intel.com/en-us/node/522688 and
diff --git a/nn/runtime/include/NeuralNetworks.h b/nn/runtime/include/NeuralNetworks.h
index e0d09ae..842e61a 100644
--- a/nn/runtime/include/NeuralNetworks.h
+++ b/nn/runtime/include/NeuralNetworks.h
@@ -1409,8 +1409,7 @@
*/
ANEURALNETWORKS_TANH = 28,
-// TODO: change to __ANDROID_API__ >= __ANDROID_API_P__ once available.
-#if __ANDROID_API__ > __ANDROID_API_O_MR1__
+#if __ANDROID_API__ >= __ANDROID_API_P__
// TODO: make the description easier to understand.
/**
* BatchToSpace for N-dimensional tensors.
@@ -1702,7 +1701,7 @@
* * 0: A tensor of the same {@link OperandCode} as input0.
*/
ANEURALNETWORKS_TRANSPOSE = 37,
-#endif
+#endif // __ANDROID_API__ >= __ANDROID_API_P__
} OperationCode;
/**
@@ -2171,6 +2170,7 @@
const uint32_t* inputs, uint32_t outputCount,
const uint32_t* outputs);
+#if __ANDROID_API__ >= __ANDROID_API_P__
/**
* Specifies whether {@link ANEURALNETWORKS_TENSOR_FLOAT32} is allowed to be
* calculated with range and/or precision as low as that of the IEEE 754 16-bit
@@ -2192,6 +2192,7 @@
* See {@link ANeuralNetworksModel} for information on multithreaded usage.
*/
int ANeuralNetworksModel_relaxComputationFloat32toFloat16(ANeuralNetworksModel* model, bool allow);
+#endif // __ANDROID_API__ >= __ANDROID_API_P__
/**
* Create a {@link ANeuralNetworksCompilation} to compile the given model.
@@ -2484,7 +2485,7 @@
__END_DECLS
-#endif // __ANDROID_API__ >= 27
+#endif // __ANDROID_API__ >= __ANDROID_API_O_MR1__
#endif // ANDROID_ML_NN_RUNTIME_NEURAL_NETWORKS_H
diff --git a/nn/runtime/test/Android.bp b/nn/runtime/test/Android.bp
index 7f47804..7948bfa 100644
--- a/nn/runtime/test/Android.bp
+++ b/nn/runtime/test/Android.bp
@@ -112,6 +112,29 @@
sanitize: {
address: true,
},
+ // Declare explicit library dependency for continuous builds
+ target: {
+ android_arm: {
+ required: [
+ "libclang_rt.asan-arm-android",
+ ],
+ },
+ android_arm64: {
+ required: [
+ "libclang_rt.asan-aarch64-android",
+ ],
+ },
+ android_x86: {
+ required: [
+ "libclang_rt.asan-i686-android",
+ ],
+ },
+ android_x86_64: {
+ required: [
+ "libclang_rt.asan-x86_64-android",
+ ],
+ },
+ },
}
cc_defaults {
diff --git a/nn/runtime/test/TestOpenmpSettings.cpp b/nn/runtime/test/TestOpenmpSettings.cpp
index a021f8d..3c42bcd 100644
--- a/nn/runtime/test/TestOpenmpSettings.cpp
+++ b/nn/runtime/test/TestOpenmpSettings.cpp
@@ -38,26 +38,28 @@
ASSERT_EQ(blocktimeRestored, kOpenmpDefaultBlockTime);
}
static const int kOpenmpDefaultBlockTime;
+ static const int kPreferredBlockTime;
};
const int OpenmpSettingsTest::kOpenmpDefaultBlockTime = 200;
+const int OpenmpSettingsTest::kPreferredBlockTime = 20;
using ::android::nn::ScopedOpenmpSettings;
-TEST_F(OpenmpSettingsTest, Test1) {
+TEST_F(OpenmpSettingsTest, TestkPreferredBlockTime) {
ScopedOpenmpSettings s;
const int blocktimeSet = kmp_get_blocktime();
- ASSERT_EQ(blocktimeSet, 1);
+ ASSERT_EQ(blocktimeSet, kPreferredBlockTime);
}
TEST_F(OpenmpSettingsTest, Test2) {
ScopedOpenmpSettings s1;
const int blocktimeSet1 = kmp_get_blocktime();
- ASSERT_EQ(blocktimeSet1, 1);
+ ASSERT_EQ(blocktimeSet1, kPreferredBlockTime);
ScopedOpenmpSettings s2;
const int blocktimeSet2 = kmp_get_blocktime();
- ASSERT_EQ(blocktimeSet2, 1);
+ ASSERT_EQ(blocktimeSet2, kPreferredBlockTime);
}
TEST_F(OpenmpSettingsTest, TestThreaded) {
@@ -76,12 +78,12 @@
ScopedOpenmpSettings s;
const int blocktimeSet1 = kmp_get_blocktime();
- ASSERT_EQ(blocktimeSet1, 1);
+ ASSERT_EQ(blocktimeSet1, kPreferredBlockTime);
usleep(sleepFor);
const int blocktimeSet2 = kmp_get_blocktime();
- ASSERT_EQ(blocktimeSet2, 1);
+ ASSERT_EQ(blocktimeSet2, kPreferredBlockTime);
}));
}
std::for_each(threads.begin(), threads.end(), [](std::thread& t) {