From 49b9e100bfbb3b8da01472a0ff48b2bd92944e01 Mon Sep 17 00:00:00 2001 From: surmeh01 Date: Thu, 17 May 2018 14:11:25 +0100 Subject: Release 18.05 --- test/DriverTestHelpers.hpp | 135 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 test/DriverTestHelpers.hpp (limited to 'test/DriverTestHelpers.hpp') diff --git a/test/DriverTestHelpers.hpp b/test/DriverTestHelpers.hpp new file mode 100644 index 00000000..e90f7ecf --- /dev/null +++ b/test/DriverTestHelpers.hpp @@ -0,0 +1,135 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#pragma once + +#ifndef LOG_TAG +#define LOG_TAG "ArmnnDriverTests" +#endif // LOG_TAG + +#include "../ArmnnDriver.hpp" +#include + +namespace android +{ +namespace hardware +{ +namespace neuralnetworks +{ +namespace V1_0 +{ + +std::ostream& operator<<(std::ostream& os, ErrorStatus stat); + +} // namespace android::hardware::neuralnetworks::V1_0 +} // namespace android::hardware::neuralnetworks +} // namespace android::hardware +} // namespace android + +namespace driverTestHelpers +{ + +std::ostream& operator<<(std::ostream& os, android::hardware::neuralnetworks::V1_0::ErrorStatus stat); + +struct ExecutionCallback : public IExecutionCallback +{ + ExecutionCallback() : mNotified(false) {} + Return notify(ErrorStatus status) override; + /// wait until the callback has notified us that it is done + Return wait(); + +private: + // use a mutex and a condition variable to wait for asynchronous callbacks + std::mutex mMutex; + std::condition_variable mCondition; + // and a flag, in case we are notified before the wait call + bool mNotified; +}; + +class PreparedModelCallback : public IPreparedModelCallback +{ +public: + PreparedModelCallback() + : m_ErrorStatus(ErrorStatus::NONE) + , m_PreparedModel() + { } + ~PreparedModelCallback() override { } + + Return notify(ErrorStatus status, + const android::sp& preparedModel) override; + ErrorStatus GetErrorStatus() { return m_ErrorStatus; } + android::sp GetPreparedModel() { return m_PreparedModel; } + +private: + ErrorStatus m_ErrorStatus; + android::sp m_PreparedModel; +}; + +hidl_memory allocateSharedMemory(int64_t size); + +android::sp AddPoolAndGetData(uint32_t size, Request& request); + +void AddPoolAndSetData(uint32_t size, Request& request, const float* data); + +void AddOperand(Model& model, const Operand& op); + +void AddIntOperand(Model& model, int32_t value); + +template +OperandType TypeToOperandType(); + +template<> +OperandType TypeToOperandType(); + +template<> +OperandType TypeToOperandType(); + +template +void AddTensorOperand(Model& model, hidl_vec dimensions, T* values) +{ + uint32_t totalElements = 1; + for (uint32_t dim : dimensions) + { + totalElements *= dim; + } + + DataLocation location = {}; + location.offset = model.operandValues.size(); + location.length = totalElements * sizeof(T); + + Operand op = {}; + op.type = TypeToOperandType(); + op.dimensions = dimensions; + op.lifetime = OperandLifeTime::CONSTANT_COPY; + op.location = location; + + model.operandValues.resize(model.operandValues.size() + location.length); + for (uint32_t i = 0; i < totalElements; i++) + { + *(reinterpret_cast(&model.operandValues[location.offset]) + i) = values[i]; + } + + AddOperand(model, op); +} + +void AddInputOperand(Model& model, hidl_vec dimensions); + +void AddOutputOperand(Model& model, hidl_vec dimensions); + +android::sp PrepareModel(const Model& model, + armnn_driver::ArmnnDriver& driver); + +android::sp PrepareModelWithStatus(const Model& model, + armnn_driver::ArmnnDriver& driver, + ErrorStatus & prepareStatus, + ErrorStatus expectedStatus=ErrorStatus::NONE); + +ErrorStatus Execute(android::sp preparedModel, + const Request& request, + ErrorStatus expectedStatus=ErrorStatus::NONE); + +android::sp ExecuteNoWait(android::sp preparedModel, + const Request& request); + +} // namespace driverTestHelpers -- cgit v1.2.1