papi.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*****************************************************************************
  2. * This example shows how to use PAPI_add_event, PAPI_start, PAPI_read, *
  3. * PAPI_stop and PAPI_remove_event. *
  4. ******************************************************************************/
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <nvml.h>
  9. #include <cuda.h>
  10. #include <cuda_runtime.h>
  11. #define NUM_EVENTS 2
  12. #define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
  13. const char* event_names[] = { "rapl:::PACKAGE_ENERGY:PACKAGE0",
  14. "rapl:::DRAM_ENERGY:PACKAGE0"};
  15. int main()
  16. {
  17. int i, retval;
  18. /*This is where we store the values we read from the eventset */
  19. /* We use number to keep track of the number of events in the EventSet */
  20. //int deviceCount;
  21. /************************************************************/
  22. unsigned long long energy_begin, energy_end;
  23. nvmlDevice_t device;
  24. /*retval = nvmlDeviceGetCount_v2 ( & deviceCount ) ;
  25. if(retval != 0){
  26. printf("error getting nvml number of devices\n");
  27. exit (0);
  28. }*/
  29. //energy_begin = (long long*)malloc(device * sizeof(long long));
  30. //energy_end = (long long*)malloc(device * sizeof(long long));
  31. /************************************************************/
  32. retval = nvmlDeviceGetHandleByIndex_v2 (0, &device);
  33. retval = nvmlDeviceGetTotalEnergyConsumption ( device, &energy_begin );
  34. /* you can replace your code here */
  35. int j;
  36. for( i = 0; i < 2000000000; i++) { j += i;}
  37. sleep ( 10 );
  38. // retval = nvmlDeviceGetHandleByIndex_v2 (0, &device);
  39. retval = nvmlDeviceGetTotalEnergyConsumption ( device, &energy_end );
  40. //energy est caclule en mJ
  41. /***********************************************************/
  42. printf("energy consumptionnnnnnnnnn on device %d is %lld mJ \n", 0, (energy_end - energy_begin));
  43. /*********************************************************/
  44. exit(0);
  45. }