load_data_interface.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016 Inria
  4. * Copyright (C) 2017 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <stdlib.h>
  19. #include <common/config.h>
  20. #include "load_data_interface.h"
  21. #if defined(STARPU_USE_MPI_MPI)
  22. int load_data_get_sleep_threshold(starpu_data_handle_t handle)
  23. {
  24. struct load_data_interface *ld_interface =
  25. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  26. return ld_interface->sleep_task_threshold;
  27. }
  28. int load_data_get_wakeup_threshold(starpu_data_handle_t handle)
  29. {
  30. struct load_data_interface *ld_interface =
  31. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  32. return ld_interface->wakeup_task_threshold;
  33. }
  34. int load_data_get_current_phase(starpu_data_handle_t handle)
  35. {
  36. struct load_data_interface *ld_interface =
  37. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  38. return ld_interface->phase;
  39. }
  40. int load_data_get_nsubmitted_tasks(starpu_data_handle_t handle)
  41. {
  42. struct load_data_interface *ld_interface =
  43. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  44. return ld_interface->nsubmitted_tasks;
  45. }
  46. int load_data_get_nfinished_tasks(starpu_data_handle_t handle)
  47. {
  48. struct load_data_interface *ld_interface =
  49. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  50. return ld_interface->nfinished_tasks;
  51. }
  52. int load_data_inc_nsubmitted_tasks(starpu_data_handle_t handle)
  53. {
  54. struct load_data_interface *ld_interface =
  55. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  56. (ld_interface->nsubmitted_tasks)++;
  57. return 0;
  58. }
  59. int load_data_inc_nfinished_tasks(starpu_data_handle_t handle)
  60. {
  61. struct load_data_interface *ld_interface =
  62. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  63. (ld_interface->nfinished_tasks)++;
  64. return 0;
  65. }
  66. int load_data_next_phase(starpu_data_handle_t handle)
  67. {
  68. struct load_data_interface *ld_interface =
  69. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  70. ld_interface->phase++;
  71. return 0;
  72. }
  73. int load_data_update_elapsed_time(starpu_data_handle_t handle)
  74. {
  75. struct load_data_interface *ld_interface =
  76. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  77. ld_interface->elapsed_time = starpu_timing_now() - ld_interface->start;
  78. return 0;
  79. }
  80. double load_data_get_elapsed_time(starpu_data_handle_t handle)
  81. {
  82. struct load_data_interface *ld_interface =
  83. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  84. return ld_interface->elapsed_time;
  85. }
  86. int load_data_update_wakeup_cond(starpu_data_handle_t handle)
  87. {
  88. struct load_data_interface *ld_interface =
  89. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  90. int previous_threshold = ld_interface->wakeup_task_threshold;
  91. ld_interface->wakeup_task_threshold += (ld_interface->nsubmitted_tasks - previous_threshold) * ld_interface->wakeup_ratio;
  92. return 0;
  93. }
  94. int load_data_wakeup_cond(starpu_data_handle_t handle)
  95. {
  96. struct load_data_interface *ld_interface =
  97. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  98. return (ld_interface->wakeup_task_threshold > 0) && (ld_interface->nfinished_tasks == ld_interface->wakeup_task_threshold);
  99. }
  100. static void load_data_register_data_handle(starpu_data_handle_t handle, unsigned home_node, void *data_interface)
  101. {
  102. (void) home_node;
  103. struct load_data_interface *ld_interface = (struct load_data_interface *) data_interface;
  104. unsigned node;
  105. for (node = 0; node < STARPU_MAXNODES; node++)
  106. {
  107. struct load_data_interface *local_interface = (struct load_data_interface *)
  108. starpu_data_get_interface_on_node(handle, node);
  109. local_interface->start = ld_interface->start;
  110. local_interface->elapsed_time = ld_interface->elapsed_time;
  111. local_interface->phase = ld_interface->phase;
  112. local_interface->nsubmitted_tasks = ld_interface->nsubmitted_tasks;
  113. local_interface->nfinished_tasks = ld_interface->nsubmitted_tasks;
  114. local_interface->wakeup_task_threshold = ld_interface->wakeup_task_threshold;
  115. local_interface->wakeup_ratio = ld_interface->wakeup_ratio;
  116. local_interface->sleep_task_threshold = ld_interface->sleep_task_threshold;
  117. }
  118. }
  119. static starpu_ssize_t load_data_allocate_data_on_node(void *data_interface, unsigned node)
  120. {
  121. (void) data_interface;
  122. (void) node;
  123. return 0;
  124. }
  125. static void load_data_free_data_on_node(void *data_interface, unsigned node)
  126. {
  127. (void) data_interface;
  128. (void) node;
  129. }
  130. static size_t load_data_get_size(starpu_data_handle_t handle)
  131. {
  132. (void) handle;
  133. return sizeof(struct load_data_interface);
  134. }
  135. static uint32_t load_data_footprint(starpu_data_handle_t handle)
  136. {
  137. struct load_data_interface *ld_interface =
  138. (struct load_data_interface *) starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  139. return starpu_hash_crc32c_be(ld_interface->start,
  140. starpu_hash_crc32c_be(ld_interface->elapsed_time,
  141. starpu_hash_crc32c_be(ld_interface->nsubmitted_tasks,
  142. starpu_hash_crc32c_be(ld_interface->sleep_task_threshold, ld_interface->wakeup_task_threshold))));
  143. }
  144. static int load_data_pack_data(starpu_data_handle_t handle, unsigned node, void **ptr, starpu_ssize_t *count)
  145. {
  146. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  147. struct load_data_interface *ld_interface = (struct load_data_interface *)
  148. starpu_data_get_interface_on_node(handle, node);
  149. *count = load_data_get_size(handle);
  150. if (ptr != NULL)
  151. {
  152. char *data;
  153. starpu_malloc_flags((void**) &data, *count, 0);
  154. *ptr = data;
  155. memcpy(data, ld_interface, *count);
  156. }
  157. return 0;
  158. }
  159. static int load_data_unpack_data(starpu_data_handle_t handle, unsigned node, void *ptr, size_t count)
  160. {
  161. char *data = ptr;
  162. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  163. struct load_data_interface *ld_interface = (struct load_data_interface *)
  164. starpu_data_get_interface_on_node(handle, node);
  165. STARPU_ASSERT(count == sizeof(struct load_data_interface));
  166. memcpy(ld_interface, data, count);
  167. return 0;
  168. }
  169. static int copy_any_to_any(void *src_interface, unsigned src_node,
  170. void *dst_interface, unsigned dst_node,
  171. void *async_data)
  172. {
  173. (void) src_interface;
  174. (void) dst_interface;
  175. (void) src_node;
  176. (void) dst_node;
  177. (void) async_data;
  178. return 0;
  179. }
  180. static const struct starpu_data_copy_methods load_data_copy_methods =
  181. {
  182. .any_to_any = copy_any_to_any
  183. };
  184. static struct starpu_data_interface_ops interface_load_data_ops =
  185. {
  186. .register_data_handle = load_data_register_data_handle,
  187. .allocate_data_on_node = load_data_allocate_data_on_node,
  188. .free_data_on_node = load_data_free_data_on_node,
  189. .copy_methods = &load_data_copy_methods,
  190. .get_size = load_data_get_size,
  191. .footprint = load_data_footprint,
  192. .interfaceid = STARPU_UNKNOWN_INTERFACE_ID,
  193. .interface_size = sizeof(struct load_data_interface),
  194. .handle_to_pointer = NULL,
  195. .pack_data = load_data_pack_data,
  196. .unpack_data = load_data_unpack_data,
  197. .describe = NULL
  198. };
  199. void load_data_data_register(starpu_data_handle_t *handleptr, unsigned home_node, int sleep_task_threshold, double wakeup_ratio)
  200. {
  201. struct load_data_interface load_data =
  202. {
  203. .start = starpu_timing_now(),
  204. .elapsed_time = 0,
  205. .phase = 0,
  206. .nsubmitted_tasks = 0,
  207. .nfinished_tasks = 0,
  208. .sleep_task_threshold = sleep_task_threshold,
  209. .wakeup_task_threshold = 0,
  210. .wakeup_ratio = wakeup_ratio
  211. };
  212. if (interface_load_data_ops.interfaceid == STARPU_UNKNOWN_INTERFACE_ID)
  213. {
  214. interface_load_data_ops.interfaceid = starpu_data_interface_get_next_id();
  215. }
  216. starpu_data_register(handleptr, home_node, &load_data, &interface_load_data_ops);
  217. }
  218. #endif