driver_mic_common.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012, 2016 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. #include <starpu.h>
  17. #include <drivers/mp_common/mp_common.h>
  18. #include <drivers/mic/driver_mic_common.h>
  19. #include <drivers/mic/driver_mic_source.h>
  20. void _starpu_mic_common_report_scif_error(const char *func, const char *file, const int line, const int status)
  21. {
  22. const char *errormsg = strerror(status);
  23. _STARPU_ERROR("Common: oops in %s (%s:%d)... %d: %s \n", func, file, line, status, errormsg);
  24. }
  25. /* Handles the error so the caller (which must be generic) doesn't have to
  26. * care about it.
  27. */
  28. void _starpu_mic_common_send(const struct _starpu_mp_node *node, void *msg, int len)
  29. {
  30. if ((scif_send(node->mp_connection.mic_endpoint, msg, len, SCIF_SEND_BLOCK)) < 0)
  31. STARPU_MP_COMMON_REPORT_ERROR(node, errno);
  32. }
  33. /* Teel is the mic endpoint is ready
  34. * return 1 if a message has been receive, 0 if no message has been receive
  35. */
  36. int _starpu_mic_common_recv_is_ready(const struct _starpu_mp_node *mp_node)
  37. {
  38. struct scif_pollepd pollepd;
  39. pollepd.epd = mp_node->mp_connection.mic_endpoint;
  40. pollepd.events = SCIF_POLLIN;
  41. pollepd.revents = 0;
  42. return scif_poll(&pollepd,1,0);
  43. }
  44. /* Handles the error so the caller (which must be generic) doesn't have to
  45. * care about it.
  46. */
  47. void _starpu_mic_common_recv(const struct _starpu_mp_node *node, void *msg, int len)
  48. {
  49. if ((scif_recv(node->mp_connection.mic_endpoint, msg, len, SCIF_RECV_BLOCK)) < 0)
  50. STARPU_MP_COMMON_REPORT_ERROR(node, errno);
  51. }
  52. /* Handles the error so the caller (which must be generic) doesn't have to
  53. * care about it.
  54. */
  55. void _starpu_mic_common_dt_send(const struct _starpu_mp_node *mp_node, void *msg, int len, void * event)
  56. {
  57. if ((scif_send(mp_node->host_sink_dt_connection.mic_endpoint, msg, len, SCIF_SEND_BLOCK)) < 0)
  58. STARPU_MP_COMMON_REPORT_ERROR(mp_node, errno);
  59. }
  60. /* Handles the error so the caller (which must be generic) doesn't have to
  61. * care about it.
  62. */
  63. void _starpu_mic_common_dt_recv(const struct _starpu_mp_node *mp_node, void *msg, int len, void * event)
  64. {
  65. if ((scif_recv(mp_node->host_sink_dt_connection.mic_endpoint, msg, len, SCIF_SEND_BLOCK)) < 0)
  66. STARPU_MP_COMMON_REPORT_ERROR(mp_node, errno);
  67. }
  68. void _starpu_mic_common_connect(scif_epd_t *endpoint, uint16_t remote_node, COIPROCESS process,
  69. uint16_t local_port_number, uint16_t remote_port_number)
  70. {
  71. /* Endpoint only useful for the initialization of the connection */
  72. struct scif_portID portID;
  73. portID.node = remote_node;
  74. portID.port = remote_port_number;
  75. if ((*endpoint = scif_open()) < 0)
  76. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  77. if ((scif_bind(*endpoint, local_port_number)) < 0)
  78. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  79. _STARPU_DEBUG("Connecting to MIC %d on %d:%d...\n", remote_node, local_port_number, remote_port_number);
  80. while (scif_connect(*endpoint, &portID) == -1)
  81. {
  82. if (process)
  83. {
  84. const char *main_name = "starpu_init";
  85. COIFUNCTION func;
  86. COIRESULT res;
  87. /* Check whether it's still alive */
  88. res = COIProcessGetFunctionHandles(process, 1, &main_name, &func);
  89. STARPU_ASSERT_MSG(res != COI_PROCESS_DIED, "process died on MIC %d", remote_node-1);
  90. STARPU_ASSERT_MSG(res != COI_DOES_NOT_EXIST, "MIC program does not expose the 'starpu_init' function, please link it with -rdynamic or -export-dynamic");
  91. if (res != COI_SUCCESS)
  92. STARPU_MIC_SRC_REPORT_COI_ERROR(res);
  93. }
  94. if (errno != ECONNREFUSED)
  95. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  96. }
  97. _STARPU_DEBUG("done\n");
  98. }
  99. /* Wait and accept the connection from the wanted device on the port PORT_NUMBER
  100. * and then initialize the connection, the resutling endpoint is stored in ENDPOINT */
  101. void _starpu_mic_common_accept(scif_epd_t *endpoint, uint16_t port_number)
  102. {
  103. /* Unused variables, only useful to make scif_accept don't cause
  104. * a seg fault when trying to access PEER parameter */
  105. struct scif_portID portID;
  106. /* Endpoint only useful for the initialization of the connection */
  107. int init_epd;
  108. if ((init_epd = scif_open()) < 0)
  109. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  110. if ((scif_bind(init_epd, port_number)) < 0)
  111. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  112. /* We fix the maximum number of request to 1 as we
  113. * only need one connection, more would be an error */
  114. if ((scif_listen(init_epd, 1)) < 0)
  115. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  116. _STARPU_DEBUG("MIC accepting connection on %u...\n", port_number);
  117. if ((scif_accept(init_epd, &portID, endpoint, SCIF_ACCEPT_SYNC)) < 0)
  118. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  119. _STARPU_DEBUG("done : %d\n", init_epd);
  120. scif_close(init_epd);
  121. }