task.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __CORE_TASK_H__
  17. #define __CORE_TASK_H__
  18. /** @file */
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <core/jobs.h>
  22. #pragma GCC visibility push(hidden)
  23. /** Internal version of starpu_task_destroy: don't check task->destroy flag */
  24. void _starpu_task_destroy(struct starpu_task *task);
  25. #ifdef STARPU_OPENMP
  26. /** Test for the termination of the task.
  27. * Call starpu_task_destroy if required and the task is terminated. */
  28. int _starpu_task_test_termination(struct starpu_task *task);
  29. #endif
  30. /** A pthread key is used to store the task currently executed on the thread.
  31. * _starpu_task_init initializes this pthread key and
  32. * _starpu_set_current_task updates its current value. */
  33. void _starpu_task_init(void);
  34. void _starpu_task_deinit(void);
  35. void _starpu_set_current_task(struct starpu_task *task);
  36. int _starpu_submit_job(struct _starpu_job *j, int nodeps);
  37. void _starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[], int check);
  38. #define _STARPU_JOB_UNSET ((struct _starpu_job *) NULL)
  39. #define _STARPU_JOB_SETTING ((struct _starpu_job *) 1)
  40. /** Returns the job structure (which is the internal data structure associated
  41. * to a task). */
  42. struct _starpu_job *_starpu_get_job_associated_to_task_slow(struct starpu_task *task, struct _starpu_job *job);
  43. static inline struct _starpu_job *_starpu_get_job_associated_to_task(struct starpu_task *task)
  44. {
  45. STARPU_ASSERT(task);
  46. struct _starpu_job *job = (struct _starpu_job *) task->starpu_private;
  47. if (STARPU_LIKELY(job != _STARPU_JOB_UNSET && job != _STARPU_JOB_SETTING))
  48. {
  49. /* Already available */
  50. STARPU_RMB();
  51. return job;
  52. }
  53. return _starpu_get_job_associated_to_task_slow(task, job);
  54. }
  55. /** Submits starpu internal tasks to the initial context */
  56. int _starpu_task_submit_internally(struct starpu_task *task);
  57. int _starpu_handle_needs_conversion_task(starpu_data_handle_t handle,
  58. unsigned int node);
  59. int
  60. _starpu_handle_needs_conversion_task_for_arch(starpu_data_handle_t handle,
  61. enum starpu_node_kind node_kind);
  62. #ifdef STARPU_OPENMP
  63. /** Prepare the current task for accepting new dependencies before becoming a continuation. */
  64. void _starpu_task_prepare_for_continuation_ext(unsigned continuation_resubmit,
  65. void (*continuation_callback_on_sleep)(void *arg), void *continuation_callback_on_sleep_arg);
  66. void _starpu_task_prepare_for_continuation(void);
  67. void _starpu_task_set_omp_cleanup_callback(struct starpu_task *task, void (*omp_cleanup_callback)(void *arg),
  68. void *omp_cleanup_callback_arg);
  69. #endif
  70. int _starpu_task_uses_multiformat_handles(struct starpu_task *task);
  71. int _starpu_task_submit_conversion_task(struct starpu_task *task,
  72. unsigned int workerid);
  73. void _starpu_task_check_deprecated_fields(struct starpu_task *task);
  74. void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl);
  75. static inline starpu_cpu_func_t _starpu_task_get_cpu_nth_implementation(struct starpu_codelet *cl, unsigned nimpl)
  76. {
  77. return cl->cpu_funcs[nimpl];
  78. }
  79. static inline starpu_cuda_func_t _starpu_task_get_cuda_nth_implementation(struct starpu_codelet *cl, unsigned nimpl)
  80. {
  81. return cl->cuda_funcs[nimpl];
  82. }
  83. static inline starpu_opencl_func_t _starpu_task_get_opencl_nth_implementation(struct starpu_codelet *cl, unsigned nimpl)
  84. {
  85. return cl->opencl_funcs[nimpl];
  86. }
  87. static inline starpu_mpi_ms_func_t _starpu_task_get_mpi_ms_nth_implementation(struct starpu_codelet *cl, unsigned nimpl)
  88. {
  89. return cl->mpi_ms_funcs[nimpl];
  90. }
  91. static inline const char *_starpu_task_get_cpu_name_nth_implementation(struct starpu_codelet *cl, unsigned nimpl)
  92. {
  93. return cl->cpu_funcs_name[nimpl];
  94. }
  95. #define _STARPU_TASK_SET_INTERFACE(task, interface, i) do { if (task->dyn_handles) task->dyn_interfaces[i] = interface; else task->interfaces[i] = interface;} while(0)
  96. #define _STARPU_TASK_GET_INTERFACES(task) ((task->dyn_handles) ? task->dyn_interfaces : task->interfaces)
  97. void _starpu_watchdog_init(void);
  98. void _starpu_watchdog_shutdown(void);
  99. int _starpu_task_wait_for_all_and_return_nb_waited_tasks(void);
  100. int _starpu_task_wait_for_all_in_ctx_and_return_nb_waited_tasks(unsigned sched_ctx);
  101. #pragma GCC visibility pop
  102. #ifdef BUILDING_STARPU
  103. LIST_CREATE_TYPE_NOSTRUCT(starpu_task, prev, next);
  104. PRIO_LIST_CREATE_TYPE(starpu_task, priority);
  105. #endif
  106. #endif // __CORE_TASK_H__