27 #ifndef METERPU_INCLUSION_GUARD
28 #define METERPU_INCLUSION_GUARD
50 #ifdef ENABLE_SYSTEM_ENERGY //SYSTEM_ENERGY depends on PCM and NVML
67 #include <cpucounters.h>
87 #define PRINT_FUNC_NAME(message) std::cout<<"["<<__FILE__<<"#"<<__LINE__<<" "<<__func__<<"():] "<<message<<std::endl
88 #define PRINT_FUNC_NAME_CONT std::cout<<"["<<__FILE__<<"#"<<__LINE__<<" "<<__func__<<"():] "
90 #define DECLARE_CLASS_NAME(name) static std::string class_name(){return name;}
91 #define PRINT_CLASS_FUNC_NAME(message) std::cout<<"["<<__FILE__<<"#"<<__LINE__<<" "<<class_name()<<" "<<__func__<<"():] "<<message<<std::endl
92 #define PRINT_CLASS_FUNC_NAME_CONT std::cout<<"["<<__FILE__<<"#"<<__LINE__<<" "<<class_name()<<" "<<__func__<<"():] "
126 #define METERPU_TIME_MEASURE(x) clock_gettime(CLOCK_MONOTONIC, x)
132 bool bash_exe (
const std::string& cmd,std::vector<std::string>& out ) {
134 const int SIZEBUF = 1234;
136 out = std::vector<std::string> ();
137 if ((fp = popen(cmd.c_str (),
"r")) == NULL) {
140 std::string cur_string =
"";
141 while (fgets(buf,
sizeof (buf), fp)) {
144 out.push_back (cur_string.substr (0, cur_string.size () - 1));
172 #ifdef ENABLE_CUDA_TIME
181 template<GPU_Device_Id_Type device_
id=0>
183 template<GPU_Device_Id_Type device_
id>
193 #ifdef ENABLE_SYSTEM_ENERGY
349 CPU_Time::ResultType elapse_time = ((stop_time.tv_sec - start_time.tv_sec)*1000000.0f+(stop_time.tv_nsec - start_time.tv_nsec)/1000.0f);
350 #ifdef DEBUG_OPERATOR_MINUS
352 std::cout<<
"stop_time.tv_sec: "<<stop_time.tv_sec<<
"start_time.tv_sec: "<<start_time.tv_sec<<std::endl;
353 std::cout<<
"stop_time.tv_nsec: "<<stop_time.tv_nsec<<
"start_time.tv_nsec: "<<start_time.tv_nsec<<std::endl;
356 assert(elapse_time>=0);
366 if(small_time.tv_sec<large_time.tv_sec)
368 if(small_time.tv_sec>large_time.tv_sec)
370 if(small_time.tv_nsec<large_time.tv_nsec)
381 if(small_time.tv_sec!=large_time.tv_sec)
383 if(small_time.tv_nsec!=large_time.tv_nsec)
394 return (small_time<large_time || small_time == large_time);
399 #ifdef ENABLE_CUDA_TIME
437 template<GPU_Device_Id_Type device_
id>
464 #ifdef ENABLE_SYSTEM_ENERGY
487 template <
class Type>
495 std::cout<<
"-----------------------------"<<
"\n";
497 std::cout<<
"*****************************"<<
"\n";
498 for(iterator=a.begin();iterator!=a.end();++iterator)
499 std::cout<<*iterator<<
"\n";
500 std::cout<<
"*****************************"<<
"\n";
524 inline std::ostream &operator<<(std::ostream &out, NVML_Energy<>::Time_Unit ts)
527 out<<ts.tv_sec*1e6+ts.tv_nsec/1e3;
552 virtual void init()=0;
566 #if METERPU_VERBOSE >= 1
573 #ifdef ENABLE_CUDA_TIME
585 #if METERPU_VERBOSE >= 1
606 #if METERPU_VERBOSE >= 1
674 if (NVML_SUCCESS != result)
676 printf(
"Failed to initialize NVML: %s\n",
677 nvmlErrorString(result));
679 printf(
"Press ENTER to continue...\n");
683 #if METERPU_VERBOSE >= 1
693 result = nvmlShutdown();
694 if (NVML_SUCCESS != result)
696 printf(
"Failed to shutdown NVML: %s\n",
697 nvmlErrorString(result));
699 printf(
"All done.\n");
701 printf(
"Press ENTER to continue...\n");
705 #if METERPU_VERBOSE >= 1
715 #ifdef ENABLE_SYSTEM_ENERGY
727 #if METERPU_VERBOSE >= 1
761 virtual void start()=0;
767 virtual void stop()=0;
773 virtual void calc()=0;
803 #if METERPU_VERBOSE >= 1
808 #if METERPU_VERBOSE >= 1
816 #if METERPU_VERBOSE >= 1
823 #if METERPU_VERBOSE >= 1
840 std::cout<<
"[CPU Time Meter] Time consumed is "<<
get_value()<<
" micro seconds."<<std::endl;
845 #ifdef ENABLE_CUDA_TIME
871 #if METERPU_VERBOSE >= 1
882 std::cout<<
"[CUDA Time Meter] Time consumed is "<<
get_value()<<
" micro seconds."<<std::endl;
909 #if METERPU_VERBOSE >= 1
915 #if METERPU_VERBOSE >= 1
924 #if METERPU_VERBOSE >= 2
938 std::cout<<
"[CPU and DRAM Energy Meter] Energy consumed is: "<<
get_value()<<
" milli Joules."<<std::endl;
950 if(
pcm->program() != PCM::Success)
958 #if METERPU_VERBOSE >= 1
981 template<GPU_Device_Id_Type device_
id_NVML_Energy_Measurement_Controller>
1002 template<GPU_Device_Id_Type device_
id_value=device_
id_NVML_Energy_Measurement_Controller>
1032 nvmlReturn_t result;
1037 if (NVML_SUCCESS != result)
1039 printf(
"Failed to get handle for device %i: %s\n",
1044 #if METERPU_VERBOSE >= 1
1073 #if METERPU_VERBOSE >= 1
1088 #if METERPU_VERBOSE >= 1
1097 #if METERPU_VERBOSE >= 3
1105 #if METERPU_VERBOSE >= 1
1109 #ifdef DEBUG_OPERATOR_MINUS
1133 #ifdef METERPU_DUMP_DATA_FILE
1158 #ifdef METERPU_DUMP_DATA_FILE
1176 #if defined(METERPU_TEST)
1184 bool test_enable[]={0,0,0,0,0,1};
1199 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1200 std::cout<<
"Test calc: 0 sample..."<<std::endl;
1202 std::cout<<
"Expected: "<<0<<std::endl;
1203 std::cout<<
"Calculated: "<<
get_value()<<std::endl;
1204 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1224 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1225 std::cout<<
"Test calc: 1 sample..."<<std::endl;
1227 std::cout<<
"Expected: "<<200<<std::endl;
1228 std::cout<<
"Calculated: "<<
get_value()<<std::endl;
1229 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1253 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1254 std::cout<<
"Test calc: 2 sample..."<<std::endl;
1256 std::cout<<
"Expected: "<<300<<std::endl;
1257 std::cout<<
"Calculated: "<<
get_value()<<std::endl;
1258 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1287 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1288 std::cout<<
"Test calc: 3 sample..."<<std::endl;
1290 std::cout<<
"Expected: "<<400<<std::endl;
1291 std::cout<<
"Calculated: "<<
get_value()<<std::endl;
1292 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1334 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1335 std::cout<<
"Test calc: 3 samples with 3 noises..."<<std::endl;
1337 std::cout<<
"Expected: "<<400<<std::endl;
1338 std::cout<<
"Calculated: "<<
get_value()<<std::endl;
1339 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1420 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1421 std::cout<<
"Test calc: 10 samples, more realistic scenarios ..."<<std::endl;
1423 std::cout<<
"Expected: NA, check the database directly, if power changes drastically instead of gradually."<<std::endl;
1424 std::cout<<
"Calculated: "<<
get_value()<<std::endl;
1425 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1436 std::vector<std::string> bash_results;
1437 if(!
bash_exe(
"date +%F-%H-%M-%S", bash_results) ) {std::cout<<
"Command date not executes!"<<std::endl;exit(1);}
1439 path+=*bash_results.begin();
1440 if ( system( (
"mkdir "+
path).c_str() ) ) {std::cout<<
"Command mkdir not executes!"<<std::endl;exit(1);}
1443 std::ofstream out( (
path+
"/time_event.csv").c_str() );
1444 if(!out){ std::cout<<
"file not open!"<<std::endl;exit(1); }
1445 out<<
"start_time_us,end_time_us"<<std::endl;
1449 template <
class T1,
class T2>
1450 void dumpTwoVectors(
const std::string &filename,
const std::string &header,
const T1 &keys,
const T2 &values )
const {
1451 assert(keys.size() == values.size());
1452 std::ofstream out( filename.c_str() );
1453 if(!out){ std::cout<<
"file not open!"<<std::endl;exit(1); }
1454 out<<header<<std::endl;
1456 typename T1::const_iterator it_keys;
1457 typename T2::const_iterator it_values;
1459 it_keys=keys.begin();
1460 it_values=values.begin();
1462 for(;it_keys!=keys.end();++it_keys,++it_values) {
1463 out<<*it_keys<<
","<<*it_values<<std::endl;
1476 #ifdef METERPU_DEBUG_NVML_CALC
1477 std::cout<<
"original databases: "<<std::endl;
1480 std::cout<<std::endl;
1491 nonRedundantSampleFlag[0]=1;
1498 if( *it - *(it-1) >= time_distance_us ){
1499 nonRedundantSampleFlag[index]=1;
1514 while( index<nonRedundantSampleFlag.size() ) {
1515 if(nonRedundantSampleFlag[index]){
1527 #ifdef METERPU_DEBUG_NVML_CALC
1528 std::cout<<
"After remove redundant samples"<<std::endl;
1531 std::cout<<std::endl;
1544 const float C = 0.84f;
1549 int index_placeholder=2, index=1;
1553 #ifdef NEVER_DEFINE_IT_UNTIL_YOU_REALLY_WANT
1570 ++index_placeholder;
1583 #ifdef METERPU_DEBUG_NVML_CALC
1584 std::cout<<
"After correcting power samples"<<std::endl;
1588 std::cout<<std::endl;
1613 #ifdef METERPU_DEBUG_NVML_CALC
1614 std::cout<<
"After filling values at start and end"<<std::endl;
1617 std::cout<<std::endl;
1627 #if METERPU_VERBOSE >= 2 || defined(DEBUG_OPERATOR_MINUS)
1639 #if METERPU_VERBOSE >= 2 || defined(DEBUG_OPERATOR_MINUS)
1643 assert(power_db.size()==time_db.size());
1646 for(;power_iter!=power_db.end()-1;)
1654 return totalArea/1000000.0f;
1665 #if METERPU_VERBOSE >= 2 || defined(DEBUG_OPERATOR_MINUS)
1671 #ifdef TEST_ENERGY_CAL
1672 std::cout<<(l*r+(h-l)*r/2)/1000000.0f<<std::endl;
1674 return l*r+(h-l)*r/2;
1713 #if METERPU_VERBOSE >= 1
1724 nvmlReturn_t return_code;
1725 #if METERPU_VERBOSE >= 2
1729 while(*sampling_local)
1733 return_code = nvmlDeviceGetPowerUsage( device_local, power_local );
1734 if ( return_code != NVML_SUCCESS) {
1739 #if METERPU_VERBOSE >= 4
1744 power_db_local->push_back(*power_local);
1745 time_db_local->push_back(*time_local);
1748 #if METERPU_VERBOSE >= 2
1755 pthread_exit((
void*) arg);
1764 pthread_attr_init(&
attr);
1765 pthread_attr_setdetachstate(&
attr, PTHREAD_CREATE_JOINABLE);
1770 #if METERPU_VERBOSE >= 2
1776 #if METERPU_VERBOSE >= 1
1780 printf(
"ERROR; return code from pthread_create() is %d\n", rc);
1792 rc = pthread_join(
thread, &status);
1794 printf(
"ERROR; return code from pthread_join() is %d\n", rc);
1797 pthread_attr_destroy(&
attr);
1799 #if METERPU_VERBOSE >= 1
1822 #if METERPU_VERBOSE >= 1
1860 #ifdef ENABLE_NVML_OLD
1861 template<GPU_Device_Id_Type device_
id_NVML_Energy_Measurement_Controller>
1874 template<GPU_Device_Id_Type device_
id_value=device_
id_NVML_Energy_Measurement_Controller>
1875 struct NVML_Energy_Device_Init
1904 nvmlReturn_t result;
1909 if (NVML_SUCCESS != result)
1911 printf(
"Failed to get handle for device %i: %s\n",
1916 #if METERPU_VERBOSE >= 1
1929 NVML_Energy<>::Time_Unit execution_stop_time;
1949 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1950 std::cout<<
"Test operator overloading..."<<std::endl;
1951 std::cout<<
"Expected: "<<1e6<<std::endl;
1952 std::cout<<
"Calculated: "<<stop_time-start_time<<std::endl;
1953 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1958 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1959 std::cout<<
"Test calAreaForOneTrapezoid()..."<<std::endl;
1960 std::cout<<
"Expected: "<<1.5<<std::endl;
1962 std::cout<<
"Expected: "<<1.5<<std::endl;
1964 std::cout<<
"Expected: "<<1<<std::endl;
1966 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1969 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1970 std::cout<<
"Test calTotalArea()..."<<std::endl;
1971 NVML_Energy<>::Power_DB_Type power_db;
1972 power_db.push_back(1);
1973 power_db.push_back(2);
1974 power_db.push_back(3);
1976 NVML_Energy<>::Time_DB_Type time_db;
1977 time_db.push_back(start_time);
1978 time_db.push_back(stop_time);
1979 time_db.push_back(compensation_end);
1981 std::cout<<
"Expected: "<<4<<std::endl;
1982 std::cout<<
"Calculated: "<<
calTotalArea(power_db,time_db)<<std::endl;
1983 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1987 std::cout<<
"-----------------------------------------------------------"<<std::endl;
1988 std::cout<<
"Test energy calculation by"
1989 <<
" calTotalArea(), calCompensatedStaticEnergy() and calStaticEnergy()..."<<std::endl;
1990 std::cout<<
"Expected: "<<3<<std::endl;
1991 std::cout<<
"Calculated: "
1992 <<
calTotalArea(power_db,time_db)-calCompensatedStaticEnergy(stop_time,compensation_end,1)<<std::endl;
1993 std::cout<<
"Expected: "<<2<<std::endl;
1994 std::cout<<
"Calculated: "
1995 <<
calTotalArea(power_db,time_db)-calCompensatedStaticEnergy(stop_time,compensation_end,1)-calStaticEnergy(start_time,stop_time,1)<<std::endl;
1996 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
1999 std::cout<<
"-----------------------------------------------------------"<<std::endl;
2000 std::cout<<
"Test time unit comparison"<<std::endl;
2001 std::cout<<std::boolalpha;
2004 small.tv_sec=1;small.tv_nsec=2;
2005 large.tv_sec=1;large.tv_nsec=2;
2006 std::cout<<
"1 Expected: equal true"<<std::endl;
2007 std::cout<<
"1 Calculated: "<<(small==large)<<std::endl;
2008 std::cout<<
"2 Expected: small and equal true"<<std::endl;
2009 std::cout<<
"2 Calculated: "<<(small<=large)<<std::endl;
2011 small.tv_sec=2;small.tv_nsec=2;
2012 large.tv_sec=3;large.tv_nsec=2;
2013 std::cout<<
"3 Expected: small true"<<std::endl;
2014 std::cout<<
"3 Calculated: "<<(small<large)<<std::endl;
2015 std::cout<<
"4 Expected: small and equal true"<<std::endl;
2016 std::cout<<
"4 Calculated: "<<(small<=large)<<std::endl;
2018 small.tv_sec=1;small.tv_nsec=1;
2019 large.tv_sec=1;large.tv_nsec=2;
2020 std::cout<<
"5 Expected: small true"<<std::endl;
2021 std::cout<<
"5 Calculated: "<<(small<large)<<std::endl;
2022 std::cout<<
"6 Expected: small and equal true"<<std::endl;
2023 std::cout<<
"6 Calculated: "<<(small<=large)<<std::endl;
2025 small.tv_sec=0;small.tv_nsec=4;
2026 large.tv_sec=1;large.tv_nsec=2;
2027 std::cout<<
"7 Expected: small true"<<std::endl;
2028 std::cout<<
"7 Calculated: "<<(small<large)<<std::endl;
2029 std::cout<<
"8 Expected: small and equal true"<<std::endl;
2030 std::cout<<
"8 Calculated: "<<(small<=large)<<std::endl;
2032 small.tv_sec=2;small.tv_nsec=1;
2033 large.tv_sec=1;large.tv_nsec=2;
2034 std::cout<<
"9 Expected: small false"<<std::endl;
2035 std::cout<<
"9 Calculated: "<<(small<large)<<std::endl;
2036 std::cout<<
"10 Expected: small and equal false"<<std::endl;
2037 std::cout<<
"10 Calculated: "<<(small<=large)<<std::endl;
2038 std::cout<<
"-----------------------------------------------------------"<<std::endl<<std::endl;
2050 #if METERPU_VERBOSE >= 1
2057 sampling_static_power();
2067 #if METERPU_VERBOSE >= 1
2071 #if METERPU_VERBOSE >= 2
2077 #if METERPU_VERBOSE >= 2
2081 typename NVML_Energy<>::Hp_Power_Unit power_threshold
2083 (static_power_value*1.05f);
2087 #if METERPU_VERBOSE >= 3
2091 #if METERPU_VERBOSE >= 2
2100 #if METERPU_VERBOSE >= 3
2109 #if METERPU_VERBOSE >= 1
2113 #ifdef DEBUG_OPERATOR_MINUS
2144 std::cout<<
"Energy consumed is: "<<
get_value()<<
" milli Joules."<<std::endl;
2152 #if METERPU_VERBOSE >= 2 || defined(DEBUG_OPERATOR_MINUS)
2161 NVML_Energy<>::Power_DB_Type
const &power_db,
2162 NVML_Energy<>::Time_DB_Type
const &time_db
2165 #if METERPU_VERBOSE >= 2 || defined(DEBUG_OPERATOR_MINUS)
2168 NVML_Energy<>::Energy_Unit totalArea=0;
2170 assert(power_db.size()==time_db.size());
2171 NVML_Energy<>::Power_DB_Type::const_iterator power_iter=power_db.begin();
2172 NVML_Energy<>::Time_DB_Type::const_iterator time_iter=time_db.begin();
2173 for(;power_iter!=power_db.end()-1;)
2181 return totalArea/1000000.0f;
2187 NVML_Energy<>::Time_Unit start_time,
2188 NVML_Energy<>::Time_Unit end_time,
2189 NVML_Energy<>::Power_Unit start_power,
2190 NVML_Energy<>::Power_Unit end_power
2193 #if METERPU_VERBOSE >= 2 || defined(DEBUG_OPERATOR_MINUS)
2196 NVML_Energy<>::Power_Unit h=(start_power>end_power?start_power:end_power);
2197 NVML_Energy<>::Power_Unit l=(start_power<=end_power?start_power:end_power);
2199 #ifdef TEST_ENERGY_CAL
2201 std::cout<<(l*r+(h-l)*r/2)/1000000.0f<<std::endl;
2203 return l*r+(h-l)*r/2;
2209 NVML_Energy<>::Energy_Unit calCompensatedStaticEnergy()
2211 #if METERPU_VERBOSE >= 2 || defined(DEBUG_OPERATOR_MINUS)
2220 NVML_Energy<>::Energy_Unit calCompensatedStaticEnergy(
2221 NVML_Energy<>::Time_Unit execution_end,
2222 NVML_Energy<>::Time_Unit compensation_end,
2223 NVML_Energy<>::Power_Unit static_power_value
2226 CPU_Time::ResultType compensation_period=(execution_end<compensation_end?compensation_end-execution_end:0);
2227 #if METERPU_VERBOSE>=2 || defined TEST_ENERGY_CAL || defined DEBUG_OPERATOR_MINUS
2233 assert(compensation_period>=0);
2234 return (compensation_period)*static_power_value/1000000.0f;
2239 NVML_Energy<>::Energy_Unit calStaticEnergy()
2246 NVML_Energy<>::Energy_Unit calStaticEnergy(
2247 NVML_Energy<>::Time_Unit execution_start,
2248 NVML_Energy<>::Time_Unit execution_end,
2249 NVML_Energy<>::Power_Unit static_power_value
2252 return (execution_end-execution_start)*static_power_value/1000000.0f;
2256 void sampling_static_power(){
2258 nvmlReturn_t return_code;
2260 static_power_value=0;
2261 int valid_power_sampling_count=0;
2262 const int num_of_samples=10;
2264 for(
int i=0;i<num_of_samples;++i){
2266 return_code = nvmlDeviceGetPowerUsage(
device, &power );
2267 if ( return_code != NVML_SUCCESS) {
2268 #if METERPU_VERBOSE >= 3
2275 #if METERPU_VERBOSE >= 3
2279 valid_power_sampling_count++;
2280 static_power_value+=power;
2282 #if METERPU_VERBOSE >= 2 || defined TEST_ENERGY_CAL
2286 static_power_value=static_power_value/valid_power_sampling_count;
2287 #if METERPU_VERBOSE >= 2
2288 std::cout<<std::setprecision(10)<<
"sampling_static_power(): final static power("<<static_power_value<<
")\n";
2295 NVML_Energy<>::Hp_Power_Unit static_power_value;
2296 NVML_Energy<>::Power_Unit power;
2332 class Sampling_Thread_Controller
2333 :
public Measurement_Controller
2353 NVML_Energy<>::Power_Unit
power;
2358 NVML_Energy<>::Time_Unit
time;
2363 NVML_Energy<>::Time_DB_Type
time_db;
2364 NVML_Energy<>::Power_DB_Type
power_db;
2367 #if METERPU_VERBOSE >= 1
2378 nvmlReturn_t return_code;
2379 #if METERPU_VERBOSE >= 2
2383 while(*sampling_local)
2387 return_code = nvmlDeviceGetPowerUsage( device_local, power_local );
2388 if ( return_code != NVML_SUCCESS) {
2400 #if METERPU_VERBOSE >= 4
2406 power_db_local->push_back(*power_local);
2407 time_db_local->push_back(*time_local);
2410 #if METERPU_VERBOSE >= 2
2411 NVML_Energy<>::Time_DB_Type::iterator it=time_db_local->end();
2417 pthread_exit((
void*) arg);
2420 pthread_attr_t
attr;
2444 pthread_attr_init(&
attr);
2445 pthread_attr_setdetachstate(&
attr, PTHREAD_CREATE_JOINABLE);
2450 #if METERPU_VERBOSE >= 2
2456 #if METERPU_VERBOSE >= 1
2460 printf(
"ERROR; return code from pthread_create() is %d\n", rc);
2472 rc = pthread_join(
thread, &status);
2474 printf(
"ERROR; return code from pthread_join() is %d\n", rc);
2477 pthread_attr_destroy(&
attr);
2479 #if METERPU_VERBOSE >= 1
2481 NVML_Energy<>::Time_DB_Type::iterator it=time_db.end();
2482 CPU_Time_Measurement_Controller temp(*time_db.begin(),*--it);
2494 <<power_db.size()/temp.get_value()
2502 #if METERPU_VERBOSE >= 1
2513 const NVML_Energy<>::Power_Unit &
get_power()
const {
return power;}
2517 assert(time_db.size()>=1);
2519 NVML_Energy<>::Time_DB_Type::iterator it=time_db.end();
2523 assert(time_db.size()>=1);
2527 return *time_db.begin();
2529 void reset_state(){time_db.clear();power_db.clear();}
2539 #ifdef ENABLE_SYSTEM_ENERGY
2550 #define POINTER ((Meter<NVML_Energy<first_device_id> >*)x[array_index])
2560 #define LOOPER(name, return_type, base_code, general_code) \
2561 template <GPU_Device_Id_Type ...default_case> \
2562 struct name { static return_type apply(void *x[]) { base_code } }; \
2563 template <GPU_Device_Id_Type array_index, \
2564 GPU_Device_Id_Type first_device_id, \
2565 GPU_Device_Id_Type ...rest> \
2566 struct name <array_index,first_device_id, rest...> \
2568 static return_type apply(void *x[]) \
2571 name <array_index+1,rest...>::apply(x); \
2582 struct System_Energy_Measurement_Controller :
public Measurement_Controller
2586 LOOPER(GPU_Meter_Constructor,
void,
NOTHING, x[array_index]=
new Meter<NVML_Energy<first_device_id> >;)
2591 LOOPER(GPU_Meter_Get_Meter_Reading, NVML_Energy<>::ResultType,
return 0;,
return POINTER->get_value()+)
2595 enum{
N=
sizeof...(gpu_device_ids)};
2600 GPU_Meter_Constructor<0,gpu_device_ids...>::apply(gpu_meters);
2603 GPU_Meter_Destructor<0,gpu_device_ids...>::apply(gpu_meters);
2607 GPU_Meter_Start<0,gpu_device_ids...>::apply(gpu_meters);
2612 GPU_Meter_Stop<0,gpu_device_ids...>::apply(gpu_meters);
2618 GPU_Meter_Cal<0,gpu_device_ids...>::apply(gpu_meters);
2620 + GPU_Meter_Get_Meter_Reading<0,gpu_device_ids...>::apply(gpu_meters)
void stop()
mark the end of a measurement phase/period.
Definition: MeterPU.h:914
PCM_Energy::DRAM_Energy_Type dram_energy
Definition: MeterPU.h:945
const CPU_Time::Time_Unit & get_start_time() const
Definition: MeterPU.h:1060
void init()
Definition: MeterPU.h:605
PCM_Energy::ResultType const & get_dram_energy() const
Definition: MeterPU.h:941
std::string path
Definition: MeterPU.h:1433
const NVML_Energy::Power_Unit & get_power() const
Definition: MeterPU.h:1832
GPU_Device_Id_Type device_id
Device id.
Definition: MeterPU.h:1012
bool sampling
Definition: MeterPU.h:1690
void * gpu_meters[N]
Definition: MeterPU.h:2596
void dumpOriginalPowerData() const
Definition: MeterPU.h:1467
Definition: MeterPU.h:511
void dumpTimeEvent()
Definition: MeterPU.h:1442
void stop()
mark the end of a measurement phase/period.
Definition: MeterPU.h:1784
nvmlDevice_t device
Device handle.
Definition: MeterPU.h:1017
void start()
mark the start of a measurement phase/period.
Definition: MeterPU.h:875
CPU_Time::ResultType meter_reading
Definition: MeterPU.h:799
CPU_Time::ResultType diff()
Definition: MeterPU.h:1068
NVML_Energy::Hp_Power_DB_Type correctedPowerDB
Definition: MeterPU.h:1536
DECLARE_CLASS_NAME("CPU_Time_Environment_Init")
Meter_Traits< Type >::ResultType const & get_value() const
Get calculated metric value, require calc() to be called already.
Definition: MeterPU.h:251
Sampling_Thread_Controller()
Definition: MeterPU.h:1686
nvmlDevice_t device
Device handle.
Definition: MeterPU.h:1695
Cuda Timer Traits.
Definition: MeterPU.h:404
void start()
mark the start of a measurement phase/period.
Definition: MeterPU.h:807
#define PRINT_FUNC_NAME_CONT
Definition: MeterPU.h:88
DECLARE_CLASS_NAME("Sampling_Thread_Controller")
std::vector< Power_Unit > Power_DB_Type
Definition: MeterPU.h:456
nvmlDevice_t device
Definition: MeterPU.h:1056
PCM_Energy::ResultType const & get_cpu_energy() const
Definition: MeterPU.h:940
NVML_Energy::Power_Unit power
Power value for each sample.
Definition: MeterPU.h:1700
NVML_Energy::Time_Unit const & get_start_time()
Definition: MeterPU.h:1844
DECLARE_CLASS_NAME("CUDA_Time_Environment_Init")
double ResultType
Definition: MeterPU.h:420
void show_meter_reading() const
Print the calculated metric value to standard output, requires an invocation of calc() already done...
Definition: MeterPU.h:2630
long double Hp_Power_Unit
High precision power unit.
Definition: MeterPU.h:453
Sampling Thread Controller.
Definition: MeterPU.h:1681
SystemCounterState after_sstate
Definition: MeterPU.h:965
cudaEvent_t start_time
Definition: MeterPU.h:855
void init()
Definition: MeterPU.h:2605
#define PRINT_CLASS_FUNC_NAME_CONT
Definition: MeterPU.h:92
CPU and DRAME Energy Measurement Controller.
Definition: MeterPU.h:901
std::vector< Hp_Power_Unit > Hp_Power_DB_Type
Definition: MeterPU.h:457
Type::Measurement_Controller Measurement_Controller
Measurement Controller Object.
Definition: MeterPU.h:319
PCM Energy Traits.
Definition: MeterPU.h:417
CUDA-enabled GPU Time Measurement Controller.
Definition: MeterPU.h:851
void init()
Definition: MeterPU.h:584
void init()
Definition: MeterPU.h:668
void show_meter_reading() const
Print the calculated metric value to standard output, requires an invocation of calc() already done...
Definition: MeterPU.h:839
CPU_Time::Time_Unit start_time
Definition: MeterPU.h:1058
virtual void calc()=0
calculate the metric value between start() and stop().
CPU_Time::Time_Unit stop_time
Definition: MeterPU.h:798
CPU_Time::Time_Unit start_time
Definition: MeterPU.h:797
NVML_Energy::Time_DB_Type Data_Type
Definition: MeterPU.h:521
virtual void start()=0
mark the start of a measurement phase/period.
CPU_Time::ResultType operator-(CPU_Time::Time_Unit const &stop_time, CPU_Time::Time_Unit const &start_time)
Calculate elapsed time between two time stamp.
Definition: MeterPU.h:347
void init()
Definition: MeterPU.h:726
NVML_Energy::Energy_Unit calAreaForOneTrapezoid(NVML_Energy<>::Time_Unit start_time, NVML_Energy<>::Time_Unit end_time, NVML_Energy<>::Hp_Power_Unit start_power, NVML_Energy<>::Hp_Power_Unit end_power)
Definition: MeterPU.h:1657
void stop()
mark the end of a measurement phase/period.
Definition: MeterPU.h:1085
PCM_Energy_Measurement_Controller Measurement_Controller
Definition: MeterPU.h:421
void start()
mark the start of a measurement phase/period.
Definition: MeterPU.h:1760
#define PRINT_CLASS_FUNC_NAME(message)
Definition: MeterPU.h:91
DECLARE_CLASS_NAME("PCM_Energy_Environment_Init")
CUDA_Time::ResultType const & get_value() const
Get calculated metric value, require calc() to be called already.
Definition: MeterPU.h:890
DECLARE_CLASS_NAME("NVML_Energy_Measurement_Controller")
NVML_Energy::Power_DB_Type Data_Type
Definition: MeterPU.h:507
DECLARE_CLASS_NAME("CPU_Time_Measurement_Controller")
struct timespec Time_Unit
Time stamp unit.
Definition: MeterPU.h:337
void show_meter_reading()
Write measurement value on standard output with its unit.
Definition: MeterPU.h:258
NVML_Energy::Energy_Unit get_value() const
Get calculated metric value, require calc() to be called already.
Definition: MeterPU.h:1173
void calc()
calculate the metric value between start() and stop().
Definition: MeterPU.h:1103
PCM_Energy::ResultType meter_reading
Definition: MeterPU.h:943
NVML_Energy::Power_DB_Const_Iterator_Type Const_Iterator_Type
Definition: MeterPU.h:508
double CPU_Energy_Type
Definition: MeterPU.h:423
NVML_Manager()
Definition: MeterPU.h:649
NVML_Energy::Hp_Power_DB_Type Data_Type
Definition: MeterPU.h:514
CPU_Time_Measurement_Controller Measurement_Controller
Definition: MeterPU.h:331
NVML_Energy_Device_Init()
Definition: MeterPU.h:1022
~PCM_Energy_Measurement_Controller()
Definition: MeterPU.h:957
void set_device(const nvmlDevice_t &device_handle)
Definition: MeterPU.h:1831
unsigned int Power_Unit
Definition: MeterPU.h:448
double ResultType
Definition: MeterPU.h:330
CUDA_Time_Measurement_Controller Measurement_Controller
Definition: MeterPU.h:408
void start()
mark the start of a measurement phase/period.
Definition: MeterPU.h:908
void teardown()
Definition: MeterPU.h:690
void init()
Definition: MeterPU.h:869
void correctPowerSamplesByBurtscherApproach()
Definition: MeterPU.h:1537
#define METERPU_TIME_MEASURE(x)
Definition: MeterPU.h:126
void calc()
calculate the metric value between start() and stop().
Definition: MeterPU.h:877
System_Energy_Measurement_Controller< gpu_ids...> Measurement_Controller
Definition: MeterPU.h:474
CUDA_Time_Measurement_Controller()
Definition: MeterPU.h:859
NVML_Energy_Environment_Init Environment_Init_Type
Definition: MeterPU.h:442
Power_DB_Type::const_iterator Power_DB_Const_Iterator_Type
Definition: MeterPU.h:458
void calc()
calculate the metric value between start() and stop().
Definition: MeterPU.h:920
static std::string header_message()
Definition: MeterPU.h:490
#define POINTER
A macro for downcast a void pointer to a NVML Energy Meter.
Definition: MeterPU.h:2550
DECLARE_CLASS_NAME("PCM_Energy_Measurement_Controller")
Time_DB_Type::const_iterator Time_DB_Const_Iterator_Type
Definition: MeterPU.h:455
void init()
Definition: MeterPU.h:623
DECLARE_CLASS_NAME("PCM_Energy_Environment_Init")
static std::string header_message()
Definition: MeterPU.h:520
void init()
Definition: MeterPU.h:801
bool bash_exe(const std::string &cmd, std::vector< std::string > &out)
Definition: MeterPU.h:132
static void * thread_program(void *arg)
Definition: MeterPU.h:1711
Time Traits.
Definition: MeterPU.h:327
void set_power_db(const NVML_Energy<>::Power_DB_Type &x)
Definition: MeterPU.h:1838
Meter< PCM_Energy > cpu_meter
Definition: MeterPU.h:2594
~NVML_Manager()
Definition: MeterPU.h:656
CUDA_Time::ResultType meter_reading
Definition: MeterPU.h:857
void init()
Definition: MeterPU.h:1030
NVML_Energy_Device_Init nvml_energy_device_init
Definition: MeterPU.h:1055
unsigned int GPU_Device_Id_Type
Definition: MeterPU.h:175
void set_time_db(const NVML_Energy<>::Time_DB_Type &x)
Definition: MeterPU.h:1837
NVML_Energy::Power_DB_Type & get_power_db_nonconst()
Definition: MeterPU.h:1835
cudaEvent_t stop_time
Definition: MeterPU.h:856
const CPU_Time::Time_Unit & get_stop_time() const
Definition: MeterPU.h:1061
Definition: MeterPU.h:518
Traits Interface.
Definition: MeterPU.h:165
CPU_Time_Measurement_Controller(CPU_Time::Time_Unit const &start_time_p, CPU_Time::Time_Unit const &stop_time_p)
Definition: MeterPU.h:792
NVML_Energy::Power_DB_Type power_db
Definition: MeterPU.h:1710
Type::Const_Iterator_Type Const_Iterator_Type
Definition: MeterPU.h:492
bool operator==(CPU_Time::Time_Unit const &small_time, CPU_Time::Time_Unit const &large_time)
Check if two time stamps are the same.
Definition: MeterPU.h:379
Sampling_Thread_Controller sampling_thread_controller
Definition: MeterPU.h:1852
void start()
mark the start of a measurement phase/period.
Definition: MeterPU.h:2606
System_Energy_Environment_Init Environment_Init_Type
Definition: MeterPU.h:473
CPU_Time::ResultType const & get_value() const
Get calculated metric value, require calc() to be called already.
Definition: MeterPU.h:835
void init()
Initialize a GPU device.
Definition: MeterPU.h:994
void show_meter_reading() const
Print the calculated metric value to standard output, requires an invocation of calc() already done...
Definition: MeterPU.h:1174
void init()
Definition: MeterPU.h:907
Meter_Traits< Type >::ResultType meter_reading
The variable used to store the calculated.
Definition: MeterPU.h:280
PCM_Energy::CPU_Energy_Type cpu_energy
Definition: MeterPU.h:944
CPU_Time_Environment_Init Environment_Init_Type
Definition: MeterPU.h:329
System_Energy_Measurement_Controller()
Definition: MeterPU.h:2599
PCM_Energy_Environment_Init Environment_Init_Type
Definition: MeterPU.h:419
Definition: MeterPU.h:488
bool operator<=(CPU_Time::Time_Unit const &small_time, CPU_Time::Time_Unit const &large_time)
Check if a time stamp is earlier or equal to another.
Definition: MeterPU.h:392
CPU_Time_Measurement_Controller()
Definition: MeterPU.h:791
Library Initializer Interface.
Definition: MeterPU.h:550
void calc()
calculate measurement value
Definition: MeterPU.h:240
void init()
Definition: MeterPU.h:565
pthread_t thread
Definition: MeterPU.h:1757
void show_meter_reading() const
Print the calculated metric value to standard output, requires an invocation of calc() already done...
Definition: MeterPU.h:1830
const NVML_Energy::Power_DB_Type & get_power_db() const
Definition: MeterPU.h:1833
void fillPowerValuesAtStartAndEnd()
Definition: MeterPU.h:1592
NVML_Energy::Energy_Unit meter_reading
Definition: MeterPU.h:1057
Meter_Traits< Type >::Environment_Init_Type environment_init_object
Native library initializer.
Definition: MeterPU.h:268
GPU Energy Traits.
Definition: MeterPU.h:182
GPU Time Library Initializer.
Definition: MeterPU.h:578
void operator=(const NVML_Manager &)
void dumpCorrectedPowerData()
Definition: MeterPU.h:1470
Energy_Unit ResultType
Definition: MeterPU.h:443
void update_cpu_energy()
Definition: MeterPU.h:946
NVML_Energy::ResultType meter_reading
Definition: MeterPU.h:2597
void removeRedundantSamplesByDistance(const CPU_Time::ResultType &time_distance_ms)
Definition: MeterPU.h:1473
void update_dram_energy()
Definition: MeterPU.h:947
NVML_Energy::Energy_Unit calTotalArea(NVML_Energy<>::Hp_Power_DB_Type const &power_db, NVML_Energy<>::Time_DB_Type const &time_db)
Definition: MeterPU.h:1633
Type::Environment_Init_Type Environment_Init_Type
Object for initialization of a native measurement library.
Definition: MeterPU.h:309
void show_meter_reading() const
Print the calculated metric value to standard output, requires an invocation of calc() already done...
Definition: MeterPU.h:937
NVML_Energy::Hp_Power_DB_Const_Iterator_Type Const_Iterator_Type
Definition: MeterPU.h:515
~CUDA_Time_Measurement_Controller()
Definition: MeterPU.h:864
Type::ResultType ResultType
Result type.
Definition: MeterPU.h:314
void calc()
calculate the metric value between start() and stop().
Definition: MeterPU.h:1821
#define LOOPER(name, return_type, base_code, general_code)
A macro to build variadic template to recursively apply code snippets.
Definition: MeterPU.h:2560
Meter_Traits< Type >::Measurement_Controller measurement_controller_object
Measurement controller.
Definition: MeterPU.h:274
NVML_Energy::Energy_Unit calTotalArea()
Definition: MeterPU.h:1624
static std::string header_message()
Definition: MeterPU.h:506
CPU Time Library Initializer.
Definition: MeterPU.h:559
const NVML_Energy::Time_DB_Type & get_time_db() const
Definition: MeterPU.h:1834
System_Energy::ResultType const & get_value() const
Get calculated metric value, require calc() to be called already.
Definition: MeterPU.h:2629
Meter()
Definition: MeterPU.h:224
CPU Time Measurement Controller.
Definition: MeterPU.h:787
Definition: MeterPU.h:1003
void stop()
mark the end of a measurement phase/period.
Definition: MeterPU.h:815
float ResultType
Definition: MeterPU.h:407
System Energy Measurement Controller.
Definition: MeterPU.h:198
PCM * pcm
Definition: MeterPU.h:963
CUDA_Time_Environment_Init Environment_Init_Type
Definition: MeterPU.h:406
virtual void stop()=0
mark the end of a measurement phase/period.
void calc()
calculate the metric value between start() and stop().
Definition: MeterPU.h:2614
double ResultType
Definition: MeterPU.h:475
void start()
start a measurement
Definition: MeterPU.h:232
SystemCounterState before_sstate
Definition: MeterPU.h:964
void record_start_time()
Definition: MeterPU.h:1062
void calc()
calculate the metric value between start() and stop().
Definition: MeterPU.h:822
CPU_Time::Time_Unit stop_time
Definition: MeterPU.h:1059
GPU Energy Library Initializer.
Definition: MeterPU.h:619
NVML_Energy::Time_Unit time
Time value for each sample.
Definition: MeterPU.h:1704
double DRAM_Energy_Type
Definition: MeterPU.h:424
#define NOTHING
Definition: MeterPU.h:2552
CUDA-enabled GPU Energy Measurement Controller.
Definition: MeterPU.h:184
System Energy Library Initializer.
Definition: MeterPU.h:720
void stop()
mark the end of a measurement phase/period.
Definition: MeterPU.h:876
Measurement Controller Interface.
Definition: MeterPU.h:754
NVML_Energy::Time_DB_Type & get_time_db_nonconst()
Definition: MeterPU.h:1836
PCM_Energy_Measurement_Controller()
Definition: MeterPU.h:949
Hp_Power_DB_Type::const_iterator Hp_Power_DB_Const_Iterator_Type
Definition: MeterPU.h:459
static std::string header_message()
Definition: MeterPU.h:513
The software multi-meters.
Definition: MeterPU.h:221
NVML library init and teardown.
Definition: MeterPU.h:630
Type::Data_Type Data_Type
Definition: MeterPU.h:491
void stop()
mark the end of a measurement phase/period.
Definition: MeterPU.h:2610
virtual void show_meter_reading() const =0
Print the calculated metric value to standard output, requires an invocation of calc() already done...
double Energy_Unit
Definition: MeterPU.h:440
NVML_Energy::Time_Unit const & get_stop_time()
Definition: MeterPU.h:1839
void set_device_id(GPU_Device_Id_Type id)
Definition: MeterPU.h:1026
pthread_attr_t attr
Definition: MeterPU.h:1758
void show_meter_reading() const
Print the calculated metric value to standard output, requires an invocation of calc() already done...
Definition: MeterPU.h:881
static NVML_Energy::Power_Unit get_UNREALISTIC_POWER_VALUE()
Definition: MeterPU.h:1689
void resetDir()
Definition: MeterPU.h:1434
NVML_Energy_Measurement_Controller< device_id > Measurement_Controller
Definition: MeterPU.h:444
Definition: MeterPU.h:2595
struct timespec Time_Unit
Definition: MeterPU.h:447
~System_Energy_Measurement_Controller()
Definition: MeterPU.h:2602
CPU Energy Library Initializer.
Definition: MeterPU.h:599
void dumpTwoVectors(const std::string &filename, const std::string &header, const T1 &keys, const T2 &values) const
Definition: MeterPU.h:1450
bool operator<(CPU_Time::Time_Unit const &small_time, CPU_Time::Time_Unit const &large_time)
Check if a time stamp is earlier than another.
Definition: MeterPU.h:364
void record_stop_time()
Definition: MeterPU.h:1065
NVML_Energy::Time_DB_Const_Iterator_Type Const_Iterator_Type
Definition: MeterPU.h:522
static void print(const Data_Type &a)
Definition: MeterPU.h:493
PCM_Energy::ResultType const & get_value() const
Get calculated metric value, require calc() to be called already.
Definition: MeterPU.h:936
#define DECLARE_CLASS_NAME(name)
Definition: MeterPU.h:90
Definition: MeterPU.h:504
void reset_state()
Definition: MeterPU.h:1848
NVML_Energy::Time_DB_Type time_db
Power data database.
Definition: MeterPU.h:1709
static void init_NVML()
Definition: MeterPU.h:639
std::vector< Time_Unit > Time_DB_Type
Definition: MeterPU.h:454
const nvmlDevice_t & get_device() const
Definition: MeterPU.h:1052
void start()
mark the start of a measurement phase/period.
Definition: MeterPU.h:1071
System Energy Traits.
Definition: MeterPU.h:196
void stop()
stop a measurement
Definition: MeterPU.h:236