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