diff --git a/onert-micro/onert-micro/include/OMConfig.h b/onert-micro/onert-micro/include/OMConfig.h new file mode 100644 index 00000000000..10b2dbb8f07 --- /dev/null +++ b/onert-micro/onert-micro/include/OMConfig.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONERT_MICRO_CONFIG_H +#define ONERT_MICRO_CONFIG_H + +namespace onert_micro +{ + +struct OMConfig +{ + bool keep_input = false; + bool cmsis_nn = false; +}; + +} // namespace onert_micro + +#endif // ONERT_MICRO_CONFIG_H diff --git a/onert-micro/onert-micro/include/OMInterpreter.h b/onert-micro/onert-micro/include/OMInterpreter.h new file mode 100644 index 00000000000..d450c3403e4 --- /dev/null +++ b/onert-micro/onert-micro/include/OMInterpreter.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONERT_MICRO_INTERPRETER_H +#define ONERT_MICRO_INTERPRETER_H + +#include "OMStatus.h" +#include "OMConfig.h" + +#include "core/OMRuntimeModule.h" + +namespace onert_micro +{ + +class OMInterpreter +{ +private: + core::OMRuntimeModule _runtime_module; + +public: + OMInterpreter() = default; + OMInterpreter(const OMInterpreter &) = delete; + OMInterpreter(OMInterpreter &&) = delete; + OMInterpreter &operator=(const OMInterpreter &) = delete; + OMInterpreter &&operator=(const OMInterpreter &&) = delete; + ~OMInterpreter() = default; + + OMStatus importModel(const char *model_ptr, const OMConfig &config); + + OMStatus run(); + + OMStatus reset(); + + uint32_t getNumberOfInputs(); + uint32_t getNumberOfOutputs(); + + OMStatus allocateInputs(); + + uint32_t getInputSizeAt(uint32_t position); + uint32_t getOutputSizeAt(uint32_t position); + + void *getInputDataAt(uint32_t position); + void *getOutputDataAt(uint32_t position); +}; + +} // namespace onert_micro + +#endif // ONERT_MICRO_INTERPRETER_H diff --git a/onert-micro/onert-micro/include/OMStatus.h b/onert-micro/onert-micro/include/OMStatus.h new file mode 100644 index 00000000000..b7a41116d27 --- /dev/null +++ b/onert-micro/onert-micro/include/OMStatus.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONERT_MICRO_STATUS_H +#define ONERT_MICRO_STATUS_H + +namespace onert_micro +{ + +enum OMStatus +{ + Ok, + UnsupportedType, + UnsupportedActivation, + UnsupportedOp, + UnknownError, + ModelNotImport, + FailedCheckCondition, + NoQuantization, + UnsupportedDynamicShapeCase, +}; + +} // namespace onert_micro + +#endif // ONERT_MICRO_STATUS_H diff --git a/onert-micro/onert-micro/src/OMInterpreter.cpp b/onert-micro/onert-micro/src/OMInterpreter.cpp new file mode 100644 index 00000000000..1e7ee420d4a --- /dev/null +++ b/onert-micro/onert-micro/src/OMInterpreter.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "OMInterpreter.h" + +using namespace onert_micro; + +OMStatus OMInterpreter::importModel(const char *model_ptr, const OMConfig &config) +{ + assert(model_ptr != nullptr && "Model ptr shouldn't be nullptr"); + if (model_ptr == nullptr) + return UnknownError; + + return _runtime_module.importModel(model_ptr, config); +} + +OMStatus OMInterpreter::run() { return _runtime_module.run(); } + +OMStatus OMInterpreter::reset() { return _runtime_module.reset(); } + +uint32_t OMInterpreter::getNumberOfInputs() { return _runtime_module.getNumberOfInputs(); } + +uint32_t OMInterpreter::getNumberOfOutputs() { return _runtime_module.getNumberOfOutputs(); } + +void *OMInterpreter::getInputDataAt(uint32_t position) +{ + return _runtime_module.getInputDataAt(position); +} + +void *OMInterpreter::getOutputDataAt(uint32_t position) +{ + return _runtime_module.getOutputDataAt(position); +} + +uint32_t OMInterpreter::getInputSizeAt(uint32_t position) +{ + return _runtime_module.getInputSizeAt(position); +} + +uint32_t OMInterpreter::getOutputSizeAt(uint32_t position) +{ + return _runtime_module.getOutputSizeAt(position); +} + +OMStatus OMInterpreter::allocateInputs() { return _runtime_module.allocateInputs(); }