Fix for HDRNet producing nondeterministic results.
Eigen reads and writes volatile scalars to allow thread A to communicate
to thread B that data written by thread A is available for thread B to
read. However, volatile on Android doesn't guarantee ordered accesses,
so it's not certain that after thread B sees the volatile write from
thread A that data written by thread A is actually visible to thread B.
The solution is to replace those volatile scalars with std::atomic<>.
There might be an alternative with better performance (such as imposing
looser ordering constraints than the default std::atomic<> ordering
constraints).
Bug: 109953668
Test: NeuralNetworksTest_static
Test: adb shell am instrument -e class \
"com.example.android.nn.benchmark.NNTest#testNNAPI11Seconds[hdrnet_float]" \
-w com.example.android.nn.benchmark/android.support.test.runner.AndroidJUnitRunner
# test device (including neural networks runtime) is aosp_walleye-userdebug
# bench is from goog/master
# also ran with mobilenet_float in place of hdrnet_float
# could not reproduce problem in this environment; reproduced on
# an internal branch on unreleased hardware
Change-Id: Idea6e4b0a3db168dce5915c1beacb643267f3ec6
2 files changed