write_back.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <datawizard/write_back.h>
  17. #include <datawizard/coherency.h>
  18. void write_through_data(starpu_data_handle handle, uint32_t requesting_node,
  19. uint32_t write_through_mask)
  20. {
  21. if ((write_through_mask & ~(1<<requesting_node)) == 0) {
  22. /* nothing will be done ... */
  23. return;
  24. }
  25. while (starpu_spin_trylock(&handle->header_lock))
  26. _starpu_datawizard_progress(requesting_node, 1);
  27. /* first commit all changes onto the nodes specified by the mask */
  28. uint32_t node;
  29. for (node = 0; node < MAXNODES; node++)
  30. {
  31. if (write_through_mask & (1<<node)) {
  32. /* we need to commit the buffer on that node */
  33. if (node != requesting_node)
  34. {
  35. uint32_t handling_node =
  36. select_node_to_handle_request(requesting_node, node);
  37. data_request_t r;
  38. /* check that there is not already a similar
  39. * request that we should reuse */
  40. r = search_existing_data_request(handle, node, 1, 0);
  41. if (!r) {
  42. /* there was no existing request so we create one now */
  43. r = create_data_request(handle, requesting_node,
  44. node, handling_node, 1, 0, 1);
  45. post_data_request(r, handling_node);
  46. }
  47. else {
  48. /* if there is already a similar request, it is
  49. * useless to post another one */
  50. starpu_spin_unlock(&r->lock);
  51. }
  52. }
  53. }
  54. }
  55. starpu_spin_unlock(&handle->header_lock);
  56. }
  57. void starpu_data_set_wb_mask(starpu_data_handle handle, uint32_t wb_mask)
  58. {
  59. handle->wb_mask = wb_mask;
  60. /* in case the data has some children, set their wb_mask as well */
  61. if (handle->nchildren > 0)
  62. {
  63. unsigned child;
  64. for (child = 0; child < handle->nchildren; child++)
  65. starpu_data_set_wb_mask(&handle->children[child], wb_mask);
  66. }
  67. }