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 <crown/CrownConfigOrgan.hpp> 00021 #include <pelib/Matrix.hpp> 00022 #include <pelib/time.h> 00023 #include <pelib/AmplInput.hpp> 00024 00025 #ifdef debug 00026 #undef debug 00027 #endif 00028 00029 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << (var) << "\"" << endl; 00030 00031 using namespace pelib; 00032 using namespace crown; 00033 using namespace std; 00034 00035 static 00036 map<int, map<int, float> > 00037 build_crown(size_t p, size_t wi, size_t skip, const map<int, map<int, float> > matrix, map<int, map<int, float> > &tree) 00038 { 00039 map<int, map<int, float> > config = matrix; 00040 map<int, float> group; 00041 for(size_t i = 0; i < p; i++) 00042 { 00043 if(i < skip || i >= skip + wi) 00044 { 00045 group.insert(pair<int, float>(i + 1, 0)); 00046 } 00047 else 00048 { 00049 group.insert(pair<int, float>(i + 1, 1)); 00050 } 00051 } 00052 00053 // Dependencies fo this group 00054 map<int, float> deps; 00055 for(size_t i = 0; i < 2 * p - 1; i++) 00056 { 00057 deps.insert(pair<int, float>(i + 1, 0)); 00058 } 00059 00060 // Browse all other groups already formed 00061 for(map<int, map<int, float> >::iterator i = config.begin(); i != config.end(); i++) 00062 { 00063 // Browse all cores 00064 int ii = std::distance(config.begin(), i) + 1; 00065 for(map<int, float>::iterator j = i->second.begin(); j != i->second.end(); j++) 00066 { 00067 int jj = std::distance(i->second.begin(), j) + 1; 00068 // If both groups have the core, then there is a dependency link 00069 if(group[jj] == j->second && j->second > 0) 00070 { 00071 deps[ii] = 1; 00072 break; 00073 } 00074 } 00075 } 00076 00077 // Add groups membership and dependencies to temporary outcome 00078 config.insert(pair<int, map<int, float> >(config.size() + 1, group)); 00079 tree.insert(pair<int, map<int, float> >(tree.size() + 1, deps)); 00080 00081 // Recurse, if necessary 00082 if(wi > 1) 00083 { 00084 config = build_crown(p, wi - 1, skip, config, tree); 00085 config = build_crown(p, 1, skip + wi - 1, config, tree); 00086 } 00087 00088 return config; 00089 } 00090 00091 string 00092 CrownConfigOrgan::getShortDescription() const 00093 { 00094 return string("org"); 00095 } 00096 00097 Algebra 00098 CrownConfigOrgan::configure(const Taskgraph &tg, const Platform &pt, const Algebra ¶m, std::map<const string, double> &stats) const 00099 { 00100 // Compute a binary crown and place it in class' Algebra container 00101 size_t p = pt.getCores().size(); 00102 map<int, map<int, float> > tree; 00103 struct timespec start, stop, total_time; 00104 00105 clock_gettime(CLOCK_MONOTONIC, &start); 00106 map<int, map<int, float> > config = build_crown(p, p, 0, map<int, map<int, float> >(), tree); 00107 clock_gettime(CLOCK_MONOTONIC, &stop); 00108 00109 pelib_timespec_subtract(&total_time, &stop, &start); 00110 stats.insert(pair<const string, double>("time_config", (float)(total_time.tv_sec * pelib_nsec_in_sec + total_time.tv_nsec) / (float)pelib_nsec_in_sec)); 00111 00112 Algebra conf; 00113 conf.insert(new Matrix<int, int, float>(CrownConfig::crownConfigGroups, config)); 00114 conf.insert(new Matrix<int, int, float>(CrownConfig::crownConfigTree, tree)); 00115 00116 return conf; 00117 } 00118 00119 CrownConfigOrgan::~CrownConfigOrgan() 00120 { 00121 // Do nothing 00122 } 00123 00124 CrownConfig* 00125 CrownConfigOrgan::clone() const 00126 { 00127 return new CrownConfigOrgan(*this); 00128 } 00129 00130 float 00131 CrownConfigOrgan::complexity(const Algebra &problem) const 00132 { 00133 return 0; 00134 } 00135 00136 float 00137 CrownConfigOrgan::complexity(const Taskgraph&, const Platform&, const Algebra&) const 00138 { 00139 return 0; 00140 } 00141