driver_common.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 Université de Bordeaux 1
  4. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011 Télécom-SudParis
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <math.h>
  19. #include <starpu.h>
  20. #include <starpu_profiling.h>
  21. #include <profiling/profiling.h>
  22. #include <common/utils.h>
  23. #include <core/debug.h>
  24. #include <drivers/driver_common/driver_common.h>
  25. #include <starpu_top.h>
  26. void _starpu_driver_start_job(struct starpu_worker_s *args, starpu_job_t j, struct timespec *codelet_start, int rank)
  27. {
  28. struct starpu_task *task = j->task;
  29. struct starpu_codelet_t *cl = task->cl;
  30. struct starpu_task_profiling_info *profiling_info;
  31. int profiling = starpu_profiling_status_get();
  32. int starpu_top=starpu_top_status_get();
  33. int workerid = args->workerid;
  34. unsigned calibrate_model = 0;
  35. if (cl->model && cl->model->benchmarking)
  36. calibrate_model = 1;
  37. args->status = STATUS_EXECUTING;
  38. task->status = STARPU_TASK_RUNNING;
  39. if (rank == 0) {
  40. cl->per_worker_stats[workerid]++;
  41. profiling_info = task->profiling_info;
  42. if ((profiling && profiling_info) || calibrate_model || starpu_top)
  43. {
  44. starpu_clock_gettime(codelet_start);
  45. _starpu_worker_register_executing_start_date(workerid, codelet_start);
  46. }
  47. }
  48. if (starpu_top)
  49. starputop_task_started(task,workerid,codelet_start);
  50. STARPU_TRACE_START_CODELET_BODY(j);
  51. }
  52. void _starpu_driver_end_job(struct starpu_worker_s *args, starpu_job_t j, struct timespec *codelet_end, int rank)
  53. {
  54. struct starpu_task *task = j->task;
  55. struct starpu_codelet_t *cl = task->cl;
  56. struct starpu_task_profiling_info *profiling_info = task->profiling_info;
  57. int profiling = starpu_profiling_status_get();
  58. int starpu_top=starpu_top_status_get();
  59. int workerid = args->workerid;
  60. unsigned calibrate_model = 0;
  61. enum starpu_perf_archtype archtype STARPU_ATTRIBUTE_UNUSED = args->perf_arch;
  62. STARPU_TRACE_END_CODELET_BODY(j, archtype);
  63. if (cl->model && cl->model->benchmarking)
  64. calibrate_model = 1;
  65. if (rank == 0) {
  66. if ((profiling && profiling_info) || calibrate_model || starpu_top)
  67. starpu_clock_gettime(codelet_end);
  68. }
  69. if (starpu_top)
  70. starputop_task_ended(task,workerid,codelet_end);
  71. args->status = STATUS_UNKNOWN;
  72. }
  73. void _starpu_driver_update_job_feedback(starpu_job_t j, struct starpu_worker_s *worker_args,
  74. enum starpu_perf_archtype perf_arch,
  75. struct timespec *codelet_start, struct timespec *codelet_end, double conversion_time)
  76. {
  77. struct starpu_task_profiling_info *profiling_info = j->task->profiling_info;
  78. struct timespec measured_ts;
  79. double measured;
  80. int workerid = worker_args->workerid;
  81. struct starpu_codelet_t *cl = j->task->cl;
  82. int calibrate_model = 0;
  83. int profiling = starpu_profiling_status_get();
  84. int updated = 0;
  85. if (cl->model && _starpu_get_calibrate_flag())
  86. calibrate_model = 1;
  87. if (profiling_info || calibrate_model)
  88. {
  89. starpu_timespec_sub(codelet_end, codelet_start, &measured_ts);
  90. measured = starpu_timing_timespec_to_us(&measured_ts);
  91. if (profiling && profiling_info)
  92. {
  93. memcpy(&profiling_info->start_time, codelet_start, sizeof(struct timespec));
  94. memcpy(&profiling_info->end_time, codelet_end, sizeof(struct timespec));
  95. profiling_info->workerid = workerid;
  96. _starpu_worker_update_profiling_info_executing(workerid, &measured_ts, 1,
  97. profiling_info->used_cycles,
  98. profiling_info->stall_cycles,
  99. profiling_info->power_consumed);
  100. updated = 1;
  101. }
  102. if (calibrate_model)
  103. _starpu_update_perfmodel_history(j, j->task->cl->model, perf_arch, worker_args->devid, measured,j->nimpl);
  104. }
  105. if (!updated)
  106. _starpu_worker_update_profiling_info_executing(workerid, NULL, 1, 0, 0, 0);
  107. if (profiling_info && profiling_info->power_consumed && cl->power_model && cl->power_model->benchmarking) {
  108. _starpu_update_perfmodel_history(j, j->task->cl->power_model, perf_arch, worker_args->devid, profiling_info->power_consumed,j->nimpl);
  109. }
  110. if (j->task->cl->conversion_model) {
  111. _starpu_update_perfmodel_history(j, j->task->cl->conversion_model, perf_arch,
  112. worker_args->devid, conversion_time, j->nimpl);
  113. }
  114. }
  115. /* Workers may block when there is no work to do at all. We assume that the
  116. * mutex is hold when that function is called. */
  117. void _starpu_block_worker(int workerid, pthread_cond_t *cond, pthread_mutex_t *mutex)
  118. {
  119. struct timespec start_time, end_time;
  120. STARPU_TRACE_WORKER_SLEEP_START
  121. _starpu_worker_set_status(workerid, STATUS_SLEEPING);
  122. starpu_clock_gettime(&start_time);
  123. _starpu_worker_register_sleeping_start_date(workerid, &start_time);
  124. PTHREAD_COND_WAIT(cond, mutex);
  125. _starpu_worker_set_status(workerid, STATUS_UNKNOWN);
  126. STARPU_TRACE_WORKER_SLEEP_END
  127. starpu_clock_gettime(&end_time);
  128. int profiling = starpu_profiling_status_get();
  129. if (profiling)
  130. {
  131. struct timespec sleeping_time;
  132. starpu_timespec_sub(&end_time, &start_time, &sleeping_time);
  133. _starpu_worker_update_profiling_info_sleeping(workerid, &start_time, &end_time);
  134. }
  135. }