jobs.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2012 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 <pthread.h>
  29. #include <common/config.h>
  30. #include <common/timing.h>
  31. #include <common/list.h>
  32. #include <common/fxt.h>
  33. #include <core/dependencies/tags.h>
  34. #include <datawizard/datawizard.h>
  35. #include <core/perfmodel/perfmodel.h>
  36. #include <core/errorcheck.h>
  37. #include <common/barrier.h>
  38. #include <common/utils.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. /* A job is the internal representation of a task. */
  49. LIST_TYPE(_starpu_job,
  50. /* The implementation associated to the job */
  51. unsigned nimpl;
  52. /* The task associated to that job */
  53. struct starpu_task *task;
  54. /* These synchronization structures are used to wait for the job to be
  55. * available or terminated for instance. */
  56. _starpu_pthread_mutex_t sync_mutex;
  57. _starpu_pthread_cond_t sync_cond;
  58. /* To avoid deadlocks, we reorder the different buffers accessed to by
  59. * the task so that we always grab the rw-lock associated to the
  60. * handles in the same order. */
  61. struct starpu_buffer_descr ordered_buffers[STARPU_NMAXBUFS];
  62. /* If a tag is associated to the job, this points to the internal data
  63. * structure that describes the tag status. */
  64. struct _starpu_tag *tag;
  65. /* Maintain a list of all the completion groups that depend on the job.
  66. * */
  67. struct _starpu_cg_list job_successors;
  68. /* For tasks with cl==NULL but submitted with explicit data dependency,
  69. * the handle for this dependency, so as to remove the task from the
  70. * last_writer/readers */
  71. starpu_data_handle_t implicit_dep_handle;
  72. /* The value of the footprint that identifies the job may be stored in
  73. * this structure. */
  74. unsigned footprint_is_computed;
  75. uint32_t footprint;
  76. /* Indicates whether the task associated to that job has already been
  77. * submitted to StarPU (1) or not (0) (using starpu_task_submit).
  78. * Becomes and stays 2 when the task is submitted several times.
  79. */
  80. unsigned submitted;
  81. /* Indicates whether the task associated to this job is terminated or
  82. * not. */
  83. unsigned terminated;
  84. /* Should that task appear in the debug tools ? (eg. the DAG generated
  85. * with dot) */
  86. unsigned exclude_from_dag;
  87. /* Each job is attributed a unique id. */
  88. unsigned long job_id;
  89. /* During the reduction of a handle, StarPU may have to submit tasks to
  90. * perform the reduction itself: those task should not be stalled while
  91. * other tasks are blocked until the handle has been properly reduced,
  92. * so we need a flag to differentiate them from "normal" tasks. */
  93. unsigned reduction_task;
  94. #ifdef STARPU_USE_FXT
  95. /* A symbol name may be associated to the job directly for debug
  96. * purposes (for instance if the codelet is NULL). */
  97. const char *model_name;
  98. #endif
  99. struct bound_task *bound_task;
  100. /* Number of workers executing that task (>1 if the task is parallel)
  101. * */
  102. int task_size;
  103. /* In case we have assigned this job to a combined workerid */
  104. int combined_workerid;
  105. /* How many workers are currently running an alias of that job (for
  106. * parallel tasks only). */
  107. int active_task_alias_count;
  108. /* Parallel workers may have to synchronize before/after the execution of a parallel task. */
  109. _starpu_pthread_barrier_t before_work_barrier;
  110. _starpu_pthread_barrier_t after_work_barrier;
  111. )
  112. /* Create an internal struct _starpu_job *structure to encapsulate the task. */
  113. struct _starpu_job* __attribute__((malloc)) _starpu_job_create(struct starpu_task *task);
  114. /* Destroy the data structure associated to the job structure */
  115. void _starpu_job_destroy(struct _starpu_job *j);
  116. /* Wait for the termination of the job */
  117. void _starpu_wait_job(struct _starpu_job *j);
  118. /* Specify that the task should not appear in the DAG generated by debug tools. */
  119. void _starpu_exclude_task_from_dag(struct starpu_task *task);
  120. /* try to submit job j, enqueue it if it's not schedulable yet. The job's sync mutex is supposed to be held already */
  121. unsigned _starpu_enforce_deps_and_schedule(struct _starpu_job *j);
  122. unsigned _starpu_enforce_deps_starting_from_task(struct _starpu_job *j);
  123. /* This function must be called after the execution of a job, this triggers all
  124. * job's dependencies and perform the callback function if any. */
  125. void _starpu_handle_job_termination(struct _starpu_job *j);
  126. /* Get the sum of the size of the data accessed by the job. */
  127. size_t _starpu_job_get_data_size(struct starpu_perfmodel *model, enum starpu_perf_archtype arch, unsigned nimpl, struct _starpu_job *j);
  128. /* Get a task from the local pool of tasks that were explicitly attributed to
  129. * that worker. */
  130. struct starpu_task *_starpu_pop_local_task(struct _starpu_worker *worker);
  131. /* Put a task into the pool of tasks that are explicitly attributed to the
  132. * specified worker. If "back" is set, the task is put at the back of the list.
  133. * Considering the tasks are popped from the back, this value should be 0 to
  134. * enforce a FIFO ordering. */
  135. int _starpu_push_local_task(struct _starpu_worker *worker, struct starpu_task *task, int back);
  136. #endif // __JOBS_H__