This commit partially implements functions related with ANeuralNetworksExecution
struct.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
#define __COMPILATION_H__
#include "internal/Model.h"
+#include "internal/arm_compute.h"
struct ANeuralNetworksCompilation
{
public:
ANeuralNetworksCompilation(const std::shared_ptr<const internal::tflite::Model> &model)
- : _model{model}
+ : _model{model}, _output{new internal::arm_compute::Model}
{
// DO NOTHING
}
public:
const internal::tflite::Model &model(void) const { return *_model; }
+ internal::arm_compute::Model &output(void) { return *_output; }
+
+public:
+ void publish(std::shared_ptr<const internal::arm_compute::Model> &output)
+ {
+ output = _output;
+ }
private:
std::shared_ptr<const internal::tflite::Model> _model;
+ std::shared_ptr<internal::arm_compute::Model> _output;
};
#endif
#include <nnapi.h>
+#include "compilation.h"
#include "execution.h"
+#include <cassert>
+
ResultCode
ANeuralNetworksExecution_create(ANeuralNetworksCompilation* compilation, ANeuralNetworksExecution** execution)
{
+ std::shared_ptr<const ::internal::arm_compute::Model> model;
+
+ compilation->publish(model);
+
+ *execution = new ANeuralNetworksExecution{model};
+
return ANEURALNETWORKS_NO_ERROR;
}
ResultCode
ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution* execution, ANeuralNetworksEvent** event)
{
+ assert(execution != nullptr);
+
+ const auto &operations = execution->model().operations();
+
+ for (uint32_t n = 0; n < operations.size(); ++n)
+ {
+ operations.at(n).run();
+ }
+
return ANEURALNETWORKS_NO_ERROR;
}
#ifndef __EXECUTION_H__
#define __EXECUTION_H__
+#include "internal/arm_compute.h"
+
struct ANeuralNetworksExecution
{
+public:
+ ANeuralNetworksExecution(const std::shared_ptr<const internal::arm_compute::Model> &model)
+ : _model{model}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const internal::arm_compute::Model &model(void) const { return *_model; }
+
+private:
+ std::shared_ptr<const internal::arm_compute::Model> _model;
};
#endif
--- /dev/null
+#include "internal/arm_compute.h"
+
+#include <cassert>
+
+namespace internal
+{
+namespace arm_compute
+{
+namespace operand
+{
+
+Context &Context::set(const ::internal::tflite::operand::Index &id,
+ const std::shared_ptr<::arm_compute::ICLTensor> &tensor)
+{
+ assert(_objects.find(id.asInt()) == _objects.end());
+
+ _objects[id.asInt()] = Object{tensor};
+}
+
+} // namespace operand
+} // namepsace arm_compute
+} // namespace internal
--- /dev/null
+#ifndef __INTERNAL_ARM_COMPUTE_H__
+#define __INTERNAL_ARM_COMPUTE_H__
+
+#include <arm_compute/core/CL/ICLTensor.h>
+
+namespace internal
+{
+namespace arm_compute
+{
+namespace operand
+{
+
+class Object
+{
+public:
+ Object() = default;
+
+public:
+ Object(const std::shared_ptr<::arm_compute::ICLTensor> &tensor) : _tensor{tensor}
+ {
+ // DO NOTHING
+ }
+
+public:
+ ::arm_compute::ICLTensor *ptr(void) const { return _tensor.get(); }
+
+private:
+ std::shared_ptr<::arm_compute::ICLTensor> _tensor;
+};
+
+} // namespace operand
+} // namepsace arm_compute
+} // namespace internal
+
+#include "internal/Model.h"
+
+#include <map>
+
+namespace internal
+{
+namespace arm_compute
+{
+namespace operand
+{
+
+class Context
+{
+public:
+ Context &set(const ::internal::tflite::operand::Index &id,
+ const std::shared_ptr<::arm_compute::ICLTensor> &tensor);
+
+public:
+ const Object &at(const ::internal::tflite::operand::Index &) const;
+ Object &at(const ::internal::tflite::operand::Index &);
+
+private:
+ std::map<int, Object> _objects;
+};
+
+} // namespace operand
+} // namepsace arm_compute
+} // namespace internal
+
+#include <arm_compute/runtime/IFunction.h>
+
+namespace internal
+{
+namespace arm_compute
+{
+namespace op
+{
+
+class Sequence
+{
+public:
+ uint32_t size(void) const { return _functions.size(); }
+
+public:
+ Sequence &append(std::unique_ptr<::arm_compute::IFunction> &&func)
+ {
+ _functions.emplace_back(std::move(func));
+ return (*this);
+ }
+
+public:
+ ::arm_compute::IFunction &at(uint32_t n) const
+ {
+ return *(_functions.at(n));
+ }
+
+private:
+ std::vector<std::unique_ptr<::arm_compute::IFunction>> _functions;
+};
+
+} // namespace op
+} // namepsace arm_compute
+} // namespace internal
+
+namespace internal
+{
+namespace arm_compute
+{
+
+class Model
+{
+public:
+ operand::Context &operands(void) { return _operands; }
+ const operand::Context &operands(void) const { return _operands; }
+
+public:
+ op::Sequence &operations(void) { return _ops; }
+ const op::Sequence &operations(void) const { return _ops; }
+
+private:
+ operand::Context _operands;
+ op::Sequence _ops;
+};
+
+} // namepsace arm_compute
+} // namespace internal
+
+#endif // __INTERNAL_ARM_COMPUTE_H__