crown
1.0.0
|
00001 /* 00002 Copyright 2015 Nicolas Melot 00003 00004 This file is part of Crown. 00005 00006 Crown is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 Crown is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with Crown. If not, see <http://www.gnu.org/licenses/>. 00018 00019 */ 00020 00021 00022 #include <fstream> 00023 #include <set> 00024 00025 #include <cstdlib> 00026 00027 #include <crown/allocation.h> 00028 #include <crown/mapping.h> 00029 #include <crown/scaling.h> 00030 #include <crown/crown.h> 00031 #include <crown/CrownScheduler.hpp> 00032 00033 #include <pelib/XMLSchedule.hpp> 00034 #include <pelib/AmplInput.hpp> 00035 #include <pelib/AmplOutput.hpp> 00036 #include <pelib/Vector.hpp> 00037 #include <pelib/Matrix.hpp> 00038 #include <pelib/Set.hpp> 00039 #include <pelib/GraphML.hpp> 00040 #include <pelib/Schedule.hpp> 00041 00042 #ifdef debug 00043 #undef debug 00044 #endif 00045 #if 0 00046 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << var << "\"" << endl; 00047 #else 00048 #define debug(var) 00049 #endif 00050 00051 using namespace std; 00052 using namespace pelib; 00053 using namespace pelib::crown; 00054 00055 // Quality assessment parameters 00056 const long long int nsec_in_sec = 1000000000; 00057 00058 typedef struct 00059 { 00060 double alpha, alpha_static, zeta, epsilon; 00061 char *taskgraph, *platform; 00062 bool label; 00063 } args_t; 00064 00065 static args_t 00066 parse_arguments(char **argv) 00067 { 00068 args_t args; 00069 00070 // Default values 00071 args.alpha = 3; 00072 args.alpha_static = args.alpha; 00073 args.zeta = 0.1; 00074 args.epsilon = 0.5; 00075 args.taskgraph = NULL; 00076 args.platform = NULL; 00077 args.label = false; 00078 00079 for(argv++; argv[0] != NULL; argv++) 00080 { 00081 if(string(argv[0]).compare(string("--alpha")) == 0) 00082 { 00083 argv++; 00084 args.alpha = atof(argv[0]); 00085 continue; 00086 } 00087 if(string(argv[0]).compare(string("--alpha-static")) == 0) 00088 { 00089 argv++; 00090 args.alpha_static = atof(argv[0]); 00091 continue; 00092 } 00093 if(string(argv[0]).compare(string("--zeta")) == 0) 00094 { 00095 argv++; 00096 args.zeta = atof(argv[0]); 00097 continue; 00098 } 00099 if(string(argv[0]).compare(string("--epsilon")) == 0) 00100 { 00101 argv++; 00102 args.epsilon = atof(argv[0]); 00103 continue; 00104 } 00105 if(string(argv[0]).compare(string("--taskgraph")) == 0) 00106 { 00107 argv++; 00108 args.taskgraph = argv[0]; 00109 continue; 00110 } 00111 if(string(argv[0]).compare(string("--platform")) == 0) 00112 { 00113 argv++; 00114 args.platform = argv[0]; 00115 continue; 00116 } 00117 if(string(argv[0]).compare(string("--label")) == 0) 00118 { 00119 args.label = true; 00120 continue; 00121 } 00122 } 00123 00124 return args; 00125 } 00126 00127 int 00128 main(int argc, char** argv) 00129 { 00130 args_t args = parse_arguments(argv); 00131 00132 if(args.label == false) 00133 { 00134 if(args.taskgraph == NULL) 00135 { 00136 cerr << "Missing taskgraph file parameter. Check --taskgraph option." << endl; 00137 abort(); 00138 } 00139 if(args.platform == NULL) 00140 { 00141 cerr << "Missing platform file parameter. Check --platform option." << endl; 00142 abort(); 00143 } 00144 00145 struct timespec seed, total_time; 00146 clock_gettime(CLOCK_MONOTONIC, &total_time); 00147 srand(seed.tv_nsec); 00148 time_t t = time(NULL); 00149 srand(t); 00150 00151 cout << setprecision(6) << setiosflags(ios::fixed) << setiosflags(ios::showpoint); 00152 cerr << setprecision(6) << setiosflags(ios::fixed) << setiosflags(ios::showpoint); 00153 00154 ifstream taskgraph(args.taskgraph, std::ios::in); 00155 ifstream platform(args.platform, std::ios::in); 00156 00157 Algebra alg_arch = AmplInput(AmplInput::floatHandlers()).parse(platform); 00158 Platform *arch = new Platform(alg_arch); 00159 Algebra param; 00160 param.insert(new Scalar<float>("alpha", args.alpha)); 00161 param.insert(new Scalar<float>("zeta", args.zeta)); 00162 param.insert(new Scalar<float>("epsilon", args.epsilon)); 00163 param.insert(new Scalar<float>("alpha-static", args.alpha_static)); 00164 param.insert(new Scalar<float>("b", 2)); 00165 Taskgraph *tg = GraphML().parse(taskgraph); 00166 taskgraph.close(); 00167 platform.close(); 00168 00169 //cerr << tg->getMakespanCalculator() << " = " << tg->getRoundTime(arch) << endl; 00170 Algebra schedule = tg->buildAlgebra(arch); 00171 //AmplInput().dump(cerr, schedule); 00172 schedule = schedule.merge(arch->buildAlgebra()); 00173 schedule = schedule.merge(param); 00174 00175 // Somehow give alpha, zeta, epsilon and alpha-static (= alpha if nothing is said) to a unique energy model; if alpha-static = zeta = 0, then the model is equivalent to the simple model. 00176 #if !SHOWPOWER 00177 schedule = crown_binary(schedule, 3); 00178 #else 00179 schedule = crown_binary(schedule, 0); 00180 #endif 00181 schedule = CrownScheduler::crownToSchedule(schedule); 00182 XMLSchedule().dump(cout, Schedule("crown_binary", Schedule::addStartTime(schedule, tg, *arch)), tg, *arch); 00183 00184 AmplOutput(AmplOutput::floatHandlers()).dump(cerr, Scalar<float>("complexity", crown_binary_complexity(schedule) * (allocation_fastest_complexity(schedule) + mapping_ltlg_complexity(schedule) + frequency_height_complexity(schedule)))); 00185 00186 delete arch; 00187 delete tg; 00188 00189 float m = schedule.find<Scalar<float> >("m")->getValue(); 00190 float M = schedule.find<Scalar<float> >("M")->getValue(); 00191 if(m < 0 && M > 0) 00192 { 00193 cerr << "feasible = 0" << endl; 00194 } 00195 else 00196 { 00197 cerr << "feasible = 1" << endl; 00198 } 00199 00200 #if !SHOWPOWER 00201 float qual = mapping_quality(schedule); 00202 Scalar<float> q("quality", qual); 00203 00204 AmplOutput(AmplOutput::floatHandlers()).dump(cerr, &q); 00205 AmplOutput(AmplOutput::floatHandlers()).dump(cerr, schedule.find<Scalar<float> >("_total_solve_elapsed_time")); 00206 #endif 00207 } 00208 else 00209 { 00210 cout << "Bin,LTLG,Height(a=" << args.alpha << ","; 00211 if(args.alpha != args.alpha_static) 00212 { 00213 cout << "a_s=" << args.alpha_static << ","; 00214 } 00215 cout << "z=" << args.zeta << ",e=" << args.epsilon << ")" << endl; 00216 } 00217 00218 return EXIT_SUCCESS; 00219 } 00220