starpu_mpi_insert_task_cache.c 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012 Centre National de la Recherche Scientifique
  4. * Copyright (C) 2011 Université de Bordeaux 1
  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_mpi_private.h>
  18. #include <starpu_mpi_insert_task_cache.h>
  19. typedef struct _starpu_mpi_clear_cache_s {
  20. starpu_data_handle_t data;
  21. int rank;
  22. int mode;
  23. } _starpu_mpi_clear_cache_t;
  24. struct starpu_addr_node_list **sent_data = NULL;
  25. struct starpu_addr_node_list **received_data = NULL;
  26. void _starpu_mpi_clear_cache_callback(void *callback_arg)
  27. {
  28. _starpu_mpi_clear_cache_t *clear_cache = (_starpu_mpi_clear_cache_t *)callback_arg;
  29. struct starpu_addr_node *stored_node = starpu_addr_node_new();
  30. if (clear_cache->mode == _STARPU_MPI_CLEAR_SENT_DATA) {
  31. _STARPU_MPI_DEBUG("Clearing sent cache for data %p and rank %d\n", clear_cache->data, clear_cache->rank);
  32. /* TODO: the implementation should be careful about freed memory. */
  33. stored_node->ndata = (uintptr_t)clear_cache->data;
  34. starpu_addr_node_list_push_front(sent_data[clear_cache->rank], stored_node);
  35. }
  36. else if (clear_cache->mode == _STARPU_MPI_CLEAR_RECEIVED_DATA) {
  37. _STARPU_MPI_DEBUG("Clearing received cache for data %p and rank %d\n", clear_cache->data, clear_cache->rank);
  38. stored_node->ndata = (uintptr_t)clear_cache->data;
  39. starpu_addr_node_list_push_front(received_data[clear_cache->rank], stored_node);
  40. }
  41. free(clear_cache);
  42. }
  43. double _starpu_mpi_clear_cache_cost_function(struct starpu_task *task, unsigned nimpl)
  44. {
  45. return 0;
  46. }
  47. static struct starpu_perfmodel _starpu_mpi_clear_cache_model =
  48. {
  49. .cost_function = _starpu_mpi_clear_cache_cost_function,
  50. .type = STARPU_COMMON,
  51. };
  52. static void _starpu_mpi_clear_cache_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  53. {
  54. }
  55. static struct starpu_codelet _starpu_mpi_clear_cache_codelet =
  56. {
  57. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  58. .cpu_funcs = {_starpu_mpi_clear_cache_func, NULL},
  59. .cuda_funcs = {_starpu_mpi_clear_cache_func, NULL},
  60. .opencl_funcs = {_starpu_mpi_clear_cache_func, NULL},
  61. .nbuffers = 1,
  62. .modes = {STARPU_RW},
  63. .model = &_starpu_mpi_clear_cache_model
  64. // The model has a cost function which returns 0 so as to allow the codelet to be scheduled anywhere
  65. };
  66. void _starpu_mpi_clear_cache_request(starpu_data_handle_t data_handle, int rank, int mode)
  67. {
  68. struct starpu_task *task = starpu_task_create();
  69. // We have a codelet with a empty function just to force the
  70. // task being created to have a dependency on data_handle
  71. task->cl = &_starpu_mpi_clear_cache_codelet;
  72. task->handles[0] = data_handle;
  73. _starpu_mpi_clear_cache_t *clear_cache = malloc(sizeof(_starpu_mpi_clear_cache_t));
  74. clear_cache->data = data_handle;
  75. clear_cache->rank = rank;
  76. clear_cache->mode = mode;
  77. task->callback_func = _starpu_mpi_clear_cache_callback;
  78. task->callback_arg = clear_cache;
  79. int ret = starpu_task_submit(task);
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  81. }