mp_common.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 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 __MP_COMMON_H__
  17. #define __MP_COMMON_H__
  18. #include <pthread.h>
  19. #include <semaphore.h>
  20. #include <starpu.h>
  21. #include <common/config.h>
  22. #include <common/list.h>
  23. #include <common/barrier.h>
  24. #include <common/thread.h>
  25. #ifdef STARPU_USE_MP
  26. #ifdef STARPU_USE_MIC
  27. #include <scif.h>
  28. #endif /* STARPU_USE_MIC */
  29. #define BUFFER_SIZE 256
  30. #define STARPU_MP_SRC_NODE 0
  31. #define STARPU_MP_SINK_NODE(a) ((a) + 1)
  32. #define STARPU_MP_COMMON_REPORT_ERROR(node, status) \
  33. (node)->report_error(__starpu_func__, __FILE__, __LINE__, (status))
  34. enum _starpu_mp_command
  35. {
  36. STARPU_EXIT,
  37. STARPU_EXECUTE,
  38. STARPU_ERROR_EXECUTE,
  39. STARPU_LOOKUP,
  40. STARPU_ANSWER_LOOKUP,
  41. STARPU_ERROR_LOOKUP,
  42. STARPU_ALLOCATE,
  43. STARPU_ANSWER_ALLOCATE,
  44. STARPU_ERROR_ALLOCATE,
  45. STARPU_FREE,
  46. STARPU_RECV_FROM_HOST,
  47. STARPU_SEND_TO_HOST,
  48. STARPU_RECV_FROM_SINK,
  49. STARPU_SEND_TO_SINK,
  50. STARPU_TRANSFER_COMPLETE,
  51. STARPU_SINK_NBCORES,
  52. STARPU_ANSWER_SINK_NBCORES,
  53. STARPU_EXECUTION_SUBMITTED,
  54. STARPU_EXECUTION_COMPLETED,
  55. STARPU_PRE_EXECUTION,
  56. };
  57. enum _starpu_mp_node_kind
  58. {
  59. STARPU_MIC_SINK,
  60. STARPU_MIC_SOURCE,
  61. STARPU_SCC_SINK,
  62. STARPU_SCC_SOURCE,
  63. STARPU_MPI_SINK,
  64. STARPU_MPI_SOURCE,
  65. STARPU_INVALID_KIND
  66. };
  67. union _starpu_mp_connection
  68. {
  69. #ifdef STARPU_USE_MIC
  70. scif_epd_t mic_endpoint;
  71. #endif
  72. #ifdef STARPU_USE_SCC
  73. int scc_nodeid;
  74. #endif
  75. int mpi_nodeid;
  76. };
  77. struct _starpu_mp_transfer_command
  78. {
  79. size_t size;
  80. void *addr;
  81. };
  82. struct _starpu_mp_transfer_command_to_device
  83. {
  84. int devid;
  85. size_t size;
  86. void *addr;
  87. };
  88. LIST_TYPE(mp_barrier,
  89. int id;
  90. _starpu_pthread_barrier_t before_work_barrier;
  91. _starpu_pthread_barrier_t after_work_barrier;
  92. );
  93. LIST_TYPE(mp_message,
  94. enum _starpu_mp_command type;
  95. char buffer[BUFFER_SIZE];
  96. int size;
  97. );
  98. struct mp_task
  99. {
  100. void (*kernel)(void **, void *);
  101. void *interfaces[STARPU_NMAXBUFS];
  102. void *cl_arg;
  103. unsigned coreid;
  104. enum starpu_codelet_type type;
  105. int is_parallel_task;
  106. int combined_workerid;
  107. int combined_worker_size;
  108. int combined_worker[STARPU_NMAXWORKERS];
  109. struct mp_barrier* mp_barrier;
  110. };
  111. /* Message-passing working node, whether source
  112. * or sink */
  113. struct _starpu_mp_node
  114. {
  115. enum _starpu_mp_node_kind kind;
  116. /*the number of core on the device
  117. * Must be initialized during init function*/
  118. int nb_cores;
  119. /*Is starpu running*/
  120. int is_running;
  121. /* Buffer used for scif data transfers, allocated
  122. * during node initialization.
  123. * Size : BUFFER_SIZE */
  124. void *buffer;
  125. /* For sink : -1.
  126. * For host : index of the sink = devid.
  127. */
  128. int peer_id;
  129. /* Only MIC use this for now !!
  130. * This is the devid both for the sink and the host. */
  131. int devid;
  132. /* Only MIC use this for now !!
  133. * Is the number ok MIC on the system. */
  134. unsigned int nb_mp_sinks;
  135. /* Connection used for command passing between the host thread and the
  136. * sink it controls */
  137. union _starpu_mp_connection mp_connection;
  138. /* Only MIC use this for now !!
  139. * Connection used for data transfers between the host and his sink. */
  140. union _starpu_mp_connection host_sink_dt_connection;
  141. /* Only MIC use this for now !!
  142. * Only sink use this for now !!
  143. * Connection used for data transfer between devices.
  144. * A sink opens a connection with each other sink,
  145. * thus each sink can directly send data to each other.
  146. * For sink :
  147. * - sink_sink_dt_connections[i] is the connection to the sink number i.
  148. * - sink_sink_dt_connections[j] is not initialized for the sink number j. */
  149. union _starpu_mp_connection *sink_sink_dt_connections;
  150. /* table to store pointer of the thread workers*/
  151. void* thread_table;
  152. /*list where threads add messages to send to the source node */
  153. struct mp_message_list* message_queue;
  154. pthread_mutex_t message_queue_mutex;
  155. /*list of barrier for combined worker*/
  156. struct mp_barrier_list* barrier_list;
  157. pthread_mutex_t barrier_mutex;
  158. /*table where worker comme pick task*/
  159. struct mp_task ** run_table;
  160. sem_t * sem_run_table;
  161. /* Node general functions */
  162. void (*init)(struct _starpu_mp_node *node);
  163. void (*deinit)(struct _starpu_mp_node *node);
  164. void (*report_error)(const char *, const char *, const int, const int);
  165. /* Message passing */
  166. int (*mp_recv_is_ready)(const struct _starpu_mp_node *);
  167. void (*mp_send)(const struct _starpu_mp_node *, void *, int);
  168. void (*mp_recv)(const struct _starpu_mp_node *, void *, int);
  169. /* Data transfers */
  170. void (*dt_send)(const struct _starpu_mp_node *, void *, int);
  171. void (*dt_recv)(const struct _starpu_mp_node *, void *, int);
  172. void (*dt_send_to_device)(const struct _starpu_mp_node *, int, void *, int);
  173. void (*dt_recv_from_device)(const struct _starpu_mp_node *, int, void *, int);
  174. void (*(*get_kernel_from_job)(const struct _starpu_mp_node *,struct _starpu_job *))(void);
  175. void (*(*lookup)(const struct _starpu_mp_node *, char* ))(void);
  176. void (*bind_thread)(const struct _starpu_mp_node *, int,int *,int);
  177. void (*execute)(struct _starpu_mp_node *, void *, int);
  178. void (*allocate)(const struct _starpu_mp_node *, void *, int);
  179. void (*free)(const struct _starpu_mp_node *, void *, int);
  180. };
  181. struct _starpu_mp_node * _starpu_mp_common_node_create(enum _starpu_mp_node_kind node_kind, int peer_devid);
  182. void _starpu_mp_common_node_destroy(struct _starpu_mp_node *node);
  183. void _starpu_mp_common_send_command(const struct _starpu_mp_node *node,
  184. const enum _starpu_mp_command command,
  185. void *arg, int arg_size);
  186. enum _starpu_mp_command _starpu_mp_common_recv_command(const struct _starpu_mp_node *node,
  187. void **arg, int *arg_size);
  188. #endif /* STARPU_USE_MP */
  189. #endif /* __MP_COMMON_H__ */