starpu_mpi_insert_task_cache.c 3.4 KB

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