Skip to content

Commit

Permalink
Release 18.03
Browse files Browse the repository at this point in the history
  • Loading branch information
Surmeh committed Mar 29, 2018
1 parent 5307bc1 commit 7666005
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 30 deletions.
13 changes: 13 additions & 0 deletions ArmnnDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,19 @@ Return<ErrorStatus> ArmnnDriver::prepareModel(const Model& model,
return FailPrepareModel(ErrorStatus::GENERAL_FAILURE, message.str(), cb);
}

// Check that the optimized network is valid.
if (!optNet)
{
return FailPrepareModel(ErrorStatus::GENERAL_FAILURE,
"ArmnnDriver::prepareModel: Invalid optimized network", cb);
}

// Export the optimized network graph to a dot file if an output dump directory
// has been specified in the drivers' arguments.
ExportNetworkGraphToDotFile(*optNet,
m_Options.GetRequestInputsAndOutputsDumpDir(),
model);

// load it into the runtime
armnn::NetworkId netId = 0;
try
Expand Down
28 changes: 3 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,14 @@ PRODUCT_PACKAGES += [email protected]
</pre>
4. Build Android as normal, i.e. run `make` in `<ANDROID_ROOT>`
5. To confirm that the ArmNN driver has been built, check for driver service executable at
<pre>
<ANDROID_ROOT>/out/target/product/<product>/system/vendor/bin/hw/[email protected]
</pre>
`<ANDROID_ROOT>/out/target/product/<product>/system/vendor/bin/hw/[email protected]`

### Testing

1. Run the ArmNN driver service executable in the background
<pre>
adb shell /system/vendor/bin/hw/[email protected] &
</pre>
<pre>adb shell /system/vendor/bin/hw/[email protected] &</pre>
2. Run some code that exercises the Android Neural Networks API, for example Android's
`NeuralNetworksTest` unit tests (note this is an optional component that must be built).
<pre>
adb shell /data/nativetest/NeuralNetworksTest/NeuralNetworksTest > NeuralNetworkTest.log
</pre>
<pre>adb shell /data/nativetest/NeuralNetworksTest/NeuralNetworksTest > NeuralNetworkTest.log</pre>
3. To confirm that the ArmNN driver is being used to service the Android Neural Networks API requests,
check for messages in logcat with the `ArmnnDriver` tag.

### Using ClTuner

ClTuner is a feature of the Compute Library that finds optimum values for OpenCL tuning parameters. The recommended way of using it with ArmNN is to generate the tuning data during development of the Android image for a device, and use it in read-only mode during normal operation:

1. Run the ArmNN driver service executable in tuning mode. The path to the tuning data must be writable by the service:
<pre>
adb shell /system/vendor/bin/hw/[email protected] --cl-tuned-parameters-file &lt;PATH_TO_TUNING_DATA&gt; --cl-tuned-parameters-mode UpdateTunedParameters &
</pre>
2. Run a representative set of Android NNAPI testing loads. In this mode of operation, each NNAPI workload will be slow the first time it is executed, as the tuning parameters are being selected. Subsequent executions will use the tuning data which has been generated.
3. Stop the service.
4. Deploy the tuned parameters file to a location readable by the ArmNN driver service (for example, to a location within /vendor/etc).
5. During normal operation, pass the location of the tuning data to the driver service (this would normally be done by passing arguments via Android init in the service .rc definition):
<pre>
adb shell /system/vendor/bin/hw/[email protected] --cl-tuned-parameters-file &lt;PATH_TO_TUNING_DATA&gt; &
</pre>
39 changes: 39 additions & 0 deletions Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <cassert>
#include <cinttypes>
#include <fstream>
#include <iomanip>

using namespace android;
using namespace android::hidl::memory::V1_0;
Expand Down Expand Up @@ -270,4 +271,42 @@ void DumpTensor(const std::string& dumpDir,
}
}

void ExportNetworkGraphToDotFile(const armnn::IOptimizedNetwork& optimizedNetwork,
const std::string& dumpDir,
const Model& model)
{
// The dump directory must exist in advance.
if (dumpDir.empty())
{
return;
}

// Get the memory address of the model and convert it to a hex string (of at least a '0' character).
size_t modelAddress = uintptr_t(&model);
std::stringstream ss;
ss << std::uppercase << std::hex << std::setfill('0') << std::setw(1) << modelAddress;
std::string modelAddressHexString = ss.str();

// Set the name of the output .dot file.
const std::string fileName = boost::str(boost::format("%1%/networkgraph_%2%.dot")
% dumpDir
% modelAddressHexString);

ALOGV("Exporting the optimized network graph to file: %s", fileName.c_str());

// Write the network graph to a dot file.
std::ofstream fileStream;
fileStream.open(fileName, std::ofstream::out | std::ofstream::trunc);

if (!fileStream.good())
{
ALOGW("Could not open file %s for writing", fileName.c_str());
return;
}

if (optimizedNetwork.SerializeToDot(fileStream) != armnn::Status::Success)
{
ALOGW("An error occurred when writing to file %s", fileName.c_str());
}
}
} // namespace armnn_driver
3 changes: 3 additions & 0 deletions Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ void DumpTensor(const std::string& dumpDir,
const std::string& tensorName,
const armnn::ConstTensor& tensor);

void ExportNetworkGraphToDotFile(const armnn::IOptimizedNetwork& optimizedNetwork,
const std::string& dumpDir,
const Model& model);
}
4 changes: 2 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ fi
if [ ! -d armnn ]; then
echo "++ Downloading armnn"

git clone [email protected]:ARM-software/armnn.git armnn
git clone [email protected]:ARM-software/armnn armnn
AssertZeroExitCode "Cloning armnn failed"
fi

if [ ! -d clframework ]; then
echo "++ Downloading clframework"

git clone [email protected]:ARM-software/ComputeLibrary.git clframework
git clone [email protected]:ARM-software/ComputeLibrary clframework
AssertZeroExitCode "Cloning clframework failed"
fi

Expand Down
3 changes: 2 additions & 1 deletion test/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ LOCAL_CFLAGS := \
-UNDEBUG

LOCAL_SRC_FILES := \
Tests.cpp
Tests.cpp \
UtilsTests.cpp

LOCAL_STATIC_LIBRARIES := \
libarmnn-driver \
Expand Down
2 changes: 0 additions & 2 deletions test/Tests.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ class PreparedModelCallback : public IPreparedModelCallback
sp<IPreparedModel> m_PreparedModel;
};



// lifted from common/Utils.cpp
hidl_memory allocateSharedMemory(int64_t size)
{
Expand Down
Loading

0 comments on commit 7666005

Please sign in to comment.