Skip to content

Commit

Permalink
[onert/backend] Add LayerScopeTensors into TensorRegistry
Browse files Browse the repository at this point in the history
This PR adds LayerScopeTensors into TensorRegistry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <[email protected]>

draft : Samsung#13486
for : Samsung#13282
  • Loading branch information
zetwhite committed Sep 20, 2024
1 parent d4d3bf9 commit a07ae97
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions runtime/onert/backend/train/TensorRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
#define __ONERT_BACKEND_TRAIN_TENSOR_REGISTRY__

#include <backend/train/ITensorRegistry.h>
#include <backend/train/LayerScopeTensor.h>

#include "DisposableTensorIndex.h"
#include "LayerScopeTensorIndex.h"
#include "Tensor.h"

namespace onert
Expand Down Expand Up @@ -60,9 +62,36 @@ class TensorRegistry
return _disposable_back_prop;
}

std::shared_ptr<LayerScopeTensor> getLayerScopeTensor(const LayerScopeTensorIndex &index)
{
auto itr = _layer_scope.find(index);
if (itr != _layer_scope.end())
return itr->second;

return nullptr;
}

void setLayerScopeTensor(const LayerScopeTensorIndex &index, std::shared_ptr<LayerScopeTensor> &tensor)
{
assert(tensor != nullptr);
auto itr = _layer_scope.find(index);
if (itr != _layer_scope.end())
throw std::runtime_error{
"Tried to set a layer scope tensor but another layer scope tensor already exists."};

_layer_scope[index] = tensor;
}

const std::unordered_map<LayerScopeTensorIndex, std::shared_ptr<LayerScopeTensor>> &
layerscope_tensors()
{
return _layer_scope;
}

private:
// Disposable Tensors to be accumulated to BackPropTensor
std::unordered_map<DisposableTensorIndex, std::unique_ptr<BackPropTensor>> _disposable_back_prop;
std::unordered_map<LayerScopeTensorIndex, std::shared_ptr<LayerScopeTensor>> _layer_scope;
};

} // namespace train
Expand Down

0 comments on commit a07ae97

Please sign in to comment.