starpu_mpi_insert_task_cache.c 3.5 KB

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