crown  1.0.0
src/crown_binary_simple.cpp
Go to the documentation of this file.
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 using namespace std;
00043 using namespace pelib;
00044 using namespace pelib::crown;
00045 
00046 // Quality assessment parameters
00047 const long long int nsec_in_sec = 1000000000;
00048 
00049 #if 0
00050 static int
00051 timespec_subtract(struct timespec *result, struct timespec *x, struct timespec *y)
00052 {
00053         /* Perform the carry for the later subtraction by updating y. */
00054         if (x->tv_nsec < y->tv_nsec)
00055         {
00056                 int nsec = (y->tv_nsec - x->tv_nsec) / nsec_in_sec + 1;
00057                 y->tv_nsec -= nsec_in_sec * nsec;
00058                 y->tv_sec += nsec;
00059         }
00060         if (x->tv_nsec - y->tv_nsec > nsec_in_sec)
00061         {
00062                 int nsec = (x->tv_nsec - y->tv_nsec) / nsec_in_sec;
00063                 y->tv_nsec += nsec_in_sec * nsec;
00064                 y->tv_sec -= nsec;
00065         }
00066      
00067         /* Compute the time remaining to wait. tv_nsec is certainly positive. */
00068         result->tv_sec = x->tv_sec - y->tv_sec;
00069         result->tv_nsec = x->tv_nsec - y->tv_nsec;
00070      
00071         /* Return 1 if result is negative. */
00072         return x->tv_sec < y->tv_sec;
00073 }
00074 #endif
00075 
00076 int
00077 main(int argc, char** argv)
00078 {
00079         struct timespec seed, total_time;
00080         clock_gettime(CLOCK_MONOTONIC, &total_time);
00081         srand(seed.tv_nsec);
00082         time_t t = time(NULL);
00083         srand(t);
00084 
00085         cout << setprecision(6) << setiosflags(ios::fixed) << setiosflags(ios::showpoint);
00086         cerr << setprecision(6) << setiosflags(ios::fixed) << setiosflags(ios::showpoint);
00087 
00088         ifstream taskgraph(argv[1], std::ios::in);
00089         ifstream platform(argv[2], std::ios::in);
00090         ifstream parameters(argv[3], std::ios::in);
00091 
00092         Algebra alg_arch = AmplInput(AmplInput::floatHandlers()).parse(platform);
00093         Platform *arch = new Platform(alg_arch);
00094         Algebra param = AmplInput(AmplInput::floatHandlers()).parse(parameters);
00095         Taskgraph *tg = GraphML().parse(taskgraph);
00096         taskgraph.close();
00097         platform.close();
00098         parameters.close();
00099 
00100         //cerr << tg->getMakespanCalculator() << " = " << tg->getRoundTime(arch) << endl;
00101         Algebra schedule = tg->buildAlgebra(arch);
00102         //AmplInput().dump(cerr, schedule);
00103         schedule = schedule.merge(arch->buildAlgebra());
00104         schedule = schedule.merge(param);
00105         
00106 #if !SHOWPOWER
00107         schedule = crown_binary_simple(schedule, 3);
00108 #else
00109         schedule = crown_binary_simple(schedule, 0);
00110 #endif
00111         schedule = CrownScheduler::crownToSchedule(schedule);
00112         XMLSchedule().dump(cout, Schedule("crown_binary", schedule), tg, *arch);
00113 
00114         AmplOutput(AmplOutput::floatHandlers()).dump(cerr, Scalar<float>("complexity", crown_binary_complexity(schedule) * (allocation_fastest_complexity(schedule) + mapping_ltlg_complexity(schedule) + frequency_height_complexity(schedule))));
00115 
00116         delete arch;
00117         delete tg;
00118 
00119         float m = schedule.find<Scalar<float> >("m")->getValue();
00120         if(m < 0)
00121         {
00122                 cerr << "feasible = 0" << endl;
00123         }
00124         else
00125         {
00126                 cerr << "feasible = 1" << endl;
00127         }
00128         
00129 #if !SHOWPOWER
00130         float qual = mapping_quality(schedule);
00131         Scalar<float> q("quality", qual);
00132 
00133         AmplOutput(AmplOutput::floatHandlers()).dump(cerr, &q);
00134         AmplOutput(AmplOutput::floatHandlers()).dump(cerr, schedule.find<Scalar<float> >("_total_solve_elapsed_time"));
00135 #endif
00136 
00137         return EXIT_SUCCESS;
00138 }
00139