1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /*****************************************************************************
- * This example shows how to use PAPI_add_event, PAPI_start, PAPI_read, *
- * PAPI_stop and PAPI_remove_event. *
- ******************************************************************************/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <nvml.h>
- #include <cuda.h>
- #include <cuda_runtime.h>
- #define NUM_EVENTS 2
- #define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
- const char* event_names[] = { "rapl:::PACKAGE_ENERGY:PACKAGE0",
- "rapl:::DRAM_ENERGY:PACKAGE0"};
- int main()
- {
- #ifdef HAVE_LIBNVIDIA_ML
-
-
- int i, retval;
- /*This is where we store the values we read from the eventset */
-
- /* We use number to keep track of the number of events in the EventSet */
- //int deviceCount;
-
- /************************************************************/
- unsigned long long energy_begin, energy_end;
- nvmlDevice_t device;
-
- /*retval = nvmlDeviceGetCount_v2 ( & deviceCount ) ;
- if(retval != 0){
- printf("error getting nvml number of devices\n");
- exit (0);
- }*/
- //energy_begin = (long long*)malloc(device * sizeof(long long));
- //energy_end = (long long*)malloc(device * sizeof(long long));
- /************************************************************/
- retval = nvmlDeviceGetHandleByIndex_v2 (0, &device);
- retval = nvmlDeviceGetTotalEnergyConsumption ( device, &energy_begin );
-
- /* you can replace your code here */
-
- int j;
- for( i = 0; i < 2000000000; i++) { j += i;}
- sleep ( 10 );
-
-
- // retval = nvmlDeviceGetHandleByIndex_v2 (0, &device);
- retval = nvmlDeviceGetTotalEnergyConsumption ( device, &energy_end );
-
- //energy est caclule en mJ
- /***********************************************************/
- printf("energy consumptionnnnnnnnnn on device %d is %lld mJ \n", 0, (energy_end - energy_begin));
- /*********************************************************/
-
- #endif
-
- exit(0);
- }
|