diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/1.1/Mean.cpp | 2 | ||||
-rw-r--r-- | test/1.1/Transpose.cpp | 2 | ||||
-rw-r--r-- | test/Concat.cpp | 2 | ||||
-rw-r--r-- | test/Concurrent.cpp | 4 | ||||
-rw-r--r-- | test/Convolution2D.hpp | 2 | ||||
-rw-r--r-- | test/DriverTestHelpers.cpp | 27 | ||||
-rw-r--r-- | test/DriverTestHelpers.hpp | 55 | ||||
-rw-r--r-- | test/FullyConnected.cpp | 8 | ||||
-rw-r--r-- | test/GenericLayerTests.cpp | 3 | ||||
-rw-r--r-- | test/Lstm.hpp | 8 |
10 files changed, 62 insertions, 51 deletions
diff --git a/test/1.1/Mean.cpp b/test/1.1/Mean.cpp index 6e96d84b..529371e1 100644 --- a/test/1.1/Mean.cpp +++ b/test/1.1/Mean.cpp @@ -86,7 +86,7 @@ void MeanTestImpl(const TestTensor& input, AddPoolAndSetData(input.GetNumElements(), request, input.GetData()); // Add memory for the output - android::sp<IMemory> outMemory = AddPoolAndGetData(expectedOutput.GetNumElements(), request); + android::sp<IMemory> outMemory = AddPoolAndGetData<float>(expectedOutput.GetNumElements(), request); const float* outputData = static_cast<const float*>(static_cast<void*>(outMemory->getPointer())); ErrorStatus execStatus = Execute(preparedModel, request); diff --git a/test/1.1/Transpose.cpp b/test/1.1/Transpose.cpp index f2c77b3f..1b30aa6b 100644 --- a/test/1.1/Transpose.cpp +++ b/test/1.1/Transpose.cpp @@ -86,7 +86,7 @@ void TransposeTestImpl(const TestTensor & inputs, int32_t perm[], inputs.GetData()); // add memory for the output - android::sp<IMemory> outMemory = AddPoolAndGetData(expectedOutputTensor.GetNumElements(), request); + android::sp<IMemory> outMemory = AddPoolAndGetData<float>(expectedOutputTensor.GetNumElements(), request); float* outdata = static_cast<float*>(static_cast<void*>(outMemory->getPointer())); auto execStatus = Execute(preparedModel, request); diff --git a/test/Concat.cpp b/test/Concat.cpp index 02d66cb8..9beb67bd 100644 --- a/test/Concat.cpp +++ b/test/Concat.cpp @@ -124,7 +124,7 @@ ConcatTestImpl(const std::vector<const TestTensor*> & inputs, } // add memory for the output - android::sp<IMemory> outMemory = AddPoolAndGetData(expectedOutputTensor.GetNumElements(), request); + android::sp<IMemory> outMemory = AddPoolAndGetData<float>(expectedOutputTensor.GetNumElements(), request); float* outdata = static_cast<float*>(static_cast<void*>(outMemory->getPointer())); // run the execution diff --git a/test/Concurrent.cpp b/test/Concurrent.cpp index 87ac2e80..9fe6f46e 100644 --- a/test/Concurrent.cpp +++ b/test/Concurrent.cpp @@ -84,9 +84,9 @@ BOOST_AUTO_TEST_CASE(ConcurrentExecute) requests[i].outputs = hidl_vec<RequestArgument>{output}; // set the input data (matching source test) float indata[] = {2, 32, 16}; - AddPoolAndSetData(3, requests[i], indata); + AddPoolAndSetData<float>(3, requests[i], indata); // add memory for the output - outMemory[i] = AddPoolAndGetData(1, requests[i]); + outMemory[i] = AddPoolAndGetData<float>(1, requests[i]); outdata[i] = static_cast<float*>(static_cast<void*>(outMemory[i]->getPointer())); } diff --git a/test/Convolution2D.hpp b/test/Convolution2D.hpp index 46b46549..180f57e2 100644 --- a/test/Convolution2D.hpp +++ b/test/Convolution2D.hpp @@ -102,7 +102,7 @@ void PaddingTestImpl(android::nn::PaddingScheme paddingScheme, bool fp16Enabled AddPoolAndSetData(6, request, indata); // add memory for the output - android::sp<IMemory> outMemory = AddPoolAndGetData(outSize, request); + android::sp<IMemory> outMemory = AddPoolAndGetData<float>(outSize, request); float* outdata = reinterpret_cast<float*>(static_cast<void*>(outMemory->getPointer())); // run the execution diff --git a/test/DriverTestHelpers.cpp b/test/DriverTestHelpers.cpp index 4c26174b..3a3c98ff 100644 --- a/test/DriverTestHelpers.cpp +++ b/test/DriverTestHelpers.cpp @@ -102,33 +102,6 @@ hidl_memory allocateSharedMemory(int64_t size) return memory; } -android::sp<IMemory> AddPoolAndGetData(uint32_t size, Request& request) -{ - hidl_memory pool; - - android::sp<IAllocator> allocator = IAllocator::getService("ashmem"); - allocator->allocate(sizeof(float) * size, [&](bool success, const hidl_memory& mem) { - BOOST_TEST(success); - pool = mem; - }); - - request.pools.resize(request.pools.size() + 1); - request.pools[request.pools.size() - 1] = pool; - - android::sp<IMemory> mapped = mapMemory(pool); - mapped->update(); - return mapped; -} - -void AddPoolAndSetData(uint32_t size, Request& request, const float* data) -{ - android::sp<IMemory> memory = AddPoolAndGetData(size, request); - - float* dst = static_cast<float*>(static_cast<void*>(memory->getPointer())); - - memcpy(dst, data, size * sizeof(float)); -} - android::sp<V1_0::IPreparedModel> PrepareModelWithStatus(const V1_0::Model& model, armnn_driver::ArmnnDriver& driver, ErrorStatus& prepareStatus, diff --git a/test/DriverTestHelpers.hpp b/test/DriverTestHelpers.hpp index c6f3f1fe..9da02603 100644 --- a/test/DriverTestHelpers.hpp +++ b/test/DriverTestHelpers.hpp @@ -99,9 +99,34 @@ private: hidl_memory allocateSharedMemory(int64_t size); -android::sp<IMemory> AddPoolAndGetData(uint32_t size, Request& request); +template<typename T> +android::sp<IMemory> AddPoolAndGetData(uint32_t size, Request& request) +{ + hidl_memory pool; + + android::sp<IAllocator> allocator = IAllocator::getService("ashmem"); + allocator->allocate(sizeof(T) * size, [&](bool success, const hidl_memory& mem) { + BOOST_TEST(success); + pool = mem; + }); + + request.pools.resize(request.pools.size() + 1); + request.pools[request.pools.size() - 1] = pool; + + android::sp<IMemory> mapped = mapMemory(pool); + mapped->update(); + return mapped; +} -void AddPoolAndSetData(uint32_t size, Request& request, const float* data); +template<typename T> +void AddPoolAndSetData(uint32_t size, Request& request, const T* data) +{ + android::sp<IMemory> memory = AddPoolAndGetData<T>(size, request); + + T* dst = static_cast<T*>(static_cast<void*>(memory->getPointer())); + + memcpy(dst, data, size * sizeof(T)); +} template<typename HalPolicy, typename HalModel = typename HalPolicy::Model, @@ -176,7 +201,9 @@ void AddTensorOperand(HalModel& model, const hidl_vec<uint32_t>& dimensions, const T* values, HalOperandType operandType = HalOperandType::TENSOR_FLOAT32, - HalOperandLifeTime operandLifeTime = HalOperandLifeTime::CONSTANT_COPY) + HalOperandLifeTime operandLifeTime = HalOperandLifeTime::CONSTANT_COPY, + double scale = 0.f, + int offset = 0) { using HalOperand = typename HalPolicy::Operand; @@ -197,6 +224,8 @@ void AddTensorOperand(HalModel& model, HalOperand op = {}; op.type = operandType; op.dimensions = dimensions; + op.scale = scale; + op.zeroPoint = offset; op.lifetime = HalOperandLifeTime::CONSTANT_COPY; op.location = location; @@ -218,9 +247,11 @@ void AddTensorOperand(HalModel& model, const hidl_vec<uint32_t>& dimensions, const std::vector<T>& values, HalOperandType operandType = HalPolicy::OperandType::TENSOR_FLOAT32, - HalOperandLifeTime operandLifeTime = HalOperandLifeTime::CONSTANT_COPY) + HalOperandLifeTime operandLifeTime = HalOperandLifeTime::CONSTANT_COPY, + double scale = 0.f, + int offset = 0) { - AddTensorOperand<HalPolicy, T>(model, dimensions, values.data(), operandType, operandLifeTime); + AddTensorOperand<HalPolicy, T>(model, dimensions, values.data(), operandType, operandLifeTime, scale, offset); } template<typename HalPolicy, @@ -228,14 +259,17 @@ template<typename HalPolicy, typename HalOperandType = typename HalPolicy::OperandType> void AddInputOperand(HalModel& model, const hidl_vec<uint32_t>& dimensions, - HalOperandType operandType = HalOperandType::TENSOR_FLOAT32) + HalOperandType operandType = HalOperandType::TENSOR_FLOAT32, + double scale = 0.f, + int offset = 0) { using HalOperand = typename HalPolicy::Operand; using HalOperandLifeTime = typename HalPolicy::OperandLifeTime; HalOperand op = {}; op.type = operandType; - op.scale = operandType == HalOperandType::TENSOR_QUANT8_ASYMM ? 1.f / 255.f : 0.f; + op.scale = scale; + op.zeroPoint = offset; op.dimensions = dimensions; op.lifetime = HalOperandLifeTime::MODEL_INPUT; @@ -250,14 +284,17 @@ template<typename HalPolicy, typename HalOperandType = typename HalPolicy::OperandType> void AddOutputOperand(HalModel& model, const hidl_vec<uint32_t>& dimensions, - HalOperandType operandType = HalOperandType::TENSOR_FLOAT32) + HalOperandType operandType = HalOperandType::TENSOR_FLOAT32, + double scale = 0.f, + int offset = 0) { using HalOperand = typename HalPolicy::Operand; using HalOperandLifeTime = typename HalPolicy::OperandLifeTime; HalOperand op = {}; op.type = operandType; - op.scale = operandType == HalOperandType::TENSOR_QUANT8_ASYMM ? 1.f / 255.f : 0.f; + op.scale = scale; + op.zeroPoint = offset; op.dimensions = dimensions; op.lifetime = HalOperandLifeTime::MODEL_OUTPUT; diff --git a/test/FullyConnected.cpp b/test/FullyConnected.cpp index de885153..ec4fcbda 100644 --- a/test/FullyConnected.cpp +++ b/test/FullyConnected.cpp @@ -70,10 +70,10 @@ BOOST_AUTO_TEST_CASE(FullyConnected) // set the input data (matching source test) float indata[] = {2, 32, 16}; - AddPoolAndSetData(3, request, indata); + AddPoolAndSetData<float>(3, request, indata); // add memory for the output - android::sp<IMemory> outMemory = AddPoolAndGetData(1, request); + android::sp<IMemory> outMemory = AddPoolAndGetData<float>(1, request); float* outdata = static_cast<float*>(static_cast<void*>(outMemory->getPointer())); // run the execution @@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(TestFullyConnected4dInput) AddPoolAndSetData(8, request, indata); // add memory for the output - android::sp<IMemory> outMemory = AddPoolAndGetData(8, request); + android::sp<IMemory> outMemory = AddPoolAndGetData<float>(8, request); float* outdata = static_cast<float*>(static_cast<void*>(outMemory->getPointer())); // run the execution @@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(TestFullyConnected4dInputReshape) AddPoolAndSetData(8, request, indata); // add memory for the output - android::sp<IMemory> outMemory = AddPoolAndGetData(8, request); + android::sp<IMemory> outMemory = AddPoolAndGetData<float>(8, request); float* outdata = static_cast<float*>(static_cast<void*>(outMemory->getPointer())); // run the execution diff --git a/test/GenericLayerTests.cpp b/test/GenericLayerTests.cpp index 6b51fb93..3b11b726 100644 --- a/test/GenericLayerTests.cpp +++ b/test/GenericLayerTests.cpp @@ -188,7 +188,8 @@ BOOST_AUTO_TEST_CASE(UnsupportedLayerContinueOnFailure) AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4}); AddOutputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 1, 3, 4}, - HalPolicy::OperandType::TENSOR_QUANT8_ASYMM); + HalPolicy::OperandType::TENSOR_QUANT8_ASYMM, + 1.f / 225.f); // Fully connected is supported AddInputOperand<HalPolicy>(model, hidl_vec<uint32_t>{1, 3}); diff --git a/test/Lstm.hpp b/test/Lstm.hpp index 3d9bf77f..6032f1c2 100644 --- a/test/Lstm.hpp +++ b/test/Lstm.hpp @@ -372,12 +372,12 @@ void LstmTestImpl(const hidl_vec<uint32_t>& inputDimensions, AddPoolAndSetData(cellStateInValue.size(), request, cellStateInValue.data()); // add memory for the outputs - AddPoolAndGetData(scratchBufferValue.size(), request); - android::sp<IMemory> outputStateOutMemory = AddPoolAndGetData(outputStateOutValue.size(), request); + AddPoolAndGetData<float>(scratchBufferValue.size(), request); + android::sp<IMemory> outputStateOutMemory = AddPoolAndGetData<float>(outputStateOutValue.size(), request); float* outputStateOutData = static_cast<float*>(static_cast<void*>(outputStateOutMemory->getPointer())); - android::sp<IMemory> cellStateOutMemory = AddPoolAndGetData(cellStateOutValue.size(), request); + android::sp<IMemory> cellStateOutMemory = AddPoolAndGetData<float>(cellStateOutValue.size(), request); float* cellStateOutData = static_cast<float*>(static_cast<void*>(cellStateOutMemory->getPointer())); - android::sp<IMemory> outputMemory = AddPoolAndGetData(outputValue.size(), request); + android::sp<IMemory> outputMemory = AddPoolAndGetData<float>(outputValue.size(), request); float* outputData = static_cast<float*>(static_cast<void*>(outputMemory->getPointer())); // make the prepared model and run the execution |