From ec1e5b8d0a0eeba7eae0f1fdb5e32c72f8a8093c Mon Sep 17 00:00:00 2001 From: Kevin May Date: Wed, 26 Feb 2020 17:00:39 +0000 Subject: IVGCVSW-4473 Android R pre Hal 1_3 build changes * Update ErrorStatus to V1_0::ErrorStatus * Update Request to V1_0::Request * Update OperandType to V1_2::OperandType * Add namespace android::nn::hal in ArmnnDriverImpl for R only * Add missing g_RelaxedFloat32toFloat16PerformancePowerUsageName * Add namespace V1_0 or V1_1 where necessary * Update Android.mk with R macro and android.hardware.neuralnetworks@1.3 * Remove androidnn.go * include IAllocator in DriverTestHelpers * Remove unused LOCAL_CFLAGS Signed-off-by: Kevin May Change-Id: I1787f1ed6784b3bbec017536d87d49197405e853 Signed-off-by: Kevin May --- test/1.1/Mean.cpp | 6 ++-- test/1.1/Transpose.cpp | 2 +- test/1.2/Capabilities.cpp | 82 ++++++++++++++++++++++++---------------------- test/Android.mk | 44 ++++++++++++++++++------- test/Concat.cpp | 26 +++++++-------- test/Concurrent.cpp | 2 +- test/Convolution2D.hpp | 2 +- test/DriverTestHelpers.cpp | 41 ++++++++++++----------- test/DriverTestHelpers.hpp | 58 +++++++++++++++++--------------- test/FullyConnected.cpp | 14 ++++---- test/GenericLayerTests.cpp | 37 ++++++++------------- test/Lstm.hpp | 14 ++++---- test/Tests.cpp | 6 ++-- 13 files changed, 176 insertions(+), 158 deletions(-) (limited to 'test') diff --git a/test/1.1/Mean.cpp b/test/1.1/Mean.cpp index 529371e1..10ca3aec 100644 --- a/test/1.1/Mean.cpp +++ b/test/1.1/Mean.cpp @@ -78,7 +78,7 @@ void MeanTestImpl(const TestTensor& input, outArg.dimensions = expectedOutput.GetDimensions(); // Make the request based on the arguments - Request request = {}; + V1_0::Request request = {}; request.inputs = hidl_vec{ inArg }; request.outputs = hidl_vec{ outArg }; @@ -89,8 +89,8 @@ void MeanTestImpl(const TestTensor& input, android::sp outMemory = AddPoolAndGetData(expectedOutput.GetNumElements(), request); const float* outputData = static_cast(static_cast(outMemory->getPointer())); - ErrorStatus execStatus = Execute(preparedModel, request); - BOOST_TEST(execStatus == ErrorStatus::NONE); + V1_0::ErrorStatus execStatus = Execute(preparedModel, request); + BOOST_TEST(execStatus == V1_0::ErrorStatus::NONE); const float* expectedOutputData = expectedOutput.GetData(); for (unsigned int i = 0; i < expectedOutput.GetNumElements(); i++) diff --git a/test/1.1/Transpose.cpp b/test/1.1/Transpose.cpp index 4d4238ba..5679ca22 100644 --- a/test/1.1/Transpose.cpp +++ b/test/1.1/Transpose.cpp @@ -76,7 +76,7 @@ void TransposeTestImpl(const TestTensor & inputs, int32_t perm[], output.dimensions = expectedOutputTensor.GetDimensions(); // make the request based on the arguments - Request request = {}; + V1_0::Request request = {}; request.inputs = hidl_vec{input}; request.outputs = hidl_vec{output}; diff --git a/test/1.2/Capabilities.cpp b/test/1.2/Capabilities.cpp index 8a769db2..2bbd7bed 100644 --- a/test/1.2/Capabilities.cpp +++ b/test/1.2/Capabilities.cpp @@ -57,8 +57,9 @@ struct CapabilitiesFixture } }; -void CheckOperandType(const V1_2::Capabilities& capabilities, OperandType type, float execTime, float powerUsage) +void CheckOperandType(const V1_2::Capabilities& capabilities, V1_2::OperandType type, float execTime, float powerUsage) { + using namespace armnn_driver::hal_1_2; PerformanceInfo perfInfo = android::nn::lookup(capabilities.operandPerformance, type); BOOST_ASSERT(perfInfo.execTime == execTime); BOOST_ASSERT(perfInfo.powerUsage == powerUsage); @@ -71,28 +72,28 @@ BOOST_AUTO_TEST_CASE(PerformanceCapabilitiesWithRuntime) using namespace armnn_driver::hal_1_2; using namespace android::nn; - auto getCapabilitiesFn = [&](ErrorStatus error, const V1_2::Capabilities& capabilities) + auto getCapabilitiesFn = [&](V1_0::ErrorStatus error, const V1_2::Capabilities& capabilities) { - CheckOperandType(capabilities, OperandType::TENSOR_FLOAT32, 2.0f, 2.1f); - CheckOperandType(capabilities, OperandType::FLOAT32, 2.2f, 2.3f); - CheckOperandType(capabilities, OperandType::TENSOR_FLOAT16, 2.4f, 2.5f); - CheckOperandType(capabilities, OperandType::FLOAT16, 2.6f, 2.7f); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT8_ASYMM, 2.8f, 2.9f); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT16_SYMM, 3.0f, 3.1f); - CheckOperandType(capabilities, OperandType::TENSOR_INT32, 3.2f, 3.3f); - CheckOperandType(capabilities, OperandType::INT32, 3.4f, 3.5f); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT8_SYMM, 2.8f, 2.9f); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL, 2.8f, 2.9f); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT32, 2.0f, 2.1f); + CheckOperandType(capabilities, V1_2::OperandType::FLOAT32, 2.2f, 2.3f); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT16, 2.4f, 2.5f); + CheckOperandType(capabilities, V1_2::OperandType::FLOAT16, 2.6f, 2.7f); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_ASYMM, 2.8f, 2.9f); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_SYMM, 3.0f, 3.1f); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_INT32, 3.2f, 3.3f); + CheckOperandType(capabilities, V1_2::OperandType::INT32, 3.4f, 3.5f); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM, 2.8f, 2.9f); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL, 2.8f, 2.9f); // Unsupported operands take FLT_MAX value - CheckOperandType(capabilities, OperandType::UINT32, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::BOOL, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::OEM, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX); - - BOOST_ASSERT(error == ErrorStatus::NONE); + CheckOperandType(capabilities, V1_2::OperandType::UINT32, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::BOOL, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::OEM, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX); + + BOOST_ASSERT(error == V1_0::ErrorStatus::NONE); }; __system_property_set("Armnn.operandTypeTensorFloat32Performance.execTime", "2.0f"); @@ -129,28 +130,31 @@ BOOST_AUTO_TEST_CASE(PerformanceCapabilitiesUndefined) float defaultValue = .1f; - auto getCapabilitiesFn = [&](ErrorStatus error, const V1_2::Capabilities& capabilities) + auto getCapabilitiesFn = [&](V1_0::ErrorStatus error, const V1_2::Capabilities& capabilities) { - CheckOperandType(capabilities, OperandType::TENSOR_FLOAT32, defaultValue, defaultValue); - CheckOperandType(capabilities, OperandType::FLOAT32, defaultValue, defaultValue); - CheckOperandType(capabilities, OperandType::TENSOR_FLOAT16, defaultValue, defaultValue); - CheckOperandType(capabilities, OperandType::FLOAT16, defaultValue, defaultValue); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT8_ASYMM, defaultValue, defaultValue); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT16_SYMM, defaultValue, defaultValue); - CheckOperandType(capabilities, OperandType::TENSOR_INT32, defaultValue, defaultValue); - CheckOperandType(capabilities, OperandType::INT32, defaultValue, defaultValue); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL, defaultValue, defaultValue); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT8_SYMM, defaultValue, defaultValue); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT32, defaultValue, defaultValue); + CheckOperandType(capabilities, V1_2::OperandType::FLOAT32, defaultValue, defaultValue); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_FLOAT16, defaultValue, defaultValue); + CheckOperandType(capabilities, V1_2::OperandType::FLOAT16, defaultValue, defaultValue); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_ASYMM, defaultValue, defaultValue); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_SYMM, defaultValue, defaultValue); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_INT32, defaultValue, defaultValue); + CheckOperandType(capabilities, V1_2::OperandType::INT32, defaultValue, defaultValue); + CheckOperandType(capabilities, + V1_2::OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL, + defaultValue, + defaultValue); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT8_SYMM, defaultValue, defaultValue); // Unsupported operands take FLT_MAX value - CheckOperandType(capabilities, OperandType::UINT32, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::BOOL, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::OEM, FLT_MAX, FLT_MAX); - CheckOperandType(capabilities, OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX); - - BOOST_ASSERT(error == ErrorStatus::NONE); + CheckOperandType(capabilities, V1_2::OperandType::UINT32, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::BOOL, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_QUANT16_ASYMM, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_BOOL8, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::OEM, FLT_MAX, FLT_MAX); + CheckOperandType(capabilities, V1_2::OperandType::TENSOR_OEM_BYTE, FLT_MAX, FLT_MAX); + + BOOST_ASSERT(error == V1_0::ErrorStatus::NONE); }; armnn::IRuntime::CreationOptions options; diff --git a/test/Android.mk b/test/Android.mk index 13a36b54..0448d187 100644 --- a/test/Android.mk +++ b/test/Android.mk @@ -42,12 +42,11 @@ LOCAL_CFLAGS := \ -O0 \ -UNDEBUG -ifeq ($(P_OR_LATER),1) -# 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. +# Required to build with the changes made to the Android ML framework specific to Android R +ifeq ($(R_OR_LATER),1) LOCAL_CFLAGS+= \ - -DARMNN_ANDROID_P -endif # PLATFORM_VERSION == 9 + -DARMNN_ANDROID_R +endif # R or later ifeq ($(Q_OR_LATER),1) LOCAL_CFLAGS += \ @@ -108,6 +107,11 @@ LOCAL_SHARED_LIBRARIES+= \ android.hardware.neuralnetworks@1.2 endif # PLATFORM_VERSION == Q +ifeq ($(R_OR_LATER),1) +LOCAL_SHARED_LIBRARIES+= \ + android.hardware.neuralnetworks@1.3 +endif # R or later + ifeq ($(ARMNN_COMPUTE_CL_ENABLED),1) LOCAL_SHARED_LIBRARIES+= \ libOpenCL @@ -148,9 +152,14 @@ LOCAL_CFLAGS := \ -Werror \ -O0 \ -UNDEBUG \ - -DARMNN_ANDROID_P \ -DARMNN_ANDROID_NN_V1_1 +# Required to build with the changes made to the Android ML framework specific to Android R +ifeq ($(R_OR_LATER),1) +LOCAL_CFLAGS+= \ + -DARMNN_ANDROID_R +endif # R or later + ifeq ($(Q_OR_LATER),1) LOCAL_CFLAGS += \ -DBOOST_NO_AUTO_PTR @@ -207,6 +216,11 @@ LOCAL_SHARED_LIBRARIES+= \ android.hardware.neuralnetworks@1.2 endif # PLATFORM_VERSION == Q +ifeq ($(R_OR_LATER),1) +LOCAL_SHARED_LIBRARIES+= \ + android.hardware.neuralnetworks@1.3 +endif # R or later + ifeq ($(ARMNN_COMPUTE_CL_ENABLED),1) LOCAL_SHARED_LIBRARIES+= \ libOpenCL @@ -245,13 +259,14 @@ LOCAL_CFLAGS := \ -Werror \ -O0 \ -UNDEBUG \ - -DARMNN_ANDROID_Q \ + -DBOOST_NO_AUTO_PTR \ -DARMNN_ANDROID_NN_V1_2 -ifeq ($(Q_OR_LATER),1) -LOCAL_CFLAGS += \ - -DBOOST_NO_AUTO_PTR -endif # PLATFORM_VERSION == Q or later +# Required to build with the changes made to the Android ML framework specific to Android R +ifeq ($(R_OR_LATER),1) +LOCAL_CFLAGS+= \ + -DARMNN_ANDROID_R +endif # R or later LOCAL_SRC_FILES := \ 1.0/Convolution2D.cpp \ @@ -303,6 +318,11 @@ LOCAL_SHARED_LIBRARIES := \ android.hidl.allocator@1.0 \ android.hidl.memory@1.0 +ifeq ($(R_OR_LATER),1) +LOCAL_SHARED_LIBRARIES+= \ + android.hardware.neuralnetworks@1.3 +endif # R or later + ifeq ($(ARMNN_COMPUTE_CL_ENABLED),1) LOCAL_SHARED_LIBRARIES+= \ libOpenCL @@ -310,4 +330,4 @@ endif include $(BUILD_EXECUTABLE) -endif # PLATFORM_VERSION == Q +endif # PLATFORM_VERSION == Q \ No newline at end of file diff --git a/test/Concat.cpp b/test/Concat.cpp index 9beb67bd..b99e31cc 100644 --- a/test/Concat.cpp +++ b/test/Concat.cpp @@ -35,8 +35,8 @@ ConcatTestImpl(const std::vector & inputs, int32_t concatAxis, const TestTensor & expectedOutputTensor, armnn::Compute computeDevice, - ErrorStatus expectedPrepareStatus=ErrorStatus::NONE, - ErrorStatus expectedExecStatus=ErrorStatus::NONE) + V1_0::ErrorStatus expectedPrepareStatus=V1_0::ErrorStatus::NONE, + V1_0::ErrorStatus expectedExecStatus=V1_0::ErrorStatus::NONE) { std::unique_ptr driver = std::make_unique(DriverOptions(computeDevice)); HalPolicy::Model model{}; @@ -59,13 +59,13 @@ ConcatTestImpl(const std::vector & inputs, model.operations[0].outputs = hidl_vec{static_cast(inputs.size()+1)}; // make the prepared model - ErrorStatus prepareStatus=ErrorStatus::NONE; + V1_0::ErrorStatus prepareStatus=V1_0::ErrorStatus::NONE; android::sp preparedModel = PrepareModelWithStatus(model, *driver, prepareStatus, expectedPrepareStatus); BOOST_TEST(prepareStatus == expectedPrepareStatus); - if (prepareStatus != ErrorStatus::NONE) + if (prepareStatus != V1_0::ErrorStatus::NONE) { // prepare failed, we cannot continue return; @@ -111,7 +111,7 @@ ConcatTestImpl(const std::vector & inputs, } // make the request based on the arguments - Request request = {}; + V1_0::Request request = {}; request.inputs = inputArguments; request.outputs = outputArguments; @@ -131,7 +131,7 @@ ConcatTestImpl(const std::vector & inputs, auto execStatus = Execute(preparedModel, request, expectedExecStatus); BOOST_TEST(execStatus == expectedExecStatus); - if (execStatus == ErrorStatus::NONE) + if (execStatus == V1_0::ErrorStatus::NONE) { // check the result if there was no error const float * expectedOutput = expectedOutputTensor.GetData(); @@ -310,7 +310,7 @@ BOOST_DATA_TEST_CASE(AxisTooBig, COMPUTE_DEVICES) // The axis must be within the range of [-rank(values), rank(values)) // see: https://www.tensorflow.org/api_docs/python/tf/concat TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}}; - ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; + V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus); } @@ -323,7 +323,7 @@ BOOST_DATA_TEST_CASE(AxisTooSmall, COMPUTE_DEVICES) // The axis must be within the range of [-rank(values), rank(values)) // see: https://www.tensorflow.org/api_docs/python/tf/concat TestTensor uncheckedOutput{armnn::TensorShape{1,1,1,1},{0}}; - ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; + V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; ConcatTestImpl({&aIn, &bIn}, axis, uncheckedOutput, sample, expectedParserStatus); } @@ -333,7 +333,7 @@ BOOST_DATA_TEST_CASE(TooFewInputs, COMPUTE_DEVICES) TestTensor aIn{armnn::TensorShape{1,1,1,1},{0}}; // We need at least two tensors to concatenate - ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; + V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; ConcatTestImpl({&aIn}, axis, aIn, sample, expectedParserStatus); } @@ -350,7 +350,7 @@ BOOST_DATA_TEST_CASE(MismatchedInputDimensions, COMPUTE_DEVICES) 2, 3, 7, 8, 9, 11}}; // The input dimensions must be compatible - ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; + V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; ConcatTestImpl({&aIn, &bIn, &mismatched}, axis, expected, sample, expectedParserStatus); } @@ -362,7 +362,7 @@ BOOST_DATA_TEST_CASE(MismatchedInputRanks, COMPUTE_DEVICES) TestTensor expected{armnn::TensorShape{1,1,3},{0,1,4}}; // The input dimensions must be compatible - ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; + V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; ConcatTestImpl({&aIn, &bIn}, axis, expected, sample, expectedParserStatus); } @@ -380,7 +380,7 @@ BOOST_DATA_TEST_CASE(MismatchedOutputDimensions, COMPUTE_DEVICES) 2, 3, 7, 8, 9, 11}}; // The input and output dimensions must be compatible - ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; + V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus); } @@ -398,7 +398,7 @@ BOOST_DATA_TEST_CASE(MismatchedOutputRank, COMPUTE_DEVICES) 2, 3, 7, 8, 9, 11}}; // The input and output ranks must match - ErrorStatus expectedParserStatus = ErrorStatus::GENERAL_FAILURE; + V1_0::ErrorStatus expectedParserStatus = V1_0::ErrorStatus::GENERAL_FAILURE; ConcatTestImpl({&aIn, &bIn, &cIn}, axis, mismatched, sample, expectedParserStatus); } diff --git a/test/Concurrent.cpp b/test/Concurrent.cpp index 9fe6f46e..ecf25e17 100644 --- a/test/Concurrent.cpp +++ b/test/Concurrent.cpp @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(ConcurrentExecute) output.dimensions = hidl_vec{}; // build the requests - Request requests[maxRequests]; + V1_0::Request requests[maxRequests]; android::sp outMemory[maxRequests]; float* outdata[maxRequests]; for (size_t i = 0; i < maxRequests; ++i) diff --git a/test/Convolution2D.hpp b/test/Convolution2D.hpp index 180f57e2..002677fe 100644 --- a/test/Convolution2D.hpp +++ b/test/Convolution2D.hpp @@ -93,7 +93,7 @@ void PaddingTestImpl(android::nn::PaddingScheme paddingScheme, bool fp16Enabled output.location = outloc; output.dimensions = hidl_vec{}; - Request request = {}; + V1_0::Request request = {}; request.inputs = hidl_vec{input}; request.outputs = hidl_vec{output}; diff --git a/test/DriverTestHelpers.cpp b/test/DriverTestHelpers.cpp index 3a3c98ff..0bc0cf76 100644 --- a/test/DriverTestHelpers.cpp +++ b/test/DriverTestHelpers.cpp @@ -15,7 +15,7 @@ namespace neuralnetworks namespace V1_0 { -std::ostream& operator<<(std::ostream& os, ErrorStatus stat) +std::ostream& operator<<(std::ostream& os, V1_0::ErrorStatus stat) { return os << static_cast(stat); } @@ -31,7 +31,7 @@ namespace driverTestHelpers using namespace android::hardware; using namespace armnn_driver; -Return ExecutionCallback::notify(ErrorStatus status) +Return ExecutionCallback::notify(V1_0::ErrorStatus status) { (void)status; ALOGI("ExecutionCallback::notify invoked"); @@ -53,7 +53,7 @@ Return ExecutionCallback::wait() return Void(); } -Return PreparedModelCallback::notify(ErrorStatus status, +Return PreparedModelCallback::notify(V1_0::ErrorStatus status, const android::sp& preparedModel) { m_ErrorStatus = status; @@ -63,7 +63,7 @@ Return PreparedModelCallback::notify(ErrorStatus status, #ifdef ARMNN_ANDROID_NN_V1_2 -Return PreparedModelCallback_1_2::notify(ErrorStatus status, +Return PreparedModelCallback_1_2::notify(V1_0::ErrorStatus status, const android::sp& preparedModel) { m_ErrorStatus = status; @@ -71,7 +71,7 @@ Return PreparedModelCallback_1_2::notify(ErrorStatus status, return Void(); } -Return PreparedModelCallback_1_2::notify_1_2(ErrorStatus status, +Return PreparedModelCallback_1_2::notify_1_2(V1_0::ErrorStatus status, const android::sp& preparedModel) { m_ErrorStatus = status; @@ -104,15 +104,15 @@ hidl_memory allocateSharedMemory(int64_t size) android::sp PrepareModelWithStatus(const V1_0::Model& model, armnn_driver::ArmnnDriver& driver, - ErrorStatus& prepareStatus, - ErrorStatus expectedStatus) + V1_0::ErrorStatus& prepareStatus, + V1_0::ErrorStatus expectedStatus) { android::sp cb(new PreparedModelCallback()); driver.prepareModel(model, cb); prepareStatus = cb->GetErrorStatus(); BOOST_TEST(prepareStatus == expectedStatus); - if (expectedStatus == ErrorStatus::NONE) + if (expectedStatus == V1_0::ErrorStatus::NONE) { BOOST_TEST((cb->GetPreparedModel() != nullptr)); } @@ -123,15 +123,15 @@ android::sp PrepareModelWithStatus(const V1_0::Model& mode android::sp PrepareModelWithStatus(const V1_1::Model& model, armnn_driver::ArmnnDriver& driver, - ErrorStatus& prepareStatus, - ErrorStatus expectedStatus) + V1_0::ErrorStatus& prepareStatus, + V1_0::ErrorStatus expectedStatus) { android::sp cb(new PreparedModelCallback()); driver.prepareModel_1_1(model, V1_1::ExecutionPreference::LOW_POWER, cb); prepareStatus = cb->GetErrorStatus(); BOOST_TEST(prepareStatus == expectedStatus); - if (expectedStatus == ErrorStatus::NONE) + if (expectedStatus == V1_0::ErrorStatus::NONE) { BOOST_TEST((cb->GetPreparedModel() != nullptr)); } @@ -144,8 +144,8 @@ android::sp PrepareModelWithStatus(const V1_1::Model& mode android::sp PrepareModelWithStatus_1_2(const armnn_driver::hal_1_2::HalPolicy::Model& model, armnn_driver::ArmnnDriver& driver, - ErrorStatus& prepareStatus, - ErrorStatus expectedStatus) + V1_0::ErrorStatus& prepareStatus, + V1_0::ErrorStatus expectedStatus) { android::sp cb(new PreparedModelCallback_1_2()); @@ -157,7 +157,7 @@ android::sp PrepareModelWithStatus_1_2(const armnn_driver: prepareStatus = cb->GetErrorStatus(); BOOST_TEST(prepareStatus == expectedStatus); - if (expectedStatus == ErrorStatus::NONE) + if (expectedStatus == V1_0::ErrorStatus::NONE) { BOOST_TEST((cb->GetPreparedModel_1_2() != nullptr)); } @@ -166,23 +166,24 @@ android::sp PrepareModelWithStatus_1_2(const armnn_driver: #endif -ErrorStatus Execute(android::sp preparedModel, - const Request& request, - ErrorStatus expectedStatus) +V1_0::ErrorStatus Execute(android::sp preparedModel, + const V1_0::Request& request, + V1_0::ErrorStatus expectedStatus) { BOOST_TEST(preparedModel.get() != nullptr); android::sp cb(new ExecutionCallback()); - ErrorStatus execStatus = preparedModel->execute(request, cb); + V1_0::ErrorStatus execStatus = preparedModel->execute(request, cb); BOOST_TEST(execStatus == expectedStatus); ALOGI("Execute: waiting for callback to be invoked"); cb->wait(); return execStatus; } -android::sp ExecuteNoWait(android::sp preparedModel, const Request& request) +android::sp ExecuteNoWait(android::sp preparedModel, + const V1_0::Request& request) { android::sp cb(new ExecutionCallback()); - BOOST_TEST(preparedModel->execute(request, cb) == ErrorStatus::NONE); + BOOST_TEST(preparedModel->execute(request, cb) == V1_0::ErrorStatus::NONE); ALOGI("ExecuteNoWait: returning callback object"); return cb; } diff --git a/test/DriverTestHelpers.hpp b/test/DriverTestHelpers.hpp index 9da02603..7a35b23e 100644 --- a/test/DriverTestHelpers.hpp +++ b/test/DriverTestHelpers.hpp @@ -12,6 +12,10 @@ #include #include +#include + +using ::android::hidl::allocator::V1_0::IAllocator; + namespace android { namespace hardware @@ -21,7 +25,7 @@ namespace neuralnetworks namespace V1_0 { -std::ostream& operator<<(std::ostream& os, ErrorStatus stat); +std::ostream& operator<<(std::ostream& os, V1_0::ErrorStatus stat); } // namespace android::hardware::neuralnetworks::V1_0 } // namespace android::hardware::neuralnetworks @@ -36,7 +40,7 @@ std::ostream& operator<<(std::ostream& os, V1_0::ErrorStatus stat); struct ExecutionCallback : public V1_0::IExecutionCallback { ExecutionCallback() : mNotified(false) {} - Return notify(ErrorStatus status) override; + Return notify(V1_0::ErrorStatus status) override; /// wait until the callback has notified us that it is done Return wait(); @@ -52,18 +56,18 @@ class PreparedModelCallback : public V1_0::IPreparedModelCallback { public: PreparedModelCallback() - : m_ErrorStatus(ErrorStatus::NONE) + : m_ErrorStatus(V1_0::ErrorStatus::NONE) , m_PreparedModel() { } ~PreparedModelCallback() override { } - Return notify(ErrorStatus status, + Return notify(V1_0::ErrorStatus status, const android::sp& preparedModel) override; - ErrorStatus GetErrorStatus() { return m_ErrorStatus; } + V1_0::ErrorStatus GetErrorStatus() { return m_ErrorStatus; } android::sp GetPreparedModel() { return m_PreparedModel; } private: - ErrorStatus m_ErrorStatus; + V1_0::ErrorStatus m_ErrorStatus; android::sp m_PreparedModel; }; @@ -73,24 +77,24 @@ class PreparedModelCallback_1_2 : public V1_2::IPreparedModelCallback { public: PreparedModelCallback_1_2() - : m_ErrorStatus(ErrorStatus::NONE) + : m_ErrorStatus(V1_0::ErrorStatus::NONE) , m_PreparedModel() , m_PreparedModel_1_2() { } ~PreparedModelCallback_1_2() override { } - Return notify(ErrorStatus status, const android::sp& preparedModel) override; + Return notify(V1_0::ErrorStatus status, const android::sp& preparedModel) override; - Return notify_1_2(ErrorStatus status, const android::sp& preparedModel) override; + Return notify_1_2(V1_0::ErrorStatus status, const android::sp& preparedModel) override; - ErrorStatus GetErrorStatus() { return m_ErrorStatus; } + V1_0::ErrorStatus GetErrorStatus() { return m_ErrorStatus; } android::sp GetPreparedModel() { return m_PreparedModel; } android::sp GetPreparedModel_1_2() { return m_PreparedModel_1_2; } private: - ErrorStatus m_ErrorStatus; + V1_0::ErrorStatus m_ErrorStatus; android::sp m_PreparedModel; android::sp m_PreparedModel_1_2; }; @@ -100,7 +104,7 @@ private: hidl_memory allocateSharedMemory(int64_t size); template -android::sp AddPoolAndGetData(uint32_t size, Request& request) +android::sp AddPoolAndGetData(uint32_t size, V1_0::Request& request) { hidl_memory pool; @@ -119,7 +123,7 @@ android::sp AddPoolAndGetData(uint32_t size, Request& request) } template -void AddPoolAndSetData(uint32_t size, Request& request, const T* data) +void AddPoolAndSetData(uint32_t size, V1_0::Request& request, const T* data) { android::sp memory = AddPoolAndGetData(size, request); @@ -201,7 +205,7 @@ void AddTensorOperand(HalModel& model, const hidl_vec& dimensions, const T* values, HalOperandType operandType = HalOperandType::TENSOR_FLOAT32, - HalOperandLifeTime operandLifeTime = HalOperandLifeTime::CONSTANT_COPY, + HalOperandLifeTime operandLifeTime = V1_0::OperandLifeTime::CONSTANT_COPY, double scale = 0.f, int offset = 0) { @@ -247,7 +251,7 @@ void AddTensorOperand(HalModel& model, const hidl_vec& dimensions, const std::vector& values, HalOperandType operandType = HalPolicy::OperandType::TENSOR_FLOAT32, - HalOperandLifeTime operandLifeTime = HalOperandLifeTime::CONSTANT_COPY, + HalOperandLifeTime operandLifeTime = V1_0::OperandLifeTime::CONSTANT_COPY, double scale = 0.f, int offset = 0) { @@ -306,15 +310,15 @@ void AddOutputOperand(HalModel& model, android::sp PrepareModelWithStatus(const V1_0::Model& model, armnn_driver::ArmnnDriver& driver, - ErrorStatus& prepareStatus, - ErrorStatus expectedStatus = ErrorStatus::NONE); + V1_0::ErrorStatus& prepareStatus, + V1_0::ErrorStatus expectedStatus = V1_0::ErrorStatus::NONE); #if defined(ARMNN_ANDROID_NN_V1_1) || defined(ARMNN_ANDROID_NN_V1_2) android::sp PrepareModelWithStatus(const V1_1::Model& model, armnn_driver::ArmnnDriver& driver, - ErrorStatus& prepareStatus, - ErrorStatus expectedStatus = ErrorStatus::NONE); + V1_0::ErrorStatus& prepareStatus, + V1_0::ErrorStatus expectedStatus = V1_0::ErrorStatus::NONE); #endif @@ -322,7 +326,7 @@ template android::sp PrepareModel(const HalModel& model, armnn_driver::ArmnnDriver& driver) { - ErrorStatus prepareStatus = ErrorStatus::NONE; + V1_0::ErrorStatus prepareStatus = V1_0::ErrorStatus::NONE; return PrepareModelWithStatus(model, driver, prepareStatus); } @@ -330,25 +334,25 @@ android::sp PrepareModel(const HalModel& model, android::sp PrepareModelWithStatus_1_2(const armnn_driver::hal_1_2::HalPolicy::Model& model, armnn_driver::ArmnnDriver& driver, - ErrorStatus& prepareStatus, - ErrorStatus expectedStatus = ErrorStatus::NONE); + V1_0::ErrorStatus& prepareStatus, + V1_0::ErrorStatus expectedStatus = V1_0::ErrorStatus::NONE); template android::sp PrepareModel_1_2(const HalModel& model, armnn_driver::ArmnnDriver& driver) { - ErrorStatus prepareStatus = ErrorStatus::NONE; + V1_0::ErrorStatus prepareStatus = V1_0::ErrorStatus::NONE; return PrepareModelWithStatus_1_2(model, driver, prepareStatus); } #endif -ErrorStatus Execute(android::sp preparedModel, - const Request& request, - ErrorStatus expectedStatus = ErrorStatus::NONE); +V1_0::ErrorStatus Execute(android::sp preparedModel, + const V1_0::Request& request, + V1_0::ErrorStatus expectedStatus = V1_0::ErrorStatus::NONE); android::sp ExecuteNoWait(android::sp preparedModel, - const Request& request); + const V1_0::Request& request); } // namespace driverTestHelpers diff --git a/test/FullyConnected.cpp b/test/FullyConnected.cpp index e8b5dc26..a6983dd8 100644 --- a/test/FullyConnected.cpp +++ b/test/FullyConnected.cpp @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(FullyConnected) output.location = outloc; output.dimensions = hidl_vec{}; - Request request = {}; + V1_0::Request request = {}; request.inputs = hidl_vec{input}; request.outputs = hidl_vec{output}; @@ -87,10 +87,10 @@ BOOST_AUTO_TEST_CASE(TestFullyConnected4dInput) { auto driver = std::make_unique(DriverOptions(armnn::Compute::CpuRef)); - ErrorStatus error; + V1_0::ErrorStatus error; std::vector sup; - ArmnnDriver::getSupportedOperations_cb cb = [&](ErrorStatus status, const std::vector& supported) + ArmnnDriver::getSupportedOperations_cb cb = [&](V1_0::ErrorStatus status, const std::vector& supported) { error = status; sup = supported; @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(TestFullyConnected4dInput) output.location = outloc; output.dimensions = hidl_vec{}; - Request request = {}; + V1_0::Request request = {}; request.inputs = hidl_vec{input}; request.outputs = hidl_vec{output}; @@ -173,10 +173,10 @@ BOOST_AUTO_TEST_CASE(TestFullyConnected4dInputReshape) { auto driver = std::make_unique(DriverOptions(armnn::Compute::CpuRef)); - ErrorStatus error; + V1_0::ErrorStatus error; std::vector sup; - ArmnnDriver::getSupportedOperations_cb cb = [&](ErrorStatus status, const std::vector& supported) + ArmnnDriver::getSupportedOperations_cb cb = [&](V1_0::ErrorStatus status, const std::vector& supported) { error = status; sup = supported; @@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(TestFullyConnected4dInputReshape) output.location = outloc; output.dimensions = hidl_vec{}; - Request request = {}; + V1_0::Request request = {}; request.inputs = hidl_vec{input}; request.outputs = hidl_vec{output}; diff --git a/test/GenericLayerTests.cpp b/test/GenericLayerTests.cpp index 3788e66a..961ab166 100644 --- a/test/GenericLayerTests.cpp +++ b/test/GenericLayerTests.cpp @@ -22,10 +22,10 @@ BOOST_AUTO_TEST_CASE(GetSupportedOperations) { auto driver = std::make_unique(DriverOptions(armnn::Compute::CpuRef)); - ErrorStatus errorStatus; + V1_0::ErrorStatus errorStatus; std::vector supported; - auto cb = [&](ErrorStatus _errorStatus, const std::vector& _supported) + auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector& _supported) { errorStatus = _errorStatus; supported = _supported; @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(GetSupportedOperations) model0.operations[0].outputs = hidl_vec{4}; driver->getSupportedOperations(model0, cb); - BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); + BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE); BOOST_TEST(supported.size() == (size_t)1); BOOST_TEST(supported[0] == true); @@ -81,19 +81,8 @@ BOOST_AUTO_TEST_CASE(GetSupportedOperations) driver->getSupportedOperations(model1, cb); -#if defined(ARMNN_ANDROID_P) || defined(ARMNN_ANDROID_Q) - // In Android P, android::nn::validateModel returns INVALID_ARGUMENT, because of the wrong number of inputs for the - // fully connected layer (1 instead of 4) - BOOST_TEST((int)errorStatus == (int)ErrorStatus::INVALID_ARGUMENT); + BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::INVALID_ARGUMENT); BOOST_TEST(supported.empty()); -#else - // In Android O, android::nn::validateModel indicates that the second (wrong) fully connected layer in unsupported - // in the vector of flags returned by the callback - BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); - BOOST_TEST(supported.size() == (size_t)2); - BOOST_TEST(supported[0] == true); - BOOST_TEST(supported[1] == false); -#endif // Test Broadcast on add/mul operators HalPolicy::Model model2 = {}; @@ -115,7 +104,7 @@ BOOST_AUTO_TEST_CASE(GetSupportedOperations) model2.operations[1].outputs = hidl_vec{4}; driver->getSupportedOperations(model2, cb); - BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); + BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE); BOOST_TEST(supported.size() == (size_t)2); BOOST_TEST(supported[0] == true); BOOST_TEST(supported[1] == true); @@ -144,7 +133,7 @@ BOOST_AUTO_TEST_CASE(GetSupportedOperations) model3.operations[0].outputs = hidl_vec{3, 4}; driver->getSupportedOperations(model3, cb); - BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); + BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE); BOOST_TEST(supported.size() == (size_t)1); BOOST_TEST(supported[0] == false); @@ -159,7 +148,7 @@ BOOST_AUTO_TEST_CASE(GetSupportedOperations) model4.operations[0].outputs = hidl_vec{0}; driver->getSupportedOperations(model4, cb); - BOOST_TEST((int)errorStatus == (int)ErrorStatus::INVALID_ARGUMENT); + BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::INVALID_ARGUMENT); BOOST_TEST(supported.empty()); } @@ -170,10 +159,10 @@ BOOST_AUTO_TEST_CASE(UnsupportedLayerContinueOnFailure) { auto driver = std::make_unique(DriverOptions(armnn::Compute::CpuRef)); - ErrorStatus errorStatus; + V1_0::ErrorStatus errorStatus; std::vector supported; - auto cb = [&](ErrorStatus _errorStatus, const std::vector& _supported) + auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector& _supported) { errorStatus = _errorStatus; supported = _supported; @@ -233,7 +222,7 @@ BOOST_AUTO_TEST_CASE(UnsupportedLayerContinueOnFailure) // We are testing that the unsupported layers return false and the test continues rather than failing and stopping driver->getSupportedOperations(model, cb); - BOOST_TEST((int)errorStatus == (int)ErrorStatus::NONE); + BOOST_TEST((int)errorStatus == (int)V1_0::ErrorStatus::NONE); BOOST_TEST(supported.size() == (size_t)3); BOOST_TEST(supported[0] == false); BOOST_TEST(supported[1] == true); @@ -246,10 +235,10 @@ BOOST_AUTO_TEST_CASE(ModelToINetworkConverterMemPoolFail) { auto driver = std::make_unique(DriverOptions(armnn::Compute::CpuRef)); - ErrorStatus errorStatus; + V1_0::ErrorStatus errorStatus; std::vector supported; - auto cb = [&](ErrorStatus _errorStatus, const std::vector& _supported) + auto cb = [&](V1_0::ErrorStatus _errorStatus, const std::vector& _supported) { errorStatus = _errorStatus; supported = _supported; @@ -261,7 +250,7 @@ BOOST_AUTO_TEST_CASE(ModelToINetworkConverterMemPoolFail) // Memory pool mapping should fail, we should report an error driver->getSupportedOperations(model, cb); - BOOST_TEST((int)errorStatus != (int)ErrorStatus::NONE); + BOOST_TEST((int)errorStatus != (int)V1_0::ErrorStatus::NONE); BOOST_TEST(supported.empty()); } diff --git a/test/Lstm.hpp b/test/Lstm.hpp index f0d3d853..d3e03d75 100644 --- a/test/Lstm.hpp +++ b/test/Lstm.hpp @@ -54,18 +54,18 @@ bool TolerantCompareEqual(float a, float b, float tolerance = 0.00001f) // Helper function to create an OperandLifeTime::NO_VALUE for testing. // To be used on optional input operands that have no values - these are valid and should be tested. -OperandLifeTime CreateNoValueLifeTime(const hidl_vec& dimensions) +V1_0::OperandLifeTime CreateNoValueLifeTime(const hidl_vec& dimensions) { // Only create a NO_VALUE for optional operands that have no elements if (dimensions.size() == 0 || dimensions[0] == 0) { - return OperandLifeTime::NO_VALUE; + return V1_0::OperandLifeTime::NO_VALUE; } - return OperandLifeTime::CONSTANT_COPY; + return V1_0::OperandLifeTime::CONSTANT_COPY; } template -void ExecuteModel(const HalModel& model, armnn_driver::ArmnnDriver& driver, const Request& request) +void ExecuteModel(const HalModel& model, armnn_driver::ArmnnDriver& driver, const V1_0::Request& request) { android::sp preparedModel = PrepareModel(model, driver); if (preparedModel.get() != nullptr) @@ -79,7 +79,7 @@ void ExecuteModel(const HalModel& model, armnn_driver::ArmnnDriver& driver, cons template<> void ExecuteModel(const armnn_driver::hal_1_2::HalPolicy::Model& model, armnn_driver::ArmnnDriver& driver, - const Request& request) + const V1_0::Request& request) { android::sp preparedModel = PrepareModel_1_2(model, driver); if (preparedModel.get() != nullptr) @@ -362,7 +362,7 @@ void LstmTestImpl(const hidl_vec& inputDimensions, outputArguments[2] = CreateRequestArgument(cellStateOutValue, 5); outputArguments[3] = CreateRequestArgument(outputValue, 6); - Request request = {}; + V1_0::Request request = {}; request.inputs = inputArguments; request.outputs = outputArguments; @@ -640,7 +640,7 @@ void QuantizedLstmTestImpl(const hidl_vec& inputDimensions, outputArguments[0] = CreateRequestArgument(cellStateOutValue, 3); outputArguments[1] = CreateRequestArgument(outputValue, 4); - Request request = {}; + V1_0::Request request = {}; request.inputs = inputArguments; request.outputs = outputArguments; diff --git a/test/Tests.cpp b/test/Tests.cpp index 5c388cb0..3b629a7a 100644 --- a/test/Tests.cpp +++ b/test/Tests.cpp @@ -30,10 +30,10 @@ BOOST_AUTO_TEST_CASE(TestCapabilities) // Making the driver object on the stack causes a weird libc error, so make it on the heap instead auto driver = std::make_unique(DriverOptions(armnn::Compute::CpuRef)); - ErrorStatus error; + V1_0::ErrorStatus error; V1_0::Capabilities cap; - auto cb = [&](ErrorStatus status, const V1_0::Capabilities& capabilities) + auto cb = [&](V1_0::ErrorStatus status, const V1_0::Capabilities& capabilities) { error = status; cap = capabilities; @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(TestCapabilities) driver->getCapabilities(cb); - BOOST_TEST((int)error == (int)ErrorStatus::NONE); + BOOST_TEST((int)error == (int)V1_0::ErrorStatus::NONE); BOOST_TEST(cap.float32Performance.execTime > 0.f); BOOST_TEST(cap.float32Performance.powerUsage > 0.f); BOOST_TEST(cap.quantized8Performance.execTime > 0.f); -- cgit v1.2.1