jobs.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 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. #ifdef STARPU_USE_CUDA
  39. #include <cuda.h>
  40. #endif
  41. struct _starpu_worker;
  42. /* codelet function */
  43. typedef void (*_starpu_cl_func)(void **, void *);
  44. #define _STARPU_CPU_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_CPU)
  45. #define _STARPU_CUDA_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_CUDA)
  46. #define _STARPU_SPU_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_SPU)
  47. #define _STARPU_GORDON_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_GORDON)
  48. #define _STARPU_OPENCL_MAY_PERFORM(j) ((j)->task->cl->where & STARPU_OPENCL)
  49. /* A job is the internal representation of a task. */
  50. LIST_TYPE(_starpu_job,
  51. /* The implementation associated to the job */
  52. unsigned nimpl;
  53. /* The task associated to that job */
  54. struct starpu_task *task;
  55. /* These synchronization structures are used to wait for the job to be
  56. * available or terminated for instance. */
  57. pthread_mutex_t sync_mutex;
  58. pthread_cond_t sync_cond;
  59. /* To avoid deadlocks, we reorder the different buffers accessed to by
  60. * the task so that we always grab the rw-lock associated to the
  61. * handles in the same order. */
  62. struct starpu_buffer_descr ordered_buffers[STARPU_NMAXBUFS];
  63. /* If a tag is associated to the job, this points to the internal data
  64. * structure that describes the tag status. */
  65. struct _starpu_tag *tag;
  66. /* Maintain a list of all the completion groups that depend on the job.
  67. * */
  68. struct _starpu_cg_list job_successors;
  69. /* The value of the footprint that identifies the job may be stored in
  70. * this structure. */
  71. unsigned footprint_is_computed;
  72. uint32_t footprint;
  73. /* Indicates whether the task associated to that job has already been
  74. * submitted to StarPU or not (using starpu_task_submit). */
  75. unsigned submitted;
  76. /* Indicates whether the task associated to this job is terminated or
  77. * not. */
  78. unsigned terminated;
  79. /* Should that task appear in the debug tools ? (eg. the DAG generated
  80. * with dot) */
  81. unsigned exclude_from_dag;
  82. /* Each job is attributed a unique id. */
  83. unsigned long job_id;
  84. /* During the reduction of a handle, StarPU may have to submit tasks to
  85. * perform the reduction itself: those task should not be stalled while
  86. * other tasks are blocked until the handle has been properly reduced,
  87. * so we need a flag to differentiate them from "normal" tasks. */
  88. unsigned reduction_task;
  89. #ifdef STARPU_USE_FXT
  90. /* A symbol name may be associated to the job directly for debug
  91. * purposes (for instance if the codelet is NULL). */
  92. const char *model_name;
  93. #endif
  94. struct bound_task *bound_task;
  95. /* Number of workers executing that task (>1 if the task is parallel)
  96. * */
  97. int task_size;
  98. /* In case we have assigned this job to a combined workerid */
  99. int combined_workerid;
  100. /* How many workers are currently running an alias of that job (for
  101. * parallel tasks only). */
  102. int active_task_alias_count;
  103. /* Parallel workers may have to synchronize before/after the execution of a parallel task. */
  104. pthread_barrier_t before_work_barrier;
  105. pthread_barrier_t after_work_barrier;
  106. )
  107. /* Create an internal struct _starpu_job *structure to encapsulate the task. */
  108. struct _starpu_job* __attribute__((malloc)) _starpu_job_create(struct starpu_task *task);
  109. /* Destroy the data structure associated to the job structure */
  110. void _starpu_job_destroy(struct _starpu_job *j);
  111. /* Wait for the termination of the job */
  112. void _starpu_wait_job(struct _starpu_job *j);
  113. /* Specify that the task should not appear in the DAG generated by debug tools. */
  114. void _starpu_exclude_task_from_dag(struct starpu_task *task);
  115. /* try to submit job j, enqueue it if it's not schedulable yet */
  116. unsigned _starpu_enforce_deps_and_schedule(struct _starpu_job *j, unsigned job_is_already_locked);
  117. unsigned _starpu_enforce_deps_starting_from_task(struct _starpu_job *j, unsigned job_is_already_locked);
  118. /* This function must be called after the execution of a job, this triggers all
  119. * job's dependencies and perform the callback function if any. */
  120. void _starpu_handle_job_termination(struct _starpu_job *j, unsigned job_is_already_locked);
  121. /* Get the sum of the size of the data accessed by the job. */
  122. size_t _starpu_job_get_data_size(struct _starpu_job *j);
  123. /* Get a task from the local pool of tasks that were explicitly attributed to
  124. * that worker. */
  125. struct starpu_task *_starpu_pop_local_task(struct _starpu_worker *worker);
  126. /* Put a task into the pool of tasks that are explicitly attributed to the
  127. * specified worker. If "back" is set, the task is put at the back of the list.
  128. * Considering the tasks are popped from the back, this value should be 0 to
  129. * enforce a FIFO ordering. */
  130. int _starpu_push_local_task(struct _starpu_worker *worker, struct starpu_task *task, int back);
  131. /* Returns the symbol associated to that job if any. */
  132. const char *_starpu_get_model_name(struct _starpu_job *j);
  133. #endif // __JOBS_H__