#include "wrapper/compilation.h"
#include "wrapper/execution.h"
#include "wrapper/event.h"
+#include "wrapper/NNAPIConvert.h"
#include "util/logging.h"
//
VERBOSE(NNAPI::Execution) << "setInput: Shape mismatch" << std::endl;
return ANEURALNETWORKS_BAD_DATA;
}
+
+ if (NNAPIConvert::calculateSizeFromType(type) != length)
+ {
+ VERBOSE(NNAPI::Execution) << "setInput: Invalid length" << std::endl;
+ return ANEURALNETWORKS_BAD_DATA;
+ }
}
else
{
VERBOSE(NNAPI::Execution) << "setInput: Unspecified dimension value" << std::endl;
return ANEURALNETWORKS_BAD_DATA;
}
+
+ if (execution->getOperandSize(operand_index) != length)
+ {
+ VERBOSE(NNAPI::Execution) << "setInput: Invalid length" << std::endl;
+ return ANEURALNETWORKS_BAD_DATA;
+ }
}
if (!execution->setInput(index, type, buffer, length))
VERBOSE(NNAPI::Execution) << "setOutput: Shape mismatch" << std::endl;
return ANEURALNETWORKS_BAD_DATA;
}
+
+ if (NNAPIConvert::calculateSizeFromType(type) != length)
+ {
+ VERBOSE(NNAPI::Execution) << "setOutput: Invalid length" << std::endl;
+ return ANEURALNETWORKS_BAD_DATA;
+ }
}
else
{
VERBOSE(NNAPI::Execution) << "setOutput: Unspecified dimension value" << std::endl;
return ANEURALNETWORKS_BAD_DATA;
}
+
+ if (execution->getOperandSize(operand_index) != length)
+ {
+ VERBOSE(NNAPI::Execution) << "setInput: Invalid length" << std::endl;
+ return ANEURALNETWORKS_BAD_DATA;
+ }
}
if (!execution->setOutput(index, type, buffer, length))
#include "NNAPIConvert.h"
+#include <numeric>
+
using namespace ::neurun::model;
operand::DataType NNAPIConvert::getDataType(OperandCode type)
return shape;
}
+
+size_t NNAPIConvert::calculateSizeFromType(const ANeuralNetworksOperandType *type)
+{
+ auto shape = getShape(type);
+ auto data_type = getDataType((OperandCode)(type->type));
+
+ const auto &dims = shape.dims();
+ return std::accumulate(dims.begin(), dims.end(), operand::sizeOfDataType(data_type),
+ std::multiplies<size_t>());
+}
* @return neurun's internal operand shape
*/
static ::neurun::model::operand::Shape getShape(const ANeuralNetworksOperandType *type);
+
+ /**
+ * @brief Calcaulate operand size from NNAPI type
+ * @param[in] type NNAPI's operand type
+ * @return Operand size
+ */
+ static size_t calculateSizeFromType(const ANeuralNetworksOperandType *type);
};
#endif // __NEURUN_NNAPI_CONVERT_H__
return ((operand_shape.element_nums() == 0) ? true : false);
}
+size_t ANeuralNetworksExecution::getOperandSize(const neurun::model::operand::Index index) noexcept
+{
+ return _executor->model().operands.at(index).operandSize();
+}
+
bool ANeuralNetworksExecution::setInput(uint32_t index, const ANeuralNetworksOperandType *type,
const void *buffer, size_t length) noexcept
{