driver_scc_sink.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 <dlfcn.h>
  18. #include <datawizard/interfaces/data_interface.h>
  19. #include <drivers/mp_common/sink_common.h>
  20. #include <drivers/scc/driver_scc_common.h>
  21. #include <drivers/scc/driver_scc_sink.h>
  22. void _starpu_scc_sink_init(struct _starpu_mp_node *node)
  23. {
  24. node->mp_connection.scc_nodeid = _starpu_scc_common_get_src_node_id();
  25. /****************
  26. * TODO *
  27. * get nb_cores *
  28. ****************/
  29. node->nb_cores = 1;
  30. STARPU_ASSERT(0);
  31. }
  32. void _starpu_scc_sink_launch_workers(struct _starpu_mp_node *node)
  33. {
  34. /*****************
  35. * TODO *
  36. * init thread *
  37. *****************/
  38. STARPU_ASSERT(0);
  39. }
  40. void _starpu_scc_sink_deinit(struct _starpu_mp_node *node)
  41. {
  42. (void)node;
  43. _starpu_scc_common_unmap_shared_memory();
  44. RCCE_finalize();
  45. }
  46. void _starpu_scc_sink_send_to_device(const struct _starpu_mp_node *node, int dst_devid, void *msg, int len)
  47. {
  48. int ret;
  49. if ((ret = RCCE_send(msg, len, STARPU_TO_SCC_SINK_ID(dst_devid))) != RCCE_SUCCESS)
  50. STARPU_MP_COMMON_REPORT_ERROR(node, ret);
  51. }
  52. void _starpu_scc_sink_recv_from_device(const struct _starpu_mp_node *node, int src_devid, void *msg, int len)
  53. {
  54. int ret;
  55. if ((ret = RCCE_recv(msg, len, STARPU_TO_SCC_SINK_ID(src_devid))) != RCCE_SUCCESS)
  56. STARPU_MP_COMMON_REPORT_ERROR(node, ret);
  57. }
  58. void _starpu_scc_sink_bind_thread(const struct _starpu_mp_node *mp_node STARPU_ATTRIBUTE_UNUSED, cpu_set_t * cpuset, int coreid, starpu_pthread_t *thread)
  59. {
  60. /****************
  61. * TODO *
  62. ****************/
  63. STARPU_ASSERT(0);
  64. }
  65. /* arg -> [Function pointer on sink, number of interfaces, interfaces
  66. * (union _starpu_interface), cl_arg]
  67. *
  68. * This function change the dev_handle and the ptr of each interfaces
  69. * given to the sink.
  70. * dev_handle -> start of the shared memory (different for each sink)
  71. * ptr -> dev_handle + offset
  72. */
  73. void _starpu_scc_sink_execute(const struct _starpu_mp_node *node, void *arg, int arg_size)
  74. {
  75. void *local_arg = arg;
  76. /* point after the kernel */
  77. local_arg += sizeof(void(*)(void**, void*));
  78. unsigned nb_interfaces = *(unsigned*)local_arg;
  79. local_arg += sizeof(nb_interfaces);
  80. uintptr_t shm_addr = (uintptr_t)_starpu_scc_common_get_shared_memory_addr();
  81. unsigned i;
  82. for (i = 0; i < nb_interfaces; ++i)
  83. {
  84. /* The first field of an interface is the interface id. */
  85. switch (*(enum starpu_data_interface_id *)local_arg)
  86. {
  87. case STARPU_MATRIX_INTERFACE_ID:
  88. {
  89. struct starpu_matrix_interface *matrix = (struct starpu_matrix_interface *)local_arg;
  90. matrix->dev_handle = shm_addr;
  91. matrix->ptr = matrix->dev_handle + matrix->offset;
  92. break;
  93. }
  94. case STARPU_BLOCK_INTERFACE_ID:
  95. {
  96. struct starpu_block_interface *block = (struct starpu_block_interface *)local_arg;
  97. block->dev_handle = shm_addr;
  98. block->ptr = block->dev_handle + block->offset;
  99. break;
  100. }
  101. case STARPU_VECTOR_INTERFACE_ID:
  102. {
  103. struct starpu_vector_interface *vector = (struct starpu_vector_interface *)local_arg;
  104. vector->dev_handle = shm_addr;
  105. vector->ptr = vector->dev_handle + vector->offset;
  106. break;
  107. }
  108. case STARPU_VARIABLE_INTERFACE_ID:
  109. {
  110. struct starpu_variable_interface *variable = (struct starpu_variable_interface *)local_arg;
  111. variable->dev_handle = shm_addr;
  112. variable->ptr = variable->dev_handle + variable->offset;
  113. break;
  114. }
  115. case STARPU_CSR_INTERFACE_ID:
  116. case STARPU_BCSR_INTERFACE_ID:
  117. case STARPU_MULTIFORMAT_INTERFACE_ID:
  118. fprintf(stderr, "Data type not supported on SCC.\n");
  119. default:
  120. STARPU_ABORT();
  121. }
  122. /* point to the next interface */
  123. local_arg += sizeof(union _starpu_interface);
  124. }
  125. _starpu_sink_common_execute(node, arg, arg_size);
  126. }
  127. void (*_starpu_scc_sink_lookup (const struct _starpu_mp_node * node STARPU_ATTRIBUTE_UNUSED, char* func_name))(void)
  128. {
  129. void *dl_handle = dlopen(NULL, RTLD_NOW);
  130. return dlsym(dl_handle, func_name);
  131. }