SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
workspace.h
1 #ifndef _CORE_WORKSPACE_H_
2 #define _CORE_WORKSPACE_H_
3 
4 #include <map>
5 #include <string>
6 
7 #include "smaug/core/tensor.h"
8 #include "smaug/core/operator.h"
9 
10 namespace smaug {
11 
17 class Workspace {
18  public:
19  Workspace() {}
20  ~Workspace() {
21  for (auto& tensor : tensors)
22  delete tensor.second;
23  }
24 
25  Tensor* addTensor(Tensor* tensor) {
26  tensors[tensor->getName()] = static_cast<TensorBase*>(tensor);
27  return tensor;
28  }
29 
30  void addTiledTensor(TiledTensor& tiledTensor) {
31  for (auto i = tiledTensor.startIndex(); !i.end(); ++i) {
32  Tensor* tensor = tiledTensor[i];
33  tensors[tensor->getName()] = static_cast<TensorBase*>(tensor);
34  }
35  }
36 
37  Tensor* getTensor(const std::string& name) const {
38  if (tensors.find(name) == tensors.end())
39  return nullptr;
40  return dynamic_cast<Tensor*>(tensors.at(name));
41  }
42 
43  Tensor* getTensor(Operator* op) const {
44  return getTensor(op->getName());
45  }
46 
47  protected:
48  std::map<std::string, TensorBase*> tensors;
49 };
50 
51 }
52 
53 #endif
smaug::Tensor
Tensor represents a single multi-dimensional array of data.
Definition: tensor.h:344
smaug::Workspace
Workspace is the container and owner of all Tensors and Operators in the Network.
Definition: workspace.h:17
smaug::TiledTensor
A multidimensional container of Tensors.
Definition: tensor.h:552
smaug::TensorBase
The base class of all Tensor objects.
Definition: tensor.h:269
smaug::Operator
Operator is the base class for all graph operators supported by SMAUG.
Definition: operator.h:28
smaug
The smaug namespace is the parent namespace of all C++ code in SMAUG.
Definition: backend.cpp:38