driver_scc_sink.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 <RCCE.h>
  17. #include <drivers/mp_common/sink_common.h>
  18. #include <drivers/scc/driver_scc_common.h>
  19. #include <drivers/scc/driver_scc_sink.h>
  20. void _starpu_scc_sink_init(struct _starpu_mp_node *node)
  21. {
  22. node->mp_connection.scc_nodeid = _starpu_scc_common_get_src_node_id();
  23. }
  24. void _starpu_scc_sink_deinit(struct _starpu_mp_node *node)
  25. {
  26. (void)node;
  27. _starpu_scc_common_unmap_shared_memory();
  28. RCCE_finalize();
  29. }
  30. void _starpu_scc_sink_send_to_device(const struct _starpu_mp_node *node, int dst_devid, void *msg, int len)
  31. {
  32. int ret;
  33. if ((ret = RCCE_send(msg, len, STARPU_TO_SCC_SINK_ID(dst_devid))) != RCCE_SUCCESS)
  34. STARPU_MP_COMMON_REPORT_ERROR(node, ret);
  35. }
  36. void _starpu_scc_sink_recv_from_device(const struct _starpu_mp_node *node, int src_devid, void *msg, int len)
  37. {
  38. int ret;
  39. if ((ret = RCCE_recv(msg, len, STARPU_TO_SCC_SINK_ID(src_devid))) != RCCE_SUCCESS)
  40. STARPU_MP_COMMON_REPORT_ERROR(node, ret);
  41. }
  42. /* arg -> [Function pointer on sink, number of interfaces, interfaces
  43. * (union _starpu_interface), cl_arg]
  44. *
  45. * This function change the dev_handle and the ptr of each interfaces
  46. * given to the sink.
  47. * dev_handle -> start of the shared memory (different for each sink)
  48. * ptr -> dev_handle + offset
  49. */
  50. void _starpu_scc_sink_execute(const struct _starpu_mp_node *node, void *arg, int arg_size)
  51. {
  52. void *local_arg = arg;
  53. /* point after the kernel */
  54. local_arg += sizeof(void(*)(void**, void*));
  55. unsigned nb_interfaces = *(unsigned*)local_arg;
  56. local_arg += sizeof(nb_interfaces);
  57. uintptr_t shm_addr = (uintptr_t)_starpu_scc_common_get_shared_memory_addr();
  58. unsigned i;
  59. for (i = 0; i < nb_interfaces; ++i)
  60. {
  61. /* The first field of an interface is the interface id. */
  62. switch (*(enum starpu_data_interface_id *)local_arg)
  63. {
  64. case STARPU_MATRIX_INTERFACE_ID:
  65. {
  66. struct starpu_matrix_interface *matrix = (struct starpu_matrix_interface *)local_arg;
  67. matrix->dev_handle = shm_addr;
  68. matrix->ptr = matrix->dev_handle + matrix->offset;
  69. break;
  70. }
  71. case STARPU_BLOCK_INTERFACE_ID:
  72. {
  73. struct starpu_block_interface *block = (struct starpu_block_interface *)local_arg;
  74. block->dev_handle = shm_addr;
  75. block->ptr = block->dev_handle + block->offset;
  76. break;
  77. }
  78. case STARPU_VECTOR_INTERFACE_ID:
  79. {
  80. struct starpu_vector_interface *vector = (struct starpu_vector_interface *)local_arg;
  81. vector->dev_handle = shm_addr;
  82. vector->ptr = vector->dev_handle + vector->offset;
  83. break;
  84. }
  85. case STARPU_VARIABLE_INTERFACE_ID:
  86. {
  87. struct starpu_variable_interface *variable = (struct starpu_variable_interface *)local_arg;
  88. variable->dev_handle = shm_addr;
  89. variable->ptr = variable->dev_handle + variable->offset;
  90. break;
  91. }
  92. case STARPU_CSR_INTERFACE_ID:
  93. case STARPU_BCSR_INTERFACE_ID:
  94. case STARPU_MULTIFORMAT_INTERFACE_ID:
  95. fprintf(stderr, "Data type not supported on SCC.\n");
  96. default:
  97. STARPU_ABORT();
  98. }
  99. /* point to the next interface */
  100. local_arg += sizeof(union _starpu_interface);
  101. }
  102. _starpu_sink_common_execute(node, arg, arg_size);
  103. }