papi.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifdef HAVE_LIBNVIDIA_ML
  18. int i, retval;
  19. /*This is where we store the values we read from the eventset */
  20. /* We use number to keep track of the number of events in the EventSet */
  21. //int deviceCount;
  22. /************************************************************/
  23. unsigned long long energy_begin, energy_end;
  24. nvmlDevice_t device;
  25. /*retval = nvmlDeviceGetCount_v2 ( & deviceCount ) ;
  26. if(retval != 0){
  27. printf("error getting nvml number of devices\n");
  28. exit (0);
  29. }*/
  30. //energy_begin = (long long*)malloc(device * sizeof(long long));
  31. //energy_end = (long long*)malloc(device * sizeof(long long));
  32. /************************************************************/
  33. retval = nvmlDeviceGetHandleByIndex_v2 (0, &device);
  34. retval = nvmlDeviceGetTotalEnergyConsumption ( device, &energy_begin );
  35. /* you can replace your code here */
  36. int j;
  37. for( i = 0; i < 2000000000; i++) { j += i;}
  38. sleep ( 10 );
  39. // retval = nvmlDeviceGetHandleByIndex_v2 (0, &device);
  40. retval = nvmlDeviceGetTotalEnergyConsumption ( device, &energy_end );
  41. //energy est caclule en mJ
  42. /***********************************************************/
  43. printf("energy consumptionnnnnnnnnn on device %d is %lld mJ \n", 0, (energy_end - energy_begin));
  44. /*********************************************************/
  45. #endif
  46. exit(0);
  47. }