Skip to content

Commit

Permalink
Release 18.05.02
Browse files Browse the repository at this point in the history
  • Loading branch information
Surmeh committed Jul 5, 2018
1 parent 49b9e10 commit deb3bdb
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 164 deletions.
40 changes: 34 additions & 6 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ANDROID_NN_DRIVER_LOCAL_PATH := $(call my-dir)
LOCAL_PATH := $(ANDROID_NN_DRIVER_LOCAL_PATH)

# Configure these paths if you move the source or Khronos headers
ARMNN_HEADER_PATH := $(LOCAL_PATH)/armnn/include
ARMNN_UTILS_HEADER_PATH := $(LOCAL_PATH)/armnn/src/armnnUtils
OPENCL_HEADER_PATH := $(LOCAL_PATH)/clframework/include
NN_HEADER_PATH := $(LOCAL_PATH)/../../../frameworks/ml/nn/runtime/include

Expand All @@ -22,7 +24,9 @@ LOCAL_PROPRIETARY_MODULE := true
# Mark source files as dependent on Android.mk
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk

LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES := \
$(ARMNN_HEADER_PATH) \
$(ARMNN_UTILS_HEADER_PATH) \
$(OPENCL_HEADER_PATH) \
$(NN_HEADER_PATH)

Expand All @@ -31,11 +35,17 @@ LOCAL_CFLAGS := \
-fexceptions \
-Werror \
-Wno-format-security
ifeq ($(PLATFORM_VERSION),9)
# Required to build with the changes made to the Android ML framework starting from Android P,
# regardless of the HAL version used for the build.
LOCAL_CFLAGS+= \
-DARMNN_ANDROID_P
endif
ifeq ($(ARMNN_DRIVER_DEBUG),1)
LOCAL_CFLAGS+= -UNDEBUG
endif

LOCAL_SRC_FILES := \
LOCAL_SRC_FILES := \
ArmnnDriver.cpp \
ArmnnPreparedModel.cpp \
ModelToINetworkConverter.cpp \
Expand All @@ -49,9 +59,9 @@ LOCAL_STATIC_LIBRARIES := \
libboost_program_options \
libboost_system \
libboost_thread \
armnn-arm_compute \
armnn-arm_compute

LOCAL_SHARED_LIBRARIES := \
LOCAL_SHARED_LIBRARIES := \
libbase \
libhidlbase \
libhidltransport \
Expand All @@ -62,6 +72,12 @@ LOCAL_SHARED_LIBRARIES := \
android.hidl.allocator@1.0 \
android.hidl.memory@1.0 \
libOpenCL
ifeq ($(PLATFORM_VERSION),9)
# Required to build the 1.0 version of the NN Driver on Android P and later versions,
# as the 1.0 version of the NN API needs the 1.1 HAL headers to be included regardless.
LOCAL_SHARED_LIBRARIES+= \
android.hardware.neuralnetworks@1.1
endif

include $(BUILD_STATIC_LIBRARY)

Expand All @@ -80,6 +96,7 @@ LOCAL_PROPRIETARY_MODULE := true
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk

LOCAL_C_INCLUDES := \
$(ARMNN_HEADER_PATH) \
$(NN_HEADER_PATH)

LOCAL_CFLAGS := \
Expand All @@ -89,7 +106,7 @@ ifeq ($(ARMNN_DRIVER_DEBUG),1)
LOCAL_CFLAGS+= -UNDEBUG
endif

LOCAL_SRC_FILES := \
LOCAL_SRC_FILES := \
service.cpp

LOCAL_STATIC_LIBRARIES := \
Expand All @@ -101,8 +118,13 @@ LOCAL_STATIC_LIBRARIES := \
libboost_system \
libboost_thread \
armnn-arm_compute
ifeq ($(PLATFORM_VERSION),9)
# Required to build the 1.0 version of the NN Driver on Android P and later versions.
LOCAL_STATIC_LIBRARIES+= \
libomp
endif

LOCAL_SHARED_LIBRARIES := \
LOCAL_SHARED_LIBRARIES := \
libbase \
libhidlbase \
libhidltransport \
Expand All @@ -116,6 +138,12 @@ LOCAL_SHARED_LIBRARIES := \
android.hidl.allocator@1.0 \
android.hidl.memory@1.0 \
libOpenCL
ifeq ($(PLATFORM_VERSION),9)
# Required to build the 1.0 version of the NN Driver on Android P and later versions,
# as the 1.0 version of the NN API needs the 1.1 HAL headers to be included regardless.
LOCAL_SHARED_LIBRARIES+= \
android.hardware.neuralnetworks@1.1
endif

include $(BUILD_EXECUTABLE)

Expand Down
26 changes: 18 additions & 8 deletions ArmnnDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

#include "OperationsUtils.h"

#if defined(ARMNN_ANDROID_P)
// The headers of the ML framework have changed between Android O and Android P.
// The validation functions have been moved into their own header, ValidateHal.h.
#include <ValidateHal.h>
#endif

#include <boost/algorithm/string/predicate.hpp>
#include <boost/program_options.hpp>

Expand Down Expand Up @@ -207,11 +213,11 @@ ArmnnDriver::ArmnnDriver(DriverOptions options)
}
}

Return<void> ArmnnDriver::getCapabilities(getCapabilities_cb cb)
Return<void> ArmnnDriver::getCapabilities(V1_0::IDevice::getCapabilities_cb cb)
{
ALOGV("ArmnnDriver::getCapabilities()");

Capabilities capabilities;
V1_0::Capabilities capabilities;
if (m_Runtime)
{
capabilities.float32Performance.execTime =
Expand Down Expand Up @@ -241,7 +247,7 @@ Return<void> ArmnnDriver::getCapabilities(getCapabilities_cb cb)
return Void();
}

Return<void> ArmnnDriver::getSupportedOperations(const Model& model, getSupportedOperations_cb cb)
Return<void> ArmnnDriver::getSupportedOperations(const V1_0::Model& model, V1_0::IDevice::getSupportedOperations_cb cb)
{
ALOGV("ArmnnDriver::getSupportedOperations()");

Expand Down Expand Up @@ -310,7 +316,7 @@ Return<ErrorStatus> FailPrepareModel(ErrorStatus error,

}

Return<ErrorStatus> ArmnnDriver::prepareModel(const Model& model,
Return<ErrorStatus> ArmnnDriver::prepareModel(const V1_0::Model& model,
const sp<IPreparedModelCallback>& cb)
{
ALOGV("ArmnnDriver::prepareModel()");
Expand Down Expand Up @@ -357,7 +363,8 @@ Return<ErrorStatus> ArmnnDriver::prepareModel(const Model& model,

if (modelConverter.GetConversionResult() != ConversionResult::Success)
{
return FailPrepareModel(ErrorStatus::GENERAL_FAILURE, "ModelToINetworkConverter failed", cb);
FailPrepareModel(ErrorStatus::GENERAL_FAILURE, "ModelToINetworkConverter failed", cb);
return ErrorStatus::NONE;
}

// optimize the network
Expand All @@ -370,14 +377,16 @@ Return<ErrorStatus> ArmnnDriver::prepareModel(const Model& model,
{
std::stringstream message;
message << "armnn::Exception ("<<e.what()<<") caught from optimize.";
return FailPrepareModel(ErrorStatus::GENERAL_FAILURE, message.str(), cb);
FailPrepareModel(ErrorStatus::GENERAL_FAILURE, message.str(), cb);
return ErrorStatus::NONE;
}

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

// Export the optimized network graph to a dot file if an output dump directory
Expand All @@ -400,7 +409,8 @@ Return<ErrorStatus> ArmnnDriver::prepareModel(const Model& model,
{
std::stringstream message;
message << "armnn::Exception (" << e.what()<< ") caught from LoadNetwork.";
return FailPrepareModel(ErrorStatus::GENERAL_FAILURE, message.str(), cb);
FailPrepareModel(ErrorStatus::GENERAL_FAILURE, message.str(), cb);
return ErrorStatus::NONE;
}

std::unique_ptr<ArmnnPreparedModel> preparedModel(new ArmnnPreparedModel(
Expand Down
14 changes: 9 additions & 5 deletions ArmnnDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <set>
#include <string>

// For Android O, explicitly declare the V1_0 HAL namespace to shorten type declarations,
// as the namespace is not defined in HalInterfaces.h.
namespace V1_0 = ::android::hardware::neuralnetworks::V1_0;

namespace armnn_driver
{

Expand Down Expand Up @@ -41,14 +45,14 @@ class DriverOptions
armnn::IClTunedParameters::Mode m_ClTunedParametersMode;
};

class ArmnnDriver : public IDevice {
class ArmnnDriver : public V1_0::IDevice {
public:
ArmnnDriver(DriverOptions options);
virtual ~ArmnnDriver() {}
virtual Return<void> getCapabilities(getCapabilities_cb _hidl_cb) override;
virtual Return<void> getSupportedOperations(const Model &model,
getSupportedOperations_cb _hidl_cb) override;
virtual Return<ErrorStatus> prepareModel(const Model &model,
virtual Return<void> getCapabilities(V1_0::IDevice::getCapabilities_cb _hidl_cb) override;
virtual Return<void> getSupportedOperations(const V1_0::Model &model,
V1_0::IDevice::getSupportedOperations_cb _hidl_cb) override;
virtual Return<ErrorStatus> prepareModel(const V1_0::Model &model,
const android::sp<IPreparedModelCallback>& callback);
virtual Return<DeviceStatus> getStatus() override;

Expand Down
10 changes: 8 additions & 2 deletions ArmnnPreparedModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#include <log/log.h>
#include <OperationsUtils.h>

#if defined(ARMNN_ANDROID_P)
// The headers of the ML framework have changed between Android O and Android P.
// The validation functions have been moved into their own header, ValidateHal.h.
#include <ValidateHal.h>
#endif

#include <cassert>
#include <cinttypes>

Expand Down Expand Up @@ -101,7 +107,7 @@ void ArmnnPreparedModel::DumpTensorsIfRequired(char const* tensorNamePrefix,

ArmnnPreparedModel::ArmnnPreparedModel(armnn::NetworkId networkId,
armnn::IRuntime* runtime,
const Model& model,
const V1_0::Model& model,
const std::string& requestInputsAndOutputsDumpDir)
: m_NetworkId(networkId)
, m_Runtime(runtime)
Expand Down Expand Up @@ -269,7 +275,7 @@ void ArmnnPreparedModel::ExecuteWithDummyInputs()
}
}

AndroidNnCpuExecutorPreparedModel::AndroidNnCpuExecutorPreparedModel(const Model& model,
AndroidNnCpuExecutorPreparedModel::AndroidNnCpuExecutorPreparedModel(const V1_0::Model& model,
const std::string& requestInputsAndOutputsDumpDir)
: m_Model(model)
, m_RequestInputsAndOutputsDumpDir(requestInputsAndOutputsDumpDir)
Expand Down
10 changes: 6 additions & 4 deletions ArmnnPreparedModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "NeuralNetworks.h"
#include <armnn/ArmNN.hpp>

#include "ArmnnDriver.hpp"

#include <string>
#include <vector>

Expand All @@ -22,7 +24,7 @@ class ArmnnPreparedModel : public IPreparedModel
public:
ArmnnPreparedModel(armnn::NetworkId networkId,
armnn::IRuntime* runtime,
const Model& model,
const V1_0::Model& model,
const std::string& requestInputsAndOutputsDumpDir);

virtual ~ArmnnPreparedModel();
Expand All @@ -46,7 +48,7 @@ class ArmnnPreparedModel : public IPreparedModel

armnn::NetworkId m_NetworkId;
armnn::IRuntime* m_Runtime;
Model m_Model;
V1_0::Model m_Model;
// There must be a single RequestThread for all ArmnnPreparedModel objects to ensure serial execution of workloads
// It is specific to this class, so it is declared as static here
static RequestThread m_RequestThread;
Expand All @@ -58,7 +60,7 @@ class AndroidNnCpuExecutorPreparedModel : public IPreparedModel
{
public:

AndroidNnCpuExecutorPreparedModel(const Model& model, const std::string& requestInputsAndOutputsDumpDir);
AndroidNnCpuExecutorPreparedModel(const V1_0::Model& model, const std::string& requestInputsAndOutputsDumpDir);
virtual ~AndroidNnCpuExecutorPreparedModel() { }

bool Initialize();
Expand All @@ -74,7 +76,7 @@ class AndroidNnCpuExecutorPreparedModel : public IPreparedModel
const hidl_vec<RequestArgument>& requestArgs,
const std::vector<android::nn::RunTimePoolInfo>& requestPoolInfos);

Model m_Model;
V1_0::Model m_Model;
std::vector<android::nn::RunTimePoolInfo> m_ModelPoolInfos;
const std::string& m_RequestInputsAndOutputsDumpDir;
uint32_t m_RequestCount;
Expand Down
Loading

0 comments on commit deb3bdb

Please sign in to comment.