Skip to content

Commit

Permalink
Only report energy consumption since first reading
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Jul 8, 2024
1 parent 22b4331 commit a29ea1f
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/variorum/Intel_GPU/intel_gpu_power_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
static unsigned m_total_unit_devices;
static unsigned m_gpus_per_socket;
static char m_hostname[1024];
static double *m_initial_energy_for_gpu;
static int *m_init_energy;

void initAPMIDG(void)
{
Expand All @@ -35,6 +37,16 @@ void initAPMIDG(void)
#endif
m_gpus_per_socket = m_total_unit_devices / m_num_package;

static int init = 0;
if (!init)
{
m_initial_energy_for_gpu = (double *) malloc(sizeof(double) *
m_total_unit_devices);
m_init_energy = (int *) calloc(m_num_package, sizeof(int));

init = 1;
}

/* Save hostname */
gethostname(m_hostname, sizeof(m_hostname));
}
Expand Down Expand Up @@ -302,7 +314,16 @@ void get_energy_data(int chipid, int verbose, FILE *output)
{
int pi = 0; // only report the global power domain
apmidg_readenergy(d, pi, &energy_uj, NULL);
value = (double)energy_uj * 1.e-6;
if (!m_init_energy[chipid])
{
m_initial_energy_for_gpu[d] = (double)energy_uj * 1.e-6;
value = 0;
}
else
{
value = (double)energy_uj * 1.e-6;
value -= m_initial_energy_for_gpu[d];
}

if (verbose)
{
Expand Down Expand Up @@ -336,6 +357,7 @@ void get_energy_data(int chipid, int verbose, FILE *output)
#endif
}
}
m_init_energy[chipid] = 1;
}

void get_energy_json(int chipid, json_t *get_energy_obj)
Expand Down Expand Up @@ -369,12 +391,23 @@ void get_energy_json(int chipid, json_t *get_energy_obj)
{
int pi = 0; // only report the global power domain
apmidg_readenergy(d, pi, &energy_uj, NULL);
value = (double)energy_uj * 1.e-6;
if (!m_init_energy[chipid])
{
m_initial_energy_for_gpu[d] = (double)energy_uj * 1.e-6;
value = 0;
}
else
{
value = (double)energy_uj * 1.e-6;
value -= m_initial_energy_for_gpu[d];
}
snprintf(devID, devIDlen, "GPU_%d", d);
json_object_set_new(gpu_obj, devID, json_real(value));
total_energy_gpu += value;
}

m_init_energy[chipid] = 1;

// If we have an existing CPU object with power_node_watts, update its value.
if (json_object_get(get_energy_obj, "energy_node_joules") != NULL)
{
Expand Down

0 comments on commit a29ea1f

Please sign in to comment.