datawizard.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU 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. * StarPU 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 <starpu.h>
  17. #include <common/config.h>
  18. #include <datawizard/datawizard.h>
  19. #include <datawizard/memalloc.h>
  20. #include <datawizard/memory_nodes.h>
  21. #include <core/workers.h>
  22. #include <core/progress_hook.h>
  23. #include <core/topology.h>
  24. #ifdef STARPU_SIMGRID
  25. #include <core/simgrid.h>
  26. #endif
  27. int ___starpu_datawizard_progress(unsigned memory_node, unsigned peer_node, enum _starpu_data_request_inout inout, unsigned may_alloc, unsigned push_requests)
  28. {
  29. int ret = 0;
  30. #ifdef STARPU_SIMGRID
  31. /* XXX */
  32. starpu_sleep(0.000001);
  33. #endif
  34. STARPU_UYIELD();
  35. /* in case some other driver requested data */
  36. if (_starpu_handle_pending_node_data_requests(memory_node, peer_node, inout))
  37. ret = 1;
  38. starpu_memchunk_tidy(memory_node);
  39. if (ret || push_requests)
  40. {
  41. /* Some transfers have finished, or the driver requests to really push more */
  42. unsigned pushed;
  43. if (_starpu_handle_node_data_requests(memory_node, peer_node, inout, may_alloc, &pushed) == 0)
  44. {
  45. if (pushed)
  46. ret = 1;
  47. /* We pushed all pending requests, we can afford pushing
  48. * prefetch requests */
  49. _starpu_handle_node_prefetch_requests(memory_node, peer_node, inout, may_alloc, &pushed);
  50. if (_starpu_check_that_no_data_request_is_pending(memory_node, peer_node, inout))
  51. /* No pending transfer, push some idle transfer */
  52. _starpu_handle_node_idle_requests(memory_node, peer_node, inout, may_alloc, &pushed);
  53. }
  54. if (pushed)
  55. ret = 1;
  56. }
  57. _starpu_execute_registered_progression_hooks();
  58. return ret;
  59. }
  60. int __starpu_datawizard_progress(unsigned may_alloc, unsigned push_requests)
  61. {
  62. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  63. unsigned memnode, memnode2;
  64. if (!worker)
  65. {
  66. /* Call from main application, only make RAM requests progress */
  67. int ret = 0;
  68. int nnumas = starpu_memory_nodes_get_numa_count();
  69. int numa, numa2;
  70. for (numa = 0; numa < nnumas; numa++)
  71. for (numa2 = 0; numa2 < nnumas; numa2++)
  72. {
  73. ret |= ___starpu_datawizard_progress(numa, numa2, _STARPU_DATA_REQUEST_IN, may_alloc, push_requests);
  74. ret |= ___starpu_datawizard_progress(numa, numa2, _STARPU_DATA_REQUEST_OUT, may_alloc, push_requests);
  75. }
  76. return ret;
  77. }
  78. if (worker->set)
  79. /* Runing one of the workers of a worker set. The reference for
  80. * driving memory is its worker 0 (see registrations in topology.c) */
  81. worker = &worker->set->workers[0];
  82. unsigned current_worker_id = worker->workerid;
  83. int ret = 0;
  84. unsigned nnodes = starpu_memory_nodes_get_count();
  85. for (memnode = 0; memnode < nnodes; memnode++)
  86. {
  87. if (_starpu_worker_drives_memory[current_worker_id][memnode] == 1)
  88. for (memnode2 = 0; memnode2 < nnodes; memnode2++)
  89. {
  90. ret |= ___starpu_datawizard_progress(memnode, memnode2, _STARPU_DATA_REQUEST_IN, may_alloc, push_requests);
  91. ret |= ___starpu_datawizard_progress(memnode, memnode2, _STARPU_DATA_REQUEST_OUT, may_alloc, push_requests);
  92. }
  93. }
  94. return ret;
  95. }
  96. void _starpu_datawizard_progress(unsigned may_alloc)
  97. {
  98. __starpu_datawizard_progress(may_alloc, 1);
  99. }
  100. void _starpu_datawizard_handle_all_pending_node_data_requests(unsigned memnode)
  101. {
  102. unsigned nnodes = starpu_memory_nodes_get_count();
  103. unsigned memnode2;
  104. for (memnode2 = 0; memnode2 < nnodes; memnode2++)
  105. {
  106. _starpu_handle_all_pending_node_data_requests(memnode, memnode2, _STARPU_DATA_REQUEST_IN);
  107. _starpu_handle_all_pending_node_data_requests(memnode, memnode2, _STARPU_DATA_REQUEST_OUT);
  108. }
  109. }