Explorar o código

Fix measuring energy consumption on V100

Samuel Thibault %!s(int64=7) %!d(string=hai) anos
pai
achega
d5ea43ff1a
Modificáronse 1 ficheiros con 18 adicións e 15 borrados
  1. 18 15
      src/drivers/cuda/driver_cuda.c

+ 18 - 15
src/drivers/cuda/driver_cuda.c

@@ -534,27 +534,15 @@ static int start_job_on_cuda(struct _starpu_job *j, struct _starpu_worker *worke
 #ifdef HAVE_LIBNVIDIA_ML
 		unsigned long long energy_start = 0;
 		nvmlReturn_t nvmlRet = -1;
-		if (profiling || (cl->energy_model && cl->energy_model->benchmarking))
+		if (profiling)
 		{
 			nvmlRet = nvmlDeviceGetTotalEnergyConsumption(nvmlDev[worker->devid], &energy_start);
+			if (nvmlRet == NVML_SUCCESS)
+				task->profiling_info->energy_consumed = energy_start / 1000.;
 		}
 #endif
 
 		func(_STARPU_TASK_GET_INTERFACES(task), task->cl_arg);
-
-#ifdef HAVE_LIBNVIDIA_ML
-		if (nvmlRet == NVML_SUCCESS &&
-			(profiling || (cl->energy_model && cl->energy_model->benchmarking)))
-		{
-			unsigned long long energy_end;
-			nvmlRet = nvmlDeviceGetTotalEnergyConsumption(nvmlDev[worker->devid], &energy_end);
-#ifdef STARPU_DEVEL
-#warning TODO: measure idle consumption to subtract it
-#endif
-			if (nvmlRet == NVML_SUCCESS)
-				task->profiling_info->energy_consumed += (energy_end - energy_start) / 1000.;
-		}
-#endif
 #endif
 		_STARPU_TRACE_END_EXECUTING();
 	}
@@ -566,6 +554,21 @@ static void finish_job_on_cuda(struct _starpu_job *j, struct _starpu_worker *wor
 {
 	int profiling = starpu_profiling_status_get();
 
+
+#ifdef HAVE_LIBNVIDIA_ML
+	if (profiling && task->profiling_info->energy_consumed)
+	{
+		unsigned long long energy_end;
+		nvmlReturn_t nvmlRet = -1;
+		nvmlRet = nvmlDeviceGetTotalEnergyConsumption(nvmlDev[worker->devid], &energy_end);
+#ifdef STARPU_DEVEL
+#warning TODO: measure idle consumption to subtract it
+#endif
+		if (nvmlRet == NVML_SUCCESS)
+			j->task->profiling_info->energy_consumed =
+				(energy_end / 1000. - j->task->profiling_info->energy_consumed);
+	}
+#endif
 	_starpu_set_current_task(NULL);
 	if (worker->pipeline_length)
 		worker->current_tasks[worker->first_task] = NULL;