|
@@ -33,11 +33,16 @@
|
|
|
|
|
|
#define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
|
|
|
|
|
|
+#if 1
|
|
|
+#define debug(fmt, ...) printf(fmt, ## __VA_ARGS)
|
|
|
+#else
|
|
|
+#define debug(fmt, ...)
|
|
|
+#endif
|
|
|
+
|
|
|
static const int N_EVTS = 2;
|
|
|
|
|
|
-static hwloc_topology_t topology;
|
|
|
+static int nsockets;
|
|
|
|
|
|
-static int nnuma;
|
|
|
static const char* event_names[] = { "rapl::RAPL_ENERGY_PKG:cpu=%d",
|
|
|
|
|
|
"rapl::RAPL_ENERGY_DRAM:cpu=%d"};
|
|
@@ -45,34 +50,23 @@ static const char* event_names[] = { "rapl::RAPL_ENERGY_PKG:cpu=%d",
|
|
|
static int add_event(int EventSet, int socket);
|
|
|
|
|
|
/*must be initialized to PAPI_NULL before calling PAPI_create_event*/
|
|
|
-static int EventSet = PAPI_NULL;
|
|
|
-static int tmp, i;
|
|
|
+int EventSet = PAPI_NULL;
|
|
|
|
|
|
/*This is where we store the values we read from the eventset */
|
|
|
static long long *values;
|
|
|
|
|
|
-
|
|
|
-static int retval, number;
|
|
|
-static int device_count;
|
|
|
-static char errstring[PAPI_MAX_STR_LEN];
|
|
|
-
|
|
|
|
|
|
int starpu_energy_start()
|
|
|
{
|
|
|
+ int retval, number;
|
|
|
+ int i;
|
|
|
|
|
|
- /* Allocate and initialize topology object. */
|
|
|
- hwloc_topology_init(&topology);
|
|
|
-
|
|
|
-
|
|
|
- /* Perform the topology detection. */
|
|
|
- hwloc_topology_load(topology);
|
|
|
-
|
|
|
- nnuma = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NUMANODE);
|
|
|
-
|
|
|
-
|
|
|
- printf("nbre de sockets %d \n",nnuma);
|
|
|
-
|
|
|
- values=calloc(nnuma * N_EVTS,sizeof(long long));
|
|
|
+ struct _starpu_machine_config *config = _starpu_get_machine_config();
|
|
|
+ hwloc_topology_t topology = config->topology.hwtopology;
|
|
|
+
|
|
|
+ nsockets = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PACKAGE);
|
|
|
+
|
|
|
+ values=calloc(nsockets * N_EVTS,sizeof(long long));
|
|
|
if (values==NULL) {
|
|
|
exit(1);
|
|
|
}
|
|
@@ -84,8 +78,12 @@ int starpu_energy_start()
|
|
|
if ( (retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
|
|
|
ERROR_RETURN(retval);
|
|
|
|
|
|
- for (i = 0 ; i < nnuma ; i ++ )
|
|
|
- add_event(EventSet, i);
|
|
|
+ for (i = 0 ; i < nsockets ; i ++ )
|
|
|
+{
|
|
|
+ /* return the index of socket */
|
|
|
+ hwloc_obj_t obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, i);
|
|
|
+ add_event(EventSet, obj->os_index);
|
|
|
+}
|
|
|
|
|
|
/* get the number of events in the event set */
|
|
|
number = 0;
|
|
@@ -93,21 +91,23 @@ int starpu_energy_start()
|
|
|
ERROR_RETURN(retval);
|
|
|
|
|
|
printf("There are %d events in the event set\n", number);
|
|
|
-
|
|
|
+
|
|
|
/* Start counting */
|
|
|
if ( (retval = PAPI_start(EventSet)) != PAPI_OK)
|
|
|
ERROR_RETURN(retval);
|
|
|
|
|
|
- /* Destroy topology object. */
|
|
|
- hwloc_topology_destroy(topology);
|
|
|
-
|
|
|
+
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
int starpu_energy_stop(struct starpu_perfmodel *model, struct starpu_task *task, unsigned ntasks)
|
|
|
{
|
|
|
- double energy;
|
|
|
+ double energy = 0.;
|
|
|
+
|
|
|
+ int retval;
|
|
|
+ unsigned workerid = 0;
|
|
|
+ unsigned cpuid = 0;
|
|
|
|
|
|
/* Stop counting and store the values into the array */
|
|
|
if ( (retval = PAPI_stop(EventSet, values)) != PAPI_OK)
|
|
@@ -115,26 +115,36 @@ int starpu_energy_stop(struct starpu_perfmodel *model, struct starpu_task *task,
|
|
|
|
|
|
int k,s;
|
|
|
|
|
|
- for( s = 0 ; s < nnuma ; s ++){
|
|
|
+ for( s = 0 ; s < nsockets ; s ++){
|
|
|
|
|
|
for(k = 0 ; k < N_EVTS; k++) {
|
|
|
|
|
|
- energy=values[s * N_EVTS + k]/ ntasks;
|
|
|
+ energy += values[s * N_EVTS + k];
|
|
|
+
|
|
|
printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
|
|
|
event_names[k],
|
|
|
(energy/1.0e9),
|
|
|
- (energy/1.0e9));
|
|
|
+ (energy/1.0e9) // FIXME: diviser par le temps en secondes (utiliser starpu_timing_now() qui retourne le temps en microsecondes
|
|
|
+);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- unsigned workerid = 0;
|
|
|
- unsigned cpuid = 0;
|
|
|
+ energy=energy / ntasks;
|
|
|
|
|
|
struct starpu_perfmodel_arch *arch = starpu_worker_get_perf_archtype(workerid, STARPU_NMAX_SCHED_CTXS);
|
|
|
starpu_perfmodel_update_history(model, task, arch, cpuid, 0, energy);
|
|
|
|
|
|
- /* free the resources used by PAPI */
|
|
|
+ /*emoves all events from a PAPI event set */
|
|
|
+ if ( (retval = PAPI_cleanup_eventset(EventSet)) != PAPI_OK)
|
|
|
+ ERROR_RETURN(retval);
|
|
|
+
|
|
|
+ /*deallocates the memory associated with an empty PAPI EventSet*/
|
|
|
+ if ( (retval = PAPI_destroy_eventset(&EventSet)) != PAPI_OK)
|
|
|
+ ERROR_RETURN(retval);
|
|
|
+
|
|
|
+ /* free the resources used by PAPI */
|
|
|
PAPI_shutdown();
|
|
|
|
|
|
return retval;
|