mp_common.h 6.3 KB

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