crown
1.0.0
|
00001 /* 00002 Copyright 2015 Nicolas Melot 00003 00004 This file is part of Pelib. 00005 00006 Pelib 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 Pelib 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 Pelib. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include <pelib/Vector.hpp> 00021 00022 #include <pelib/Scalar.hpp> 00023 #include <pelib/Vector.hpp> 00024 #include <pelib/Set.hpp> 00025 00026 #include <crown/CrownScaling.hpp> 00027 #include <crown/CrownAllocationFastest.hpp> 00028 #include <crown/CrownMappingLTLG.hpp> 00029 00030 #ifdef debug 00031 #undef debug 00032 #endif 00033 00034 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << (var) << "\"" << endl; 00035 00036 using namespace pelib; 00037 using namespace crown; 00038 using namespace std; 00039 00040 void 00041 CrownScaling::initialize(const CrownAllocation *alloc, const CrownMapping *mapping) 00042 { 00043 if(alloc == NULL) 00044 { 00045 this->alloc = new CrownAllocationFastest(0, showOutput, showError); 00046 } 00047 else 00048 { 00049 this->alloc = alloc->clone(); 00050 } 00051 00052 if(mapping == NULL) 00053 { 00054 this->mapping = new CrownMappingLTLG(config, alloc, showOutput, showError); 00055 } 00056 else 00057 { 00058 this->mapping = mapping->clone(); 00059 } 00060 } 00061 00062 CrownScaling::CrownScaling(const CrownConfig *config, const CrownAllocation *alloc, const CrownMapping *mapping, bool showOutput, bool showError): CrownScheduler(config, showOutput, showError) 00063 { 00064 initialize(alloc, mapping); 00065 } 00066 00067 CrownScaling::CrownScaling(const Algebra ¶m, const CrownConfig *config, const CrownAllocation *alloc, const CrownMapping *mapping, bool showOutput, bool showError): CrownScheduler(param, config, showOutput, showError) 00068 { 00069 initialize(alloc, mapping); 00070 } 00071 00072 CrownScaling::CrownScaling(const Taskgraph &tg, const Platform &pt, const Algebra ¶m, const CrownConfig *config, const CrownAllocation *alloc, const CrownMapping *mapping, bool showOutput, bool showError): CrownScheduler(tg, pt, param, config, showOutput, showError) 00073 { 00074 initialize(alloc, mapping); 00075 } 00076 00077 CrownScaling::CrownScaling(const CrownScaling &src) : CrownScheduler(src) 00078 { 00079 initialize(src.alloc, src.mapping); 00080 } 00081 00082 Schedule 00083 CrownScaling::schedule(const Taskgraph &tg, const Platform &pt, std::map<const string, double> &statistics) const 00084 { 00085 return schedule(tg, pt, param, statistics); 00086 } 00087 00088 Schedule 00089 CrownScaling::schedule(const Taskgraph &tg, const Platform &pt, const Algebra ¶m, std::map<const string, double> &statistics) const 00090 { 00091 // Take task names apart 00092 Algebra taskgraph = tg.buildAlgebra(pt); 00093 Vector<int, string> name = *taskgraph.find<Vector<int, string> >("name"); 00094 taskgraph.remove("name"); 00095 00096 Algebra p = param.merge(config->configure(tg, pt, param, statistics)); 00097 p = solve(taskgraph, pt.buildAlgebra(), p, statistics); 00098 00099 // Put back task names 00100 p.insert(new Vector<int, string>(name)); 00101 00102 p = crownToSchedule(p); 00103 p = Schedule::addStartTime(p, tg, pt); 00104 Schedule sched(getShortDescription(), tg.getName(), p); 00105 return sched; 00106 } 00107 00108 Algebra 00109 CrownScaling::solve(const Algebra &tg, const Algebra &pt, const pelib::Algebra ¶m, std::map<const std::basic_string<char>, double> &stats) const 00110 { 00111 Algebra input = tg; 00112 input = input.merge(pt); 00113 input = input.merge(param); 00114 00115 input = this->alloc->allocate(input, stats); 00116 input = this->mapping->map(input, stats); 00117 input = this->scale(input, stats); 00118 00119 // Make up a frequency vector with minimal frequency 00120 std::map<int, float> freq; 00121 for(int i = 1; i <= tg.find<Scalar<float> >("n")->getValue(); i++) 00122 { 00123 freq.insert(pair<int, float>(i, *pt.find<Set<float> >("F")->getValues().begin())); 00124 } 00125 Vector<int, float> frequency("frequency", freq); 00126 input.insert(&frequency); 00127 00128 return input; 00129 } 00130 00131 CrownScaling::~CrownScaling() 00132 { 00133 /* Do nothing */ 00134 } 00135