Hybrid Query Processing Engine for Coprocessing in Database Systems
HyPE
|
00001 /*********************************************************************************************************** 00002 Copyright (c) 2013, Sebastian Breß, Otto-von-Guericke University of Magdeburg, Germany. All rights reserved. 00003 00004 This program and accompanying materials are made available under the terms of the 00005 GNU LESSER GENERAL PUBLIC LICENSE - Version 3, http://www.gnu.org/licenses/lgpl-3.0.txt 00006 ***********************************************************************************************************/ 00007 00008 #include <hype.h> 00009 #include <hype.hpp> 00010 #include <config/global_definitions.hpp> 00011 #include <core/scheduler.hpp> 00012 #include <core/time_measurement.hpp> 00013 #include <string> 00014 00015 using namespace hype; 00016 using namespace std; 00017 00018 #include <stdlib.h> 00019 #include <stdio.h> 00020 00021 //#define NDEBUG //uncomment for release version 00022 #include <assert.h> 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 00029 /*#############################################################################*/ 00030 /************************* Scheduling Decision ******************************/ 00031 00032 /*#############################################################################*/ 00033 00034 char* hype_SchedulingDecision_getAlgorithmName(C_SchedulingDecision* sched_dec){ 00035 if(!sched_dec) return NULL; 00036 SchedulingDecision* ptr = static_cast<SchedulingDecision*> (sched_dec->ptr); 00037 if(!ptr) return NULL; 00038 std::string result = ptr->getNameofChoosenAlgorithm(); 00039 const char* tmp = result.c_str(); 00040 char* c_result = (char*) malloc(result.size()+1); //plus one because if zero byte '\0' 00041 strcpy(c_result,tmp); 00042 return c_result; 00043 } 00044 00045 ProcessingDeviceID hype_SchedulingDecision_getProcessingDeviceID(C_SchedulingDecision* sched_dec){ 00046 if(!sched_dec) return PD0; 00047 SchedulingDecision* ptr = static_cast<SchedulingDecision*> (sched_dec->ptr); 00048 if(!ptr) return PD0; 00049 return ptr->getDeviceSpecification().getProcessingDeviceID(); 00050 } 00051 00052 int hype_deleteSchedulingDecision(C_SchedulingDecision* sched_dec) { 00053 if(!sched_dec) return int(false); 00054 SchedulingDecision* ptr = static_cast<SchedulingDecision*> (sched_dec->ptr); 00055 delete ptr; 00056 if (sched_dec) free(sched_dec); 00057 return int(true); 00058 } 00059 00060 /*#############################################################################*/ 00061 /************************* Algorithm Specification ******************************/ 00062 00063 /*#############################################################################*/ 00064 00065 C_AlgorithmSpecification* hype_createAlgorithmSpecification(const char* alg_name, 00066 const char* op_name, 00067 StatisticalMethod stat_meth, 00068 RecomputationHeuristic recomp_heur, 00069 OptimizationCriterion opt_crit) { 00070 C_AlgorithmSpecification* alg_spec = (C_AlgorithmSpecification*) malloc(sizeof (C_AlgorithmSpecification)); 00071 if (!alg_spec) return NULL; 00072 alg_spec->ptr = new AlgorithmSpecification(alg_name, op_name, stat_meth, recomp_heur, opt_crit); 00073 00074 return alg_spec; 00075 } 00076 00077 int hype_deleteAlgorithmSpecification(C_AlgorithmSpecification* alg_spec) { 00078 if(!alg_spec) return int(false); 00079 AlgorithmSpecification* ptr = static_cast<AlgorithmSpecification*> (alg_spec->ptr); 00080 delete ptr; 00081 if (alg_spec) free(alg_spec); 00082 return int(true); 00083 } 00084 00085 /*#############################################################################*/ 00086 /************************* Device Specification ******************************/ 00087 00088 /*#############################################################################*/ 00089 00090 C_DeviceSpecification* hype_createDeviceSpecification(ProcessingDeviceID pd, 00091 ProcessingDeviceType pd_t, 00092 ProcessingDeviceMemoryID pd_m) { 00093 C_DeviceSpecification* dev_spec = (C_DeviceSpecification*) malloc(sizeof (C_DeviceSpecification)); 00094 if (!dev_spec) return NULL; 00095 dev_spec->ptr = new DeviceSpecification(pd, pd_t, pd_m); 00096 00097 return dev_spec; 00098 } 00099 00100 int hype_deleteDeviceSpecification(C_DeviceSpecification* dev_spec) { 00101 if(!dev_spec) return int(false); 00102 DeviceSpecification* ptr = static_cast<DeviceSpecification*> (dev_spec->ptr); 00103 delete ptr; 00104 if (dev_spec) free(dev_spec); 00105 return int(true); 00106 } 00107 00108 /*#############################################################################*/ 00109 /************************* Operator Specification ******************************/ 00110 00111 /*#############################################################################*/ 00112 00113 00114 C_OperatorSpecification* hype_create_OperatorSpecification(const char* operator_name, 00115 double* feature_vector, 00116 size_t feature_vector_length, 00117 ProcessingDeviceMemoryID location_of_input_data, 00118 ProcessingDeviceMemoryID location_for_output_data) { 00119 C_OperatorSpecification* op_spec = (C_OperatorSpecification*) malloc(sizeof (C_OperatorSpecification)); 00120 if (!op_spec) return NULL; 00121 op_spec->ptr = new OperatorSpecification(operator_name,std::vector<double>(feature_vector,feature_vector+feature_vector_length),location_of_input_data,location_for_output_data); 00122 return op_spec; 00123 } 00124 00125 int hype_deleteOperatorSpecification(C_OperatorSpecification* op_spec) { 00126 if(!op_spec) return int(false); 00127 if(!op_spec->ptr) return int(false); 00128 OperatorSpecification* ptr = static_cast<OperatorSpecification*> (op_spec->ptr); 00129 delete ptr; 00130 if (op_spec) free(op_spec); 00131 return int(true); 00132 } 00133 00134 /*#############################################################################*/ 00135 /************************* Device Constraints *********************************/ 00136 00137 /*#############################################################################*/ 00138 00139 00140 C_DeviceConstraint* hype_createDeviceConstraint(DeviceTypeConstraint dev_type_constr, 00141 ProcessingDeviceMemoryID pd_mem_constr) { 00142 C_DeviceConstraint* dev_constr = (C_DeviceConstraint*) malloc(sizeof (C_DeviceConstraint)); 00143 if (!dev_constr) return NULL; 00144 dev_constr->ptr = new DeviceConstraint(dev_type_constr); //, pd_mem_constr); 00145 return dev_constr; 00146 } 00147 00148 int hype_deleteDeviceConstraint(C_DeviceConstraint* dev_const) { 00149 if(!dev_const) return int(false); 00150 DeviceConstraint* ptr = static_cast<DeviceConstraint*> (dev_const->ptr); 00151 delete ptr; 00152 if (dev_const) free(dev_const); 00153 return int(true); 00154 } 00155 00156 00157 /*#############################################################################*/ 00158 /************************* Scheduler functions *********************************/ 00159 00160 /*#############################################################################*/ 00161 00162 00163 int hype_addAlgorithm(const C_AlgorithmSpecification* alg_spec, const C_DeviceSpecification* dev_spec) { 00164 if(alg_spec==NULL) return int(false); 00165 if(dev_spec==NULL) return int(false); 00166 if(alg_spec->ptr==NULL) return int(false); 00167 if(dev_spec->ptr==NULL) return int(false); 00168 AlgorithmSpecification* alg = static_cast<AlgorithmSpecification*>(alg_spec->ptr); 00169 DeviceSpecification* dev = static_cast<DeviceSpecification*>(dev_spec->ptr); 00170 return int(Scheduler::instance().addAlgorithm(*alg,*dev)); 00171 } 00172 00173 int hype_setOptimizationCriterion(const char* name_of_operation, 00174 const char* name_of_optimization_criterion) { 00175 if(name_of_operation==NULL) return int(false); 00176 if(name_of_optimization_criterion==NULL) return int(false); 00177 return int(Scheduler::instance().setOptimizationCriterion(name_of_operation,name_of_optimization_criterion)); 00178 } 00179 00180 int hype_setStatisticalMethod(const char* name_of_algorithm, 00181 const char* name_of_statistical_method) { 00182 if(name_of_algorithm==NULL) return int(false); 00183 if(name_of_statistical_method==NULL) return int(false); 00184 return int(Scheduler::instance().setStatisticalMethod(name_of_algorithm,name_of_statistical_method)); 00185 } 00186 00187 int hype_setRecomputationHeuristic(const char* name_of_algorithm, 00188 const char* name_of_recomputation_strategy) { 00189 00190 if(name_of_algorithm==NULL) return int(false); 00191 if(name_of_recomputation_strategy==NULL) return int(false); 00192 return int(Scheduler::instance().setRecomputationHeuristic(name_of_algorithm,name_of_recomputation_strategy)); 00193 00194 } 00195 00196 C_SchedulingDecision* hype_getOptimalAlgorithm(const C_OperatorSpecification* op_spec, const C_DeviceConstraint* dev_constr) { 00197 if(!op_spec) return int(false); 00198 if(!op_spec->ptr) return int(false); 00199 if(!dev_constr) return int(false); 00200 if(!dev_constr->ptr) return int(false); 00201 OperatorSpecification* op_ptr = static_cast<OperatorSpecification*> (op_spec->ptr); 00202 DeviceConstraint* dev_ptr = static_cast<DeviceConstraint*> (op_spec->ptr); 00203 SchedulingDecision sched_dec = Scheduler::instance().getOptimalAlgorithm(*op_ptr,hype::DeviceConstraint()); //,*dev_ptr); 00204 SchedulingDecision* sched_dec_ptr = new SchedulingDecision(sched_dec); 00205 C_SchedulingDecision* c_sched_dec = (C_SchedulingDecision*) malloc(sizeof (C_SchedulingDecision)); 00206 if (!c_sched_dec) return NULL; 00207 c_sched_dec->ptr=sched_dec_ptr; 00208 return c_sched_dec; 00209 } 00210 00211 int hype_addObservation(const C_SchedulingDecision* sched_dec, const double measured_execution_time) { 00212 if(!sched_dec) return int(false); 00213 if(!sched_dec->ptr) return int(false); 00214 SchedulingDecision* op_ptr = static_cast<SchedulingDecision*> (sched_dec->ptr); 00215 return int(Scheduler::instance().addObservation(*op_ptr,measured_execution_time)); 00216 00217 } 00218 00219 double hype_getEstimatedExecutionTime(const C_OperatorSpecification* op_spec, const char* alg_name) { 00220 if(!op_spec) return int(false); 00221 if(!op_spec->ptr) return int(false); 00222 if(!alg_name) return int(false); 00223 OperatorSpecification* ptr = static_cast<OperatorSpecification*> (op_spec->ptr); 00224 return Scheduler::instance().getEstimatedExecutionTime(*ptr,alg_name).getTimeinNanoseconds(); 00225 } 00226 00227 /*#############################################################################*/ 00228 /************************* Util functions *********************************/ 00229 /*#############################################################################*/ 00230 uint64_t hype_getTimestamp(){ 00231 return hype::core::getTimestamp(); 00232 } 00233 00234 void hype_printStatus(){ 00235 core::Scheduler::instance().print(); 00236 } 00237 00238 00239 #ifdef __cplusplus 00240 } 00241 #endif 00242 00243 00244 00245 /* 00246 int stemod_operation_addAlgorithm(const char* name_of_operation, stemod::ComputeDevice comp_dev , const char* name_of_algorithm, const char* name_of_statistical_method, 00247 const char* name_of_recomputation_strategy){ 00248 00249 return static_cast<int> (core::Scheduler::instance().addAlgorithm(name_of_operation, name_of_algorithm, comp_dev, name_of_statistical_method, 00250 name_of_recomputation_strategy)){ 00251 return 0; 00252 } 00253 00254 } 00255 00256 00257 int stemod_operation_optimization_criterion_set(const char* name_of_operation,const char* name_of_optimization_criterion){ 00258 00259 return static_cast<int> (core::Scheduler::instance().setOptimizationCriterion(name_of_operation,name_of_optimization_criterion)){ 00260 return 0; 00261 } 00262 00263 } 00264 00265 00266 int stemod_algorithm_statistical_method_set(const char* name_of_algorithm,const char* name_of_statistical_method){ 00267 00268 return static_cast<int> (core::Scheduler::instance().setStatisticalMethod(name_of_algorithm,name_of_statistical_method)){ 00269 return 0; 00270 } 00271 00272 } 00273 00274 int stemod_algorithm_recomputation_heuristic_set(const char* name_of_algorithm,const char* name_of_recomputation_strategy){ 00275 00276 return static_cast<int> (core::Scheduler::instance().setRecomputationHeuristic(name_of_algorithm,name_of_recomputation_strategy)){ 00277 return 0; 00278 } 00279 00280 } 00281 00282 00283 char* stemod_scheduler_OptimalAlgorithmName_get(const char* name_of_operation){ 00284 00285 //TODO: schnittstelle ändern, sodass eingabedaten übergeben werden können! 00286 core::Tuple test{ 00287 return 0; 00288 } 00289 //SchedulingDecision dec = core::Scheduler::instance().getOptimalAlgorithmName(name_of_operation,test){ 00290 return 0; 00291 } 00292 00293 // char* ret=(char*)malloc(dec.size()){ 00294 return 0; 00295 } 00296 // 00297 // for(int i=0{ 00298 return 0; 00299 }i<name.size(){ 00300 return 0; 00301 }++i){ 00302 // ret[i]=name[i]{ 00303 return 0; 00304 } 00305 // } 00306 // 00307 // return ret{ 00308 return 0; 00309 } 00310 cout << name_of_operation << endl{ 00311 return 0; 00312 } 00313 00314 return (char*) 0{ 00315 return 0; 00316 } 00317 } 00318 00319 void stemod_algorithm_measurement_before_execution(struct C_AlgorithmMeasurement* algmeas,const char* name_of_algorithm,double* values,size_t number_of_values){ //starts timer 00320 00321 algmeas->starting_point_timestamp=0{ 00322 return 0; 00323 } //getTimestamp(){ 00324 return 0; 00325 } 00326 algmeas->is_valid=1{ 00327 return 0; 00328 } 00329 cout << name_of_algorithm << values << number_of_values << endl{ 00330 return 0; 00331 } 00332 00333 } 00334 00335 void stemod_algorithm_measurement_after_execution(struct C_AlgorithmMeasurement* algmeas){ //stops timer 00336 00337 00338 00339 assert(algmeas->is_valid==1){ 00340 return 0; 00341 } 00342 algmeas->is_valid=0{ 00343 return 0; 00344 } 00345 00346 } 00347 */ 00348 00349 /* 00350 int hype_add_algorithm_to_operation(const char* name_of_operation, const char* name_of_algorithm, 00351 ComputeDevice comp_dev, const char* name_of_statistical_method, 00352 const char* name_of_recomputation_strategy){ 00353 00354 return static_cast<int> (Scheduler::instance().addAlgorithm(name_of_operation, name_of_algorithm, 00355 comp_dev, name_of_statistical_method, 00356 name_of_recomputation_strategy)){ 00357 return 0; 00358 } 00359 } 00360 00361 int hype_set_optimization_criterion(const char* name_of_operation,const char* name_of_optimization_criterion){ 00362 return static_cast<int> (Scheduler::instance().setOptimizationCriterion(name_of_operation,name_of_optimization_criterion)){ 00363 return 0; 00364 } 00365 } 00366 00367 int hype_set_statistical_method(const char* name_of_algorithm,const char* name_of_statistical_method){ 00368 return static_cast<int> (core::Scheduler::instance().setStatisticalMethod(name_of_algorithm,name_of_statistical_method)){ 00369 return 0; 00370 } 00371 } 00372 00373 00374 int hype_set_recomputation_heuristic(const char* name_of_algorithm,const char* name_of_recomputation_strategy){ 00375 return static_cast<int> (core::Scheduler::instance().setRecomputationHeuristic(name_of_algorithm,name_of_recomputation_strategy)){ 00376 return 0; 00377 } 00378 } 00379 00380 char* hype_scheduling_decision_get_algorithm_name(C_SchedulingDecision* scheduling_decision_ptr){ 00381 core::SchedulingDecision* sched_dec_ptr = static_cast<core::SchedulingDecision*>(scheduling_decision_ptr->cpp_scheduling_decison_object_ptr){ 00382 return 0; 00383 } 00384 string str = sched_dec_ptr->getAlgortihmName(){ 00385 return 0; 00386 } 00387 char* cstr = (char*) malloc(str.length()+1){ 00388 return 0; 00389 } //new char [str.length()+1]{ 00390 return 0; 00391 } 00392 std::strcpy (cstr, str.c_str()){ 00393 return 0; 00394 } 00395 return cstr{ 00396 return 0; 00397 } 00398 } 00399 00400 ComputeDevice hype_scheduling_decision_get_compute_device(C_SchedulingDecision* scheduling_decision_ptr){ 00401 core::SchedulingDecision* sched_dec_ptr = static_cast<core::SchedulingDecision*>(scheduling_decision_ptr->cpp_scheduling_decison_object_ptr){ 00402 return 0; 00403 } 00404 return sched_dec_ptr->getComputeDevice(){ 00405 return 0; 00406 } 00407 } 00408 00409 double hype_scheduling_decision_get_estimated_executiontime(C_SchedulingDecision* scheduling_decision_ptr){ 00410 core::SchedulingDecision* sched_dec_ptr = static_cast<core::SchedulingDecision*>(scheduling_decision_ptr->cpp_scheduling_decison_object_ptr){ 00411 return 0; 00412 } 00413 return sched_dec_ptr->getEstimatedExecutionTimeforAlgorithm().getTimeinNanoseconds(){ 00414 return 0; 00415 } 00416 } 00417 00418 C_SchedulingDecision* hype_get_scheduling_decision(const char* name_of_operation, const double* feature_vector, size_t number_of_features){ 00419 Tuple t(feature_vector,feature_vector+number_of_features){ 00420 return 0; 00421 } 00422 core::SchedulingDecision sched_dec = scheduler.getOptimalAlgorithmName(name_of_operation,t){ 00423 return 0; 00424 } 00425 core::SchedulingDecision* sched_dec_ptr= new core::SchedulingDecision(sched_dec){ 00426 return 0; 00427 } 00428 00429 C_SchedulingDecision* c_sched_dec_ptr = (C_SchedulingDecision*) malloc(sizeof(C_SchedulingDecision)){ 00430 return 0; 00431 } 00432 c_sched_dec_ptr->cpp_scheduling_decison_object_ptr=(void*)sched_dec_ptr{ 00433 return 0; 00434 } 00435 } 00436 00437 void hype_free_scheduling_decision(C_SchedulingDecision* c_sched_dec_ptr){ 00438 if(c_sched_dec_ptr){ 00439 delete c_sched_dec_ptr->cpp_scheduling_decison_object_ptr{ 00440 return 0; 00441 } 00442 free(c_sched_dec_ptr){ 00443 return 0; 00444 } 00445 } 00446 } 00447 00448 void hype_before_algorithm_execution(struct C_AlgorithmMeasurement* algmeas,C_SchedulingDecision* scheduling_decision_ptr, const double* values,size_t number_of_values){ 00449 return 0; 00450 } //starts timer 00451 00452 void hype_after_algorithm_execution(struct C_AlgorithmMeasurement* algmeas){ 00453 return 0; 00454 } //stops timer 00455 00456 int hype_add_observation(C_SchedulingDecision* scheduling_decision_ptr, double measured_execution_time_in_ns){ 00457 return 0; 00458 } 00459 00460 */