SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
|
1 #ifndef _CORE_OPERATOR_H_
2 #define _CORE_OPERATOR_H_
7 #include <boost/format.hpp>
9 #include "smaug/core/typedefs.h"
10 #include "smaug/core/tensor.h"
12 #include "smaug/core/types.pb.h"
15 #define REGISTER_SPECIAL_OP(Operator, Backend) \
17 void Operator<Backend>::run();
23 constexpr
const char* kLayerFormat =
"%-40s %-25s %=15d\n";
31 : name(_name), opType(_opType), workspace(_workspace),
35 virtual void tile() {};
42 virtual void run() = 0;
48 return opType != OpType::UnknownOp;
90 virtual bool isSamplingSupported()
const {
return false; }
91 virtual void setSamplingInfo(
const SamplingInfo& sampling) {}
93 void printSummary(std::ostream& out)
const;
94 void setInput(TensorBase* op,
int index) {
inputs[index] = op; }
95 void setOutput(TensorBase* op,
int index) {
outputs[index] = op; }
104 const std::string& getName()
const {
return name; }
105 Vertex getVertex()
const {
return vertex; }
106 void setVertex(Vertex v) {
vertex = v; }
107 OpType getOpType()
const {
return opType; }
108 Workspace* getWorkspace() {
return workspace; }
110 Tensor* getInput(
int index)
const {
111 return dynamic_cast<Tensor*
>(
inputs.at(index));
113 const std::vector<TensorBase*>& getInputs()
const {
return inputs; }
115 Tensor* getOutput(
int index)
const {
116 return dynamic_cast<Tensor*
>(
outputs.at(index));
118 const std::vector<TensorBase*>& getOutputs()
const {
return outputs; }
120 void setInputsMemType(MemoryType type) {
inputsMemType = type; }
121 void setWeightsMemType(MemoryType type) {
weightsMemType = type; }
122 void setOutputsMemType(MemoryType type) {
outputsMemType = type; }
123 MemoryType getInputsMemType()
const {
return inputsMemType; }
Simulation sampling information maintained by the Operator and passed to the accelerated kernel.
int numPendingInputs
The number of tensors that this operator is waiting on before it can be scheduled.
virtual int getNumParameters() const
This returns the number of parameterizable weights in the operator.
MemoryType outputsMemType
The memory interface over which outputs are expected to be delivered.
MemoryType inputsMemType
The memory interface over which input activations are expected to arrive.
Workspace is the container and owner of all Tensors and Operators in the Network.
virtual void createAllTensors()
For tests: creates all input and output tensors for this operator.
Utility functions for copying/printing/tiling tensors.
virtual std::vector< TensorBase * > getParameterizableInputs()
Return a list of Tensors whose values that are parameterizable.
void setNumPendingInputs(int num)
Set the number of input tensors that this operator is waiting on.
std::vector< TensorBase * > outputs
An ordered list of output tensors produced by this operator.
Vertex vertex
The BGL Vertex corresponding to this Operator.
virtual void run()=0
Executes the Operator.
Operator is the base class for all graph operators supported by SMAUG.
The smaug namespace is the parent namespace of all C++ code in SMAUG.
Utilities for writing and invoking Aladdin kernels from Operators.
virtual bool validate()
Returns true if the parameters/tensors of this operator are all valid.
MemoryType weightsMemType
The memory interface over which weights are expected to arrive.
std::vector< TensorBase * > inputs
An ordered list of input tensors consumed by this operator.
virtual bool isDead()
Returns true if the Operator is dead.