pelib
2.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 00021 #include <iostream> 00022 00023 #include <iostream> 00024 #include <cstdlib> 00025 #include <fstream> 00026 #include <string> 00027 #include <boost/regex.hpp> 00028 #include <iomanip> 00029 00030 #include <pelib/Scalar.hpp> 00031 00032 #include <pelib/AmplInput.hpp> 00033 #include <pelib/AmplOutput.hpp> 00034 00035 #include <pelib/DummyCore.hpp> 00036 #include <pelib/GraphML.hpp> 00037 #include <pelib/Platform.hpp> 00038 #include <pelib/XMLSchedule.hpp> 00039 00040 #include <pelib/AmplInputData.hpp> 00041 #include <pelib/AmplInputScalar.hpp> 00042 #include <pelib/AmplInputVector.hpp> 00043 #include <pelib/AmplInputMatrix.hpp> 00044 00045 #include <pelib/AmplOutputScalar.hpp> 00046 #include <pelib/AmplOutputVector.hpp> 00047 #include <pelib/AmplOutputMatrix.hpp> 00048 00049 #include <pelib/Scalar.hpp> 00050 #include <pelib/Set.hpp> 00051 #include <pelib/Vector.hpp> 00052 #include <pelib/Matrix.hpp> 00053 00054 #include <pelib/unit.h> 00055 00056 #ifndef debug 00057 #if 0 00058 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << var << "\"" << endl; 00059 #else 00060 #define debug(var) 00061 #endif 00062 #endif 00063 00064 using namespace pelib; 00065 using namespace std; 00066 00067 static AmplInput input(AmplInput::intFloatHandlers()); 00068 static AmplOutput output(AmplOutput::intFloatHandlers()); 00069 00070 // Include cpp format input 00071 // Import the buildAlgebra() function 00072 #include "make_algebra.cpp" 00073 00074 extern char _binary_fft_n15_1_graphml_start; 00075 extern size_t _binary_fft_n15_1_graphml_size; 00076 std::string string_taskgraph_graphml; 00077 std::istringstream istream_taskgraph_graphml; 00078 00079 extern char _binary_fft_n15_1_input_dat_start; 00080 extern size_t _binary_fft_n15_1_input_dat_size; 00081 std::string string_taskgraph_amplinput; 00082 std::istringstream istream_taskgraph_amplinput; 00083 00084 extern char _binary_fft_n15_1_output_dat_start; 00085 extern size_t _binary_fft_n15_1_output_dat_size; 00086 std::string string_taskgraph_amploutput; 00087 std::istringstream istream_taskgraph_amploutput; 00088 00089 extern char _binary_p8_dat_start; 00090 extern size_t _binary_p8_dat_size; 00091 std::string string_platform; 00092 std::istringstream istream_platform; 00093 00094 extern char _binary_schedule_xml_start; 00095 extern size_t _binary_schedule_xml_size; 00096 std::string string_schedule_xml; 00097 std::istringstream istream_schedule_xml; 00098 00099 extern char _binary_crown_dat_start; 00100 extern size_t _binary_crown_dat_size; 00101 std::string string_schedule_crown; 00102 std::istringstream istream_schedule_crown; 00103 00104 extern char _binary_schedule_dat_start; 00105 extern size_t _binary_schedule_dat_size; 00106 std::string string_schedule_amploutput; 00107 std::istringstream istream_schedule_amploutput; 00108 00109 extern char _binary_platform_dat_start; 00110 extern size_t _binary_platform_dat_size; 00111 std::string string_platform_amplinput; 00112 std::istringstream istream_platform_amplinput; 00113 00114 void 00115 setup() 00116 { 00117 std::cout << std::setprecision(6) 00118 << std::setiosflags(std::ios::fixed) 00119 << std::setiosflags(std::ios::showpoint); 00120 } 00121 00122 void 00123 init() 00124 { 00125 string_taskgraph_graphml = std::string(&_binary_fft_n15_1_graphml_start).substr(0, (size_t)(&_binary_fft_n15_1_graphml_size)); 00126 istream_taskgraph_graphml.clear(); 00127 istream_taskgraph_graphml.str(string_taskgraph_graphml); 00128 00129 string_taskgraph_amplinput = std::string(&_binary_fft_n15_1_input_dat_start).substr(0, (size_t)(&_binary_fft_n15_1_input_dat_size)); 00130 istream_taskgraph_amplinput.clear(); 00131 istream_taskgraph_amplinput.str(string_taskgraph_amplinput); 00132 00133 string_taskgraph_amploutput = std::string(&_binary_fft_n15_1_output_dat_start).substr(0, (size_t)(&_binary_fft_n15_1_output_dat_size)); 00134 istream_taskgraph_amploutput.clear(); 00135 istream_taskgraph_amploutput.str(string_taskgraph_amploutput); 00136 00137 string_platform = std::string(&_binary_p8_dat_start).substr(0, (size_t)(&_binary_p8_dat_size)); 00138 istream_platform.clear(); 00139 istream_platform.str(string_platform); 00140 00141 string_schedule_xml = std::string(&_binary_schedule_xml_start).substr(0, (size_t)(&_binary_schedule_xml_size)); 00142 istream_schedule_xml.clear(); 00143 istream_schedule_xml.str(string_schedule_xml); 00144 00145 string_schedule_crown = std::string(&_binary_crown_dat_start).substr(0, (size_t)(&_binary_crown_dat_size)); 00146 istream_schedule_crown.clear(); 00147 istream_schedule_crown.str(string_schedule_crown); 00148 00149 string_schedule_amploutput = std::string(&_binary_schedule_dat_start).substr(0, (size_t)(&_binary_schedule_dat_size)); 00150 istream_schedule_amploutput.clear(); 00151 istream_schedule_amploutput.str(string_schedule_amploutput); 00152 00153 string_platform_amplinput = std::string(&_binary_platform_dat_start).substr(0, (size_t)(&_binary_platform_dat_size)); 00154 istream_platform_amplinput.clear(); 00155 istream_platform_amplinput.str(string_platform_amplinput); 00156 00157 /* 00158 set<float> f; 00159 f.insert(1); 00160 f.insert(2); 00161 f.insert(3); 00162 f.insert(4); 00163 f.insert(5); 00164 pt = Platform(8, new DummyCore(f)); 00165 */ 00166 } 00167 00168 void 00169 teardown() 00170 { 00171 // Do not forget to free your stacks after each test 00172 // to avoid memory leaks as now 00173 } 00174 00175 void 00176 cleanup() 00177 { 00178 // Destroy properly your test batch 00179 } 00180 00181 void 00182 parse_and_convert_graphml() 00183 { 00184 Taskgraph tg_graphml = GraphML().parse(istream_taskgraph_graphml); 00185 Algebra ampl_arch = AmplInput(AmplInput::floatHandlers()).parse(istream_platform); 00186 Platform arch(ampl_arch); 00187 00188 Algebra tg_graphml_algebra = tg_graphml.buildAlgebra(arch); 00189 Taskgraph tg_from_algebra(tg_graphml_algebra); 00190 00191 string efficiency = tg_graphml.getTasks().begin()->getEfficiencyString(); 00192 tg_from_algebra.setDeadlineCalculator("exprtk:var minF := 0; for(var j := 2; j <= n[]; j += 1) { minF += tau[j - 1] / (2 * p[] * min(F)); }; var maxF := 0; for(var j := 2; j <= n[]; j += 1) { maxF += tau[j - 1] / (2 * p[] * max(F)); }; minF + maxF"); 00193 for(set<Task>::iterator i = (set<Task>::iterator)tg_from_algebra.getTasks().begin(); i != (set<Task>::iterator)tg_from_algebra.getTasks().end(); i++) 00194 { 00195 Task &t = (Task&)*i; 00196 t.setEfficiencyString(efficiency); 00197 } 00198 00199 stringstream reference; 00200 GraphML().dump(reference, tg_from_algebra); 00201 00202 if(reference.str().compare(string_taskgraph_graphml) != 0) 00203 { 00204 cout << "Expected: " << string_taskgraph_graphml << endl; 00205 cout << "Obtained: " << reference.str() << endl; 00206 } 00207 00208 assert(reference.str().compare(string_taskgraph_graphml) == 0); 00209 00210 // Algebra taskgraph_algebra = AmplInput(AmplInput::floatHandlers()).parse(istream_taskgraph_amplinput); 00211 00212 #if 0 00213 cout << string_taskgraph_graphml << endl; 00214 cout << "===============" << endl; 00215 cout << string_taskgraph_amplinput << endl; 00216 cout << "===============" << endl; 00217 cout << string_taskgraph_amploutput << endl; 00218 cout << "===============" << endl; 00219 cout << string_platform << endl; 00220 cout << "===============" << endl; 00221 cout << string_schedule_xml << endl; 00222 cout << "===============" << endl; 00223 cout << string_schedule_crown << endl; 00224 cout << "===============" << endl; 00225 cout << string_schedule_amplinput << endl; 00226 cout << "===============" << endl; 00227 #endif 00228 } 00229 00230 void 00231 parse_and_convert_schedule() 00232 { 00233 Taskgraph tg_graphml = GraphML().parse(istream_taskgraph_graphml); 00234 Algebra ampl_schedule = AmplOutput(AmplOutput::floatHandlers()).parse(istream_schedule_amploutput); 00235 Algebra alg_arch = AmplInput(AmplInput::floatHandlers()).parse(istream_platform_amplinput); 00236 Platform pt(alg_arch); 00237 00238 Schedule schedule("Converted from AMPL", ampl_schedule); 00239 00240 stringstream reference; 00241 XMLSchedule().dump(reference, schedule, tg_graphml, pt); 00242 00243 if(reference.str().compare(string_schedule_xml) != 0) 00244 { 00245 cout << "Expected: " << string_schedule_xml << endl; 00246 cout << "Obtained: " << reference.str() << endl; 00247 } 00248 00249 assert(reference.str().compare(string_schedule_xml) == 0); 00250 } 00251 00252 void 00253 run() 00254 { 00255 test(parse_and_convert_graphml); 00256 test(parse_and_convert_schedule); 00257 } 00258