write_back.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  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 <datawizard/datawizard.h>
  18. #include <datawizard/write_back.h>
  19. #include <core/dependencies/data_concurrency.h>
  20. static void wt_callback(void *arg) {
  21. starpu_data_handle handle = (starpu_data_handle) arg;
  22. _starpu_spin_lock(&handle->header_lock);
  23. _starpu_notify_data_dependencies(handle);
  24. _starpu_spin_unlock(&handle->header_lock);
  25. }
  26. void _starpu_write_through_data(starpu_data_handle handle, uint32_t requesting_node,
  27. uint32_t write_through_mask)
  28. {
  29. if ((write_through_mask & ~(1<<requesting_node)) == 0) {
  30. /* nothing will be done ... */
  31. return;
  32. }
  33. /* first commit all changes onto the nodes specified by the mask */
  34. uint32_t node;
  35. for (node = 0; node < STARPU_MAXNODES; node++)
  36. {
  37. if (write_through_mask & (1<<node)) {
  38. /* we need to commit the buffer on that node */
  39. if (node != requesting_node)
  40. {
  41. while (_starpu_spin_trylock(&handle->header_lock))
  42. _starpu_datawizard_progress(requesting_node, 1);
  43. starpu_data_request_t r;
  44. r = create_request_to_fetch_data(handle, &handle->per_node[node],
  45. STARPU_R, 1, wt_callback, handle);
  46. /* If no request was created, the handle was already up-to-date on the
  47. * node */
  48. if (r)
  49. {
  50. /* Pending request, keep a Read lock */
  51. STARPU_ASSERT(handle->current_mode != STARPU_REDUX);
  52. STARPU_ASSERT(handle->current_mode != STARPU_SCRATCH);
  53. handle->refcnt++;
  54. handle->current_mode = STARPU_R;
  55. _starpu_spin_unlock(&handle->header_lock);
  56. }
  57. }
  58. }
  59. }
  60. }
  61. void starpu_data_set_wt_mask(starpu_data_handle handle, uint32_t wt_mask)
  62. {
  63. handle->wt_mask = wt_mask;
  64. /* in case the data has some children, set their wt_mask as well */
  65. if (handle->nchildren > 0)
  66. {
  67. unsigned child;
  68. for (child = 0; child < handle->nchildren; child++)
  69. starpu_data_set_wt_mask(&handle->children[child], wt_mask);
  70. }
  71. }