Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[onert/backend] Add LayerScopeTensors into TensorRegistry #14024

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 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,37 @@ 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