driver_mic_common.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include <starpu.h>
  17. #include <drivers/mp_common/mp_common.h>
  18. #include <drivers/mic/driver_mic_common.h>
  19. void _starpu_mic_common_report_scif_error(const char *func, const char *file, const int line, const int status)
  20. {
  21. const char *errormsg = strerror(status);
  22. printf("Common: oops in %s (%s:%u)... %d: %s \n", func, file, line, status, errormsg);
  23. STARPU_ASSERT(0);
  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. /* Handles the error so the caller (which must be generic) doesn't have to
  34. * care about it.
  35. */
  36. void _starpu_mic_common_recv(const struct _starpu_mp_node *node, void *msg, int len)
  37. {
  38. if ((scif_recv(node->mp_connection.mic_endpoint, msg, len, SCIF_RECV_BLOCK)) < 0)
  39. STARPU_MP_COMMON_REPORT_ERROR(node, errno);
  40. }
  41. /* Handles the error so the caller (which must be generic) doesn't have to
  42. * care about it.
  43. */
  44. void _starpu_mic_common_dt_send(const struct _starpu_mp_node *mp_node, void *msg, int len)
  45. {
  46. if ((scif_send(mp_node->host_sink_dt_connection.mic_endpoint, msg, len, SCIF_SEND_BLOCK)) < 0)
  47. STARPU_MP_COMMON_REPORT_ERROR(mp_node, errno);
  48. }
  49. /* Handles the error so the caller (which must be generic) doesn't have to
  50. * care about it.
  51. */
  52. void _starpu_mic_common_dt_recv(const struct _starpu_mp_node *mp_node, void *msg, int len)
  53. {
  54. if ((scif_recv(mp_node->host_sink_dt_connection.mic_endpoint, msg, len, SCIF_SEND_BLOCK)) < 0)
  55. STARPU_MP_COMMON_REPORT_ERROR(mp_node, errno);
  56. }
  57. void _starpu_mic_common_connect(scif_epd_t *endpoint, uint16_t remote_node,
  58. uint16_t local_port_number, uint16_t remote_port_number)
  59. {
  60. /* Endpoint only useful for the initialization of the connection */
  61. struct scif_portID portID;
  62. portID.node = remote_node;
  63. portID.port = remote_port_number;
  64. if ((*endpoint = scif_open()) < 0)
  65. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  66. if ((scif_bind(*endpoint, local_port_number)) < 0)
  67. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  68. _STARPU_DEBUG("Connecting to MIC %d on %d:%d...\n", remote_node, local_port_number, remote_port_number);
  69. while (scif_connect(*endpoint, &portID) == -1)
  70. {
  71. if (errno != ECONNREFUSED)
  72. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  73. }
  74. _STARPU_DEBUG("done\n");
  75. }
  76. /* Wait and accept the connection from the wanted device on the port PORT_NUMBER
  77. * and then initialize the connection, the resutling endpoint is stored in ENDPOINT */
  78. void _starpu_mic_common_accept(scif_epd_t *endpoint, uint16_t port_number)
  79. {
  80. /* Unused variables, only useful to make scif_accept don't cause
  81. * a seg fault when trying to access PEER parameter */
  82. struct scif_portID portID;
  83. /* Endpoint only useful for the initialization of the connection */
  84. int init_epd;
  85. if ((init_epd = scif_open()) < 0)
  86. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  87. if ((scif_bind(init_epd, port_number)) < 0)
  88. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  89. /* We fix the maximum number of request to 1 as we
  90. * only need one connection, more would be an error */
  91. if ((scif_listen(init_epd, 1)) < 0)
  92. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  93. _STARPU_DEBUG("MIC accepting connection on %u...\n", port_number);
  94. if ((scif_accept(init_epd, &portID, endpoint, SCIF_ACCEPT_SYNC)) < 0)
  95. STARPU_MIC_COMMON_REPORT_SCIF_ERROR(errno);
  96. _STARPU_DEBUG("done\n", init_epd);
  97. scif_close(init_epd);
  98. }