SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
|
Go to the documentation of this file.
9 #include "smaug/core/network.h"
10 #include "smaug/core/backend.h"
11 #include "smaug/core/tensor.h"
12 #include "smaug/core/workspace.h"
48 SmvBackend::initGlobals();
58 SmvBackend::freeGlobals();
69 for (
auto t : op->getInputs()) {
70 auto tensor =
dynamic_cast<Tensor*
>(t);
71 tensor->template allocateStorage<T>();
73 for (
auto t : op->getOutputs()) {
74 auto tensor =
dynamic_cast<Tensor*
>(t);
75 tensor->template allocateStorage<T>();
92 allocateAllTensors<T>(op);
93 for (
auto input : op->getInputs()) {
95 fillTensorDataFunc(tensor);
106 template <
typename DType>
108 const std::vector<DType>& expected) {
109 auto ptr = output->template data<DType>();
111 for (
auto idx = output->
startIndex(); !idx.end(); ++idx, ++i) {
115 REQUIRE(i == expected.size());
125 template <
typename DType>
127 auto outputPtr = output->template data<DType>();
128 auto expectedPtr = expected->template data<DType>();
131 for (; !outputIdx.end(); ++outputIdx, ++expectedIdx) {
132 REQUIRE(Approx(outputPtr[outputIdx])
134 .epsilon(
kEpsilon) == expectedPtr[expectedIdx]);
138 Network* buildNetwork(
const std::string& modelTopo,
139 const std::string& modelParams);
140 Tensor* buildAndRunNetwork(
const std::string& modelTopo,
141 const std::string& modelParams);
143 Network* network()
const {
return network_; }
144 Workspace* workspace()
const {
return workspace_; }
152 const char* baseDir = std::getenv(
"SMAUG_HOME");
154 assert(
false &&
"SMAUG_HOME is not set.");
155 std::string fullPath = std::string(baseDir) +
'/' + relPath;
156 if (!std::ifstream(fullPath)) {
157 std::cerr <<
"File " << fullPath
158 <<
" doesn't exist! This could be because the proto is "
159 "too large to be submit to GitHub, please check and "
160 "create it locally.\n";
Tensor represents a single multi-dimensional array of data.
The Catch2 test fixture used by all C++ unit tests.
int numAcceleratorsAvailable
The actual number of accelerator complexes currently in use.
TensorIndexIterator startIndex() const
Returns an iterator starting at the beginning of the Tensor.
Network encapsulates all of the information SMAUG will use during execution: the overall computation ...
Tensor * convertFp16ToFp32Tensor(Tensor *fp16Tensor, Workspace *workspace)
This creates a tensor with float32 data type and fills it with data converted from a source tensor wi...
std::string resolvePath(const std::string &relPath)
Resolves a SMAUG_HOME relative path to a particular resource (like a protobuf).
bool useSystolicArrayWhenAvailable
If true, uses the systolic array for applicable operators when backend support exists.
float fp32(float16 fp16_data)
This converts a float16 into a float32.
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.
void verifyOutputs(Tensor *output, Tensor *expected)
Compares the contents of the two given Tensors against each other and asserts (REQUIRE) that the two ...
void verifyOutputs(Tensor *output, const std::vector< DType > &expected)
Compares the contents of the given Tensor against an std::vector of data elements and asserts (REQUIR...
bool runningInSimulation
This is true if the user chooses to run the network in gem5 simulation.
void createAndFillTensorsWithData(Operator *op, FillTensorDataFunc fillTensorDataFunc)
Fills every input Tensor in the Operator with data by calling the provided FillTensorDataFunc.
void allocateAllTensors(Operator *op)
Allocates data storage for all Tensors in the Operator.
Operator is the base class for all graph operators supported by SMAUG.
constexpr float kMargin
Sets the absolute value by which a result can differ from Approx's expected value.
The smaug namespace is the parent namespace of all C++ code in SMAUG.
constexpr float kEpsilon
Set the percentage by which a result can differ from Approx's expected value.
void(* FillTensorDataFunc)(Tensor *tensor)
Any function that accepts a Tensor, fills it with data, and returns nothing.
float16 fp16(float fp32_data)
This converts a float32 into a float16.
Tensor * convertFp32ToFp16Tensor(Tensor *fp32Tensor, Workspace *workspace)
This creates a tensor with float16 data type and fills it with data converted from a source tensor wi...