diff --git a/onert-micro/onert-micro/include/core/OMRuntimeContext.h b/onert-micro/onert-micro/include/core/OMRuntimeContext.h index 0c75e9dd631..1a54c37184f 100644 --- a/onert-micro/onert-micro/include/core/OMRuntimeContext.h +++ b/onert-micro/onert-micro/include/core/OMRuntimeContext.h @@ -20,6 +20,7 @@ #include "OMStatus.h" #include "reader/OMCircleReader.h" +#include "reader/OMWeightOnlyFormatReader.h" #include @@ -32,6 +33,7 @@ class OMRuntimeContext { private: reader::OMCircleReader _reader; + reader::OMWeightOnlyFormatReader _wof_reader; public: OMRuntimeContext() = default; @@ -53,6 +55,17 @@ class OMRuntimeContext return Ok; } + OMStatus setWofFile(char *wof_ptr) + { + OMStatus status; + _wof_reader.parse(wof_ptr); + + status = _wof_reader.validate(&_reader); + if (status != Ok) + return status; + return Ok; + } + const bool isConstTensor(uint32_t tensor_index) { return _reader.isConstTensor(tensor_index); } const reader::CircleValues *getCircleOutputs() { return _reader.outputs(); } diff --git a/onert-micro/onert-micro/src/core/OMRuntimeContext.cpp b/onert-micro/onert-micro/src/core/OMRuntimeContext.cpp index e6b6500352a..e746d4cbd74 100644 --- a/onert-micro/onert-micro/src/core/OMRuntimeContext.cpp +++ b/onert-micro/onert-micro/src/core/OMRuntimeContext.cpp @@ -57,6 +57,18 @@ OMStatus OMRuntimeContext::getConstDataByTensorIndex(uint8_t **data, uint16_t te if (tensor == nullptr) return UnknownError; + // To handle with separated weights: + // 1) first we try to get weigths from wof file (using wof_reader) + // 2) If it is not null -> return it + // 3) It it is null try to get it from main circle file + uint8_t *buffer_data = reinterpret_cast(_wof_reader.buffer(tensor_index)); + + if (buffer_data != nullptr) + { + *data = buffer_data; + return Ok; + } + auto const *buffer = _reader.buffers()->operator[](tensor->buffer())->data(); if (buffer == nullptr)