summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-06-05 07:20:45 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-06-05 07:20:45 +0000
commitf6994f37bc7d1e1be7a751ef71cbf021acc6cd51 (patch)
tree43df93af7d7455789ea4ca3480fa079bc12c5770
parent024ec558089c2bc6f93b1b2873ac70457249d300 (diff)
parent14dec1923f0cb8b0724878f278ac6c5e0e27ea01 (diff)
downloadml-f6994f37bc7d1e1be7a751ef71cbf021acc6cd51.tar.gz
Snap for 4821244 from 14dec1923f0cb8b0724878f278ac6c5e0e27ea01 to pi-release
Change-Id: Ifdcc3605cf0d0396700fa6c76b98dccc23ce3479
-rw-r--r--nn/common/CpuExecutor.cpp2
-rw-r--r--nn/common/include/CpuExecutor.h6
-rw-r--r--nn/runtime/include/NeuralNetworks.h9
-rw-r--r--nn/runtime/test/TestOpenmpSettings.cpp14
4 files changed, 17 insertions, 14 deletions
diff --git a/nn/common/CpuExecutor.cpp b/nn/common/CpuExecutor.cpp
index 0c6219308..8f8706776 100644
--- a/nn/common/CpuExecutor.cpp
+++ b/nn/common/CpuExecutor.cpp
@@ -1536,7 +1536,7 @@ int CpuExecutor::executeOperation(const Operation& operation) {
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 64a46b65f..78b8910ea 100644
--- a/nn/common/include/CpuExecutor.h
+++ b/nn/common/include/CpuExecutor.h
@@ -142,9 +142,9 @@ private:
//
// 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 e0d09ae24..842e61a5d 100644
--- a/nn/runtime/include/NeuralNetworks.h
+++ b/nn/runtime/include/NeuralNetworks.h
@@ -1409,8 +1409,7 @@ typedef enum {
*/
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 @@ typedef enum {
* * 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 @@ int ANeuralNetworksModel_identifyInputsAndOutputs(ANeuralNetworksModel* model, u
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 @@ int ANeuralNetworksModel_identifyInputsAndOutputs(ANeuralNetworksModel* model, u
* 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 @@ void ANeuralNetworksEvent_free(ANeuralNetworksEvent* event);
__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/TestOpenmpSettings.cpp b/nn/runtime/test/TestOpenmpSettings.cpp
index 549473b46..59a794224 100644
--- a/nn/runtime/test/TestOpenmpSettings.cpp
+++ b/nn/runtime/test/TestOpenmpSettings.cpp
@@ -38,26 +38,28 @@ protected:
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) {
@@ -74,12 +76,12 @@ TEST_F(OpenmpSettingsTest, TestThreaded) {
ScopedOpenmpSettings s;
const int blocktimeSet2 = kmp_get_blocktime();
- ASSERT_EQ(blocktimeSet2, 1);
+ ASSERT_EQ(blocktimeSet2, kPreferredBlockTime);
usleep(sleepFor);
const int blocktimeSet3 = kmp_get_blocktime();
- ASSERT_EQ(blocktimeSet3, 1);
+ ASSERT_EQ(blocktimeSet3, kPreferredBlockTime);
}));
}
std::for_each(threads.begin(), threads.end(), [](std::thread& t) {