Skip to content
Open
Show file tree
Hide file tree
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
57 changes: 29 additions & 28 deletions cost-model/include/dataflow-specification-language/DFSL_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ namespace maestro {
std::string file_name_;
std::ifstream in_file_;

void ParseError(int line_num) {
void ParseError(int line_num, std::string err = "Not reported") {
std::cout << "[MAESTRO Parser] Parse error at line number " + std::to_string(line_num) + " in target file " + file_name_ << std::endl;
std::cout << "Error was: " + err << std::endl;
exit(-1);
}
}; // End of class InputParser
Expand All @@ -90,7 +91,7 @@ namespace maestro {

void ParseDFSL(std::shared_ptr<DFA::NeuralNetwork> network) {
std::string line;
boost::char_separator<char> sep(" ,->():\t;");
boost::char_separator<char> sep(" ,->():\t\n\r;");
int line_number = 1;

// network = std::make_shared<DFA::NeuralNetwork>();
Expand Down Expand Up @@ -167,7 +168,7 @@ namespace maestro {
network->SetName(tkn);
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state Network_Identifier");
}

break;
Expand All @@ -181,7 +182,7 @@ namespace maestro {
state_ = ParserState::Layer_Identifier;
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state Network_Body: " + tkn);
}
break;
}
Expand All @@ -202,7 +203,7 @@ namespace maestro {
case ParserState::Layer_Body: {
if(tkn == DFSL::brace_close_) {
if(curr_layer == nullptr) {
ParseError(line_number);
ParseError(line_number, "curr_layer is nullptr");
}
curr_layer->SetDimensions(dim_vector);

Expand Down Expand Up @@ -249,7 +250,7 @@ namespace maestro {
state_ = ParserState::Dataflow_Decl;
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state Layer_Body");
}

break;
Expand Down Expand Up @@ -355,7 +356,7 @@ namespace maestro {
//TODO
}
else {
ParseError(line_number);
ParseError(line_number, "Unsupported layer type");
}
state_ = ParserState::Layer_Body;

Expand All @@ -367,7 +368,7 @@ namespace maestro {
state_ = ParserState::Dimension_Body;
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state Dimension_Dec1");
}
break;
}
Expand All @@ -381,7 +382,7 @@ namespace maestro {
tmp_name = tkn;
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state Dimension_Body");
}
state_ = ParserState::Dimension_Size;
}
Expand All @@ -400,7 +401,7 @@ namespace maestro {


if(size == 0) {
ParseError(line_number);
ParseError(line_number, "Dimension size was 0");
}
else {

Expand All @@ -420,7 +421,7 @@ namespace maestro {
state_ = ParserState::Dataflow_Body;
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state Dataflow_Dec1");
}
break;
}
Expand All @@ -442,7 +443,7 @@ namespace maestro {
state_ = ParserState::Dataflow_ClusterSize;
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state Dataflow_Body");
}
break;
}
Expand Down Expand Up @@ -478,7 +479,7 @@ namespace maestro {
}

if(map_size <= 0) {
ParseError(line_number);
ParseError(line_number, "map_size was <= 0");
}

get_dim_size = false;
Expand Down Expand Up @@ -516,7 +517,7 @@ namespace maestro {
}

if(map_offset <= 0) {
ParseError(line_number);
ParseError(line_number, "map_offset was <= 0");
}

get_dim_size = false;
Expand All @@ -526,7 +527,7 @@ namespace maestro {

case ParserState::Dataflow_MapVar: {
if(tkn.empty()) {
ParseError(line_number);
ParseError(line_number, "Token was empty in Dataflow_MapVar state");
}

switch(curr_directive_class) {
Expand All @@ -539,7 +540,7 @@ namespace maestro {
break;
}
default: {
ParseError(line_number);
ParseError(line_number, "Bad curr_directive_class");
}
}

Expand Down Expand Up @@ -579,7 +580,7 @@ namespace maestro {
}

if(cluster_size <= 0) {
ParseError(line_number);
ParseError(line_number, "cluster_size was <= 0");
}

get_dim_size = false;
Expand Down Expand Up @@ -607,7 +608,7 @@ namespace maestro {
state_ = ParserState::Acclerator_Body;
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state Accelerator_Identifier");
}
break;
}
Expand All @@ -623,7 +624,7 @@ namespace maestro {
state_ = ParserState::NoC_Identifier;
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state Accelerator_Body");
}
break;
}
Expand All @@ -634,7 +635,7 @@ namespace maestro {
}
else {
//TODO: Add an error message
ParseError(line_number);
ParseError(line_number, "Bad token in state PE_Identifier");
}
break;
}
Expand All @@ -645,7 +646,7 @@ namespace maestro {
}
else {
//TODO: Add an error message
ParseError(line_number);
ParseError(line_number, "Bad token in state Buffer_Identifier");
}
break;
}
Expand Down Expand Up @@ -676,7 +677,7 @@ namespace maestro {
break;
}
else {
ParseError(line_number);
ParseError(line_number, "Bad token in state PE_Body");
}

break;
Expand Down Expand Up @@ -826,7 +827,7 @@ namespace maestro {
}
else {
//TODO: Add an error message
ParseError(line_number);
ParseError(line_number, "Bad token in state NoC_Identifier");
}
break;
}
Expand All @@ -848,7 +849,7 @@ namespace maestro {
}
else {
//TODO: Add an error message
ParseError(line_number);
ParseError(line_number, "Bad token in state Noc_Name_Identifier");
}
break;
}
Expand All @@ -865,15 +866,15 @@ namespace maestro {
}
else {
//TODO: Add an error message
ParseError(line_number);
ParseError(line_number, "Bad token in state SubNoC_Body");
}
break;
}

case ParserState::NoC_BW: {
int noc_bw = std::atoi(tkn.c_str());
if(noc_bw < 1) {
ParseError(line_number);
ParseError(line_number, "noc_bw was < 1");
}
else {
noc_bandwidth_.push_back(noc_bw);
Expand All @@ -885,7 +886,7 @@ namespace maestro {
case ParserState::NoC_Latency: {
int noc_latency = std::atoi(tkn.c_str());
if(noc_latency < 1) {
ParseError(line_number);
ParseError(line_number, "noc_latency was < 1");
}
else {
noc_latency_.push_back(noc_latency);
Expand All @@ -895,7 +896,7 @@ namespace maestro {
}

default: {
ParseError(line_number);
ParseError(line_number, "Bad parser state");
break;
}
} // End of switch(state_)
Expand Down
11 changes: 9 additions & 2 deletions tools/frontend/frameworks_to_modelfile_maestro.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,16 @@
import torch
import torchvision.models as models
from helpers.torch_maestro_summary import summary

import sys, os
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
model = getattr(models, opt.model)()
model = None
if opt.model == 'custom':
sys.path.insert(0,os.path.dirname(opt.custom))
fn = os.path.basename(opt.custom).split('.')[0]
new_module = __import__(fn, fromlist=[fn])
model = getattr(new_module, fn)()
else:
model = getattr(models, opt.model)()
model = model.to(device)
mae_summary = summary(model, INPUT_SIZE)
with open("../../data/model/"+opt.outfile, "w") as fo:
Expand Down
6 changes: 3 additions & 3 deletions tools/frontend/modelfile_to_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
dsconv = 0
base_path = '../../data/'
if os.path.exists(base_path + 'model/' + opt.model_file):
with open('./dataflow/' + opt.dataflow + ".m" ,"r") as fd:
with open('./dataflow/'+ 'dpt.m' , "r") as fdpt:
with open('./dataflow/' + opt.dataflow + ".m" ,"r", encoding="utf8") as fd:
with open('./dataflow/'+ 'dpt.m' , "r", encoding="utf8") as fdpt:
with open(base_path + 'mapping/' + opt.outfile, "w") as fo:
with open(base_path + 'model/' + opt.model_file, "r") as fm:
with open(base_path + 'model/' + opt.model_file, "r", encoding="utf8") as fm:
for line in fm:
if(re.search("DSCONV",line)):
dsconv = 1
Expand Down