jobs.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2013 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. #ifndef __JOBS_H__
  19. #define __JOBS_H__
  20. #include <starpu.h>
  21. #include <semaphore.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <stdint.h>
  25. #include <unistd.h>
  26. #include <string.h>
  27. #include <stdarg.h>
  28. #include <common/config.h>
  29. #include <common/timing.h>
  30. #include <common/list.h>
  31. #include <common/fxt.h>
  32. #include <core/dependencies/tags.h>
  33. #include <datawizard/datawizard.h>
  34. #include <core/perfmodel/perfmodel.h>
  35. #include <core/errorcheck.h>
  36. #include <common/barrier.h>
  37. #include <common/utils.h>
  38. #include <common/thread.h>
  39. #ifdef STARPU_USE_CUDA
  40. #include <cuda.h>
  41. #endif
  42. struct _starpu_worker;
  43. /* codelet function */
  44. typedef void (*_starpu_cl_func_t)(void **, void *);
  45. #define _STARPU_CPU_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_CPU)
  46. #define _STARPU_CUDA_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_CUDA)
  47. #define _STARPU_OPENCL_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_OPENCL)
  48. #define _STARPU_MIC_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_MIC)
  49. #define _STARPU_SCC_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_SCC)
  50. /* A job is the internal representation of a task. */
  51. LIST_TYPE(_starpu_job,
  52. /* The implementation associated to the job */
  53. unsigned nimpl;
  54. /* The task associated to that job */
  55. struct starpu_task *task;
  56. /* These synchronization structures are used to wait for the job to be
  57. * available or terminated for instance. */
  58. starpu_pthread_mutex_t sync_mutex;
  59. starpu_pthread_cond_t sync_cond;
  60. /* To avoid deadlocks, we reorder the different buffers accessed to by
  61. * the task so that we always grab the rw-lock associated to the
  62. * handles in the same order. */
  63. struct starpu_data_descr ordered_buffers[STARPU_NMAXBUFS];
  64. struct starpu_data_descr *dyn_ordered_buffers;
  65. /* If a tag is associated to the job, this points to the internal data
  66. * structure that describes the tag status. */
  67. struct _starpu_tag *tag;
  68. /* Maintain a list of all the completion groups that depend on the job.
  69. * */
  70. struct _starpu_cg_list job_successors;
  71. /* For tasks with cl==NULL but submitted with explicit data dependency,
  72. * the handle for this dependency, so as to remove the task from the
  73. * last_writer/readers */
  74. starpu_data_handle_t implicit_dep_handle;
  75. /* The value of the footprint that identifies the job may be stored in
  76. * this structure. */
  77. unsigned footprint_is_computed;
  78. uint32_t footprint;
  79. /* Indicates whether the task associated to that job has already been
  80. * submitted to StarPU (1) or not (0) (using starpu_task_submit).
  81. * Becomes and stays 2 when the task is submitted several times.
  82. */
  83. unsigned submitted;
  84. /* Indicates whether the task associated to this job is terminated or
  85. * not. */
  86. unsigned terminated;
  87. /* Should that task appear in the debug tools ? (eg. the DAG generated
  88. * with dot) */
  89. unsigned exclude_from_dag;
  90. /* Is that task internal to StarPU ? */
  91. unsigned internal;
  92. /* Each job is attributed a unique id. */
  93. unsigned long job_id;
  94. /* During the reduction of a handle, StarPU may have to submit tasks to
  95. * perform the reduction itself: those task should not be stalled while
  96. * other tasks are blocked until the handle has been properly reduced,
  97. * so we need a flag to differentiate them from "normal" tasks. */
  98. unsigned reduction_task;
  99. /* Used by MIC driver to record codelet start time instead of using a
  100. * local variable */
  101. struct timespec cl_start;
  102. #ifdef STARPU_USE_FXT
  103. /* A symbol name may be associated to the job directly for debug
  104. * purposes (for instance if the codelet is NULL). */
  105. const char *model_name;
  106. #endif
  107. struct bound_task *bound_task;
  108. /* Number of workers executing that task (>1 if the task is parallel)
  109. * */
  110. int task_size;
  111. /* In case we have assigned this job to a combined workerid */
  112. int combined_workerid;
  113. /* How many workers are currently running an alias of that job (for
  114. * parallel tasks only). */
  115. int active_task_alias_count;
  116. /* Parallel workers may have to synchronize before/after the execution of a parallel task. */
  117. _starpu_pthread_barrier_t before_work_barrier;
  118. _starpu_pthread_barrier_t after_work_barrier;
  119. )
  120. /* Create an internal struct _starpu_job *structure to encapsulate the task. */
  121. struct _starpu_job* __attribute__((malloc)) _starpu_job_create(struct starpu_task *task);
  122. /* Destroy the data structure associated to the job structure */
  123. void _starpu_job_destroy(struct _starpu_job *j);
  124. /* Wait for the termination of the job */
  125. void _starpu_wait_job(struct _starpu_job *j);
  126. /* Specify that the task should not appear in the DAG generated by debug tools. */
  127. void _starpu_exclude_task_from_dag(struct starpu_task *task);
  128. /* try to submit job j, enqueue it if it's not schedulable yet. The job's sync mutex is supposed to be held already */
  129. unsigned _starpu_enforce_deps_and_schedule(struct _starpu_job *j);
  130. unsigned _starpu_enforce_deps_starting_from_task(struct _starpu_job *j);
  131. /* This function must be called after the execution of a job, this triggers all
  132. * job's dependencies and perform the callback function if any. */
  133. void _starpu_handle_job_termination(struct _starpu_job *j);
  134. /* Get the sum of the size of the data accessed by the job. */
  135. size_t _starpu_job_get_data_size(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, unsigned nimpl, struct _starpu_job *j);
  136. /* Get a task from the local pool of tasks that were explicitly attributed to
  137. * that worker. */
  138. struct starpu_task *_starpu_pop_local_task(struct _starpu_worker *worker);
  139. /* Put a task into the pool of tasks that are explicitly attributed to the
  140. * specified worker. If "back" is set, the task is put at the back of the list.
  141. * Considering the tasks are popped from the back, this value should be 0 to
  142. * enforce a FIFO ordering. */
  143. int _starpu_push_local_task(struct _starpu_worker *worker, struct starpu_task *task, int prio);
  144. #define _STARPU_JOB_GET_ORDERED_BUFFER_HANDLE(job, i) ((job->dyn_ordered_buffers) ? job->dyn_ordered_buffers[i].handle : job->ordered_buffers[i].handle)
  145. #define _STARPU_JOB_GET_ORDERED_BUFFER_MODE(job, i) ((job->dyn_ordered_buffers) ? job->dyn_ordered_buffers[i].mode : job->ordered_buffers[i].mode)
  146. #define _STARPU_JOB_SET_ORDERED_BUFFER_HANDLE(job, handle, i) do { if (job->dyn_ordered_buffers) job->dyn_ordered_buffers[i].handle = (handle); else job->ordered_buffers[i].handle = (handle);} while(0)
  147. #define _STARPU_JOB_SET_ORDERED_BUFFER_MODE(job, mode, i) do { if (job->dyn_ordered_buffers) job->dyn_ordered_buffers[i].mode = mode; else job->ordered_buffers[i].mode = mode;} while(0)
  148. #define _STARPU_JOB_SET_ORDERED_BUFFER(job, buffer, i) do { if (job->dyn_ordered_buffers) job->dyn_ordered_buffers[i] = buffer; else job->ordered_buffers[i] = buffer;} while(0)
  149. #define _STARPU_JOB_GET_ORDERED_BUFFERS(job) (job->dyn_ordered_buffers) ? job->dyn_ordered_buffers : job->ordered_buffers
  150. #endif // __JOBS_H__