Hybrid Query Processing Engine for Coprocessing in Database Systems
HyPE
online_learning.cpp
Go to the documentation of this file.
00001 
00006 #include <iostream>
00007 #include <hype.hpp>
00008 
00009 #include <boost/thread.hpp>
00010 
00011 using namespace hype;
00012 using namespace std;
00013 
00014 
00015 
00016 void CPU_algorithm(size_t data_size){
00017    boost::this_thread::sleep(boost::posix_time::milliseconds(data_size ));
00018 
00019 }
00020 
00021 void GPU_algorithm(size_t data_size){
00022    boost::this_thread::sleep(boost::posix_time::milliseconds((data_size/2)+50 ));
00023 
00024 }
00025 
00026 int main(){
00027    
00028    Scheduler& scheduler=Scheduler::instance();
00029 
00030 
00031    AlgorithmSpecification cpu_alg("CPU_Algorithm",
00032                                   "SORT",
00033                                   hype::Least_Squares_1D,
00034                                   hype::Periodic,
00035                                   hype::ResponseTime);
00036 
00037    DeviceSpecification cpu_dev_spec(hype::PD0, //by convention, the first CPU has Device ID: PD0  (any system has at least one)
00038                                     hype::CPU, //a CPU is from type CPU
00039                                     hype::PD_Memory_0); //by convention, the host main memory has ID PD_Memory_0
00040 
00041    AlgorithmSpecification gpu_alg("GPU_Algorithm",
00042                                   "SORT",
00043                                   hype::Least_Squares_1D,
00044                                   hype::Periodic,
00045                                   hype::ResponseTime);
00046 
00047    DeviceSpecification gpu_dev_spec(hype::PD1, //different porcessing device (naturally)
00048                                     hype::GPU, //Device Type
00049                                     hype::PD_Memory_1); //seperate device memory
00050 
00051    scheduler.addAlgorithm(cpu_alg, cpu_dev_spec);
00052    scheduler.addAlgorithm(gpu_alg, gpu_dev_spec);
00053 
00054 
00055 // if(!scheduler.setOptimizationCriterion("SORT","Simple Round Robin")) 
00056 //    std::cout << "Error: Could not set Optimization Criterion!" << std::endl;  else cout << "Success..." << endl;
00057 
00058    if(!scheduler.setOptimizationCriterion("SORT","Response Time")) 
00059       std::cout << "Error: Could not set Optimization Criterion!" << std::endl;  else cout << "Success..." << endl;
00060 
00061 // if(!scheduler.setOptimizationCriterion("SORT","WaitingTimeAwareResponseTime")) 
00062 //    std::cout << "Error: Could not set Optimization Criterion!" << std::endl;  else cout << "Success..." << endl;
00063 
00064 // if(!scheduler.setOptimizationCriterion("SORT","Throughput")) 
00065 //    std::cout << "Error: Could not set Optimization Criterion!" << std::endl;  else cout << "Success..." << endl;
00066 
00067 // if(!scheduler.setOptimizationCriterion("SORT","ProbabilityBasedOutsourcing")) 
00068 //    std::cout << "Error: Could not set Optimization Criterion!" << std::endl;  else cout << "Success..." << endl;
00069 
00070 
00071    for(int i=0;i<500;i++){
00072    core::Tuple t;
00073    t.push_back(rand()%300);
00074    uint64_t begin = core::getTimestamp();
00075 
00076    OperatorSpecification op_spec("SORT", 
00077                                  t,
00078                                  hype::PD_Memory_0, //input data is in CPU RAM
00079                                  hype::PD_Memory_0); //output data has to be stored in CPU RAM
00080 
00081    DeviceConstraint dev_constr;
00082 
00083 
00084    SchedulingDecision sched_dec = scheduler.getOptimalAlgorithm(op_spec, dev_constr);
00085    cout << "Line: " << i << " ";
00086    if(sched_dec.getNameofChoosenAlgorithm()=="CPU_Algorithm"){
00087       AlgorithmMeasurement alg_measure(sched_dec);
00088       CPU_algorithm(t[0]);
00089       alg_measure.afterAlgorithmExecution(); 
00090    }else if(sched_dec.getNameofChoosenAlgorithm()=="GPU_Algorithm"){
00091       AlgorithmMeasurement alg_measure(sched_dec);
00092       GPU_algorithm(t[0]);
00093       alg_measure.afterAlgorithmExecution(); 
00094    }
00095    
00096    uint64_t end = core::getTimestamp();
00097 
00098    uint64_t result = end-begin;
00099    if(begin>end) cout << "Fatal Error" << endl; 
00100    cout << result << endl;
00101    }
00102 
00103    
00104    //string algorithm_name = sched_dec.getNameofChoosenAlgorithm();
00105 
00106  return 0;
00107 };
00108 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines