starpu_mpi_insert_task_cache.c 3.4 KB

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