datawizard.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2018 Université de Bordeaux
  4. * Copyright (C) 2010-2011,2013,2015,2017 CNRS
  5. * Copyright (C) 2017 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include <common/config.h>
  20. #include <datawizard/datawizard.h>
  21. #include <datawizard/memalloc.h>
  22. #include <datawizard/memory_nodes.h>
  23. #include <core/workers.h>
  24. #include <core/progress_hook.h>
  25. #include <core/topology.h>
  26. #ifdef STARPU_SIMGRID
  27. #include <core/simgrid.h>
  28. #endif
  29. int ___starpu_datawizard_progress(unsigned memory_node, unsigned may_alloc, unsigned push_requests)
  30. {
  31. int ret = 0;
  32. #ifdef STARPU_SIMGRID
  33. /* XXX */
  34. MSG_process_sleep(0.000001);
  35. #endif
  36. STARPU_UYIELD();
  37. /* in case some other driver requested data */
  38. if (_starpu_handle_pending_node_data_requests(memory_node))
  39. ret = 1;
  40. starpu_memchunk_tidy(memory_node);
  41. if (ret || push_requests)
  42. {
  43. /* Some transfers have finished, or the driver requests to really push more */
  44. unsigned pushed;
  45. if (_starpu_handle_node_data_requests(memory_node, may_alloc, &pushed) == 0)
  46. {
  47. if (pushed)
  48. ret = 1;
  49. /* We pushed all pending requests, we can afford pushing
  50. * prefetch requests */
  51. _starpu_handle_node_prefetch_requests(memory_node, may_alloc, &pushed);
  52. if (_starpu_check_that_no_data_request_is_pending(memory_node))
  53. /* No pending transfer, push some idle transfer */
  54. _starpu_handle_node_idle_requests(memory_node, may_alloc, &pushed);
  55. }
  56. if (pushed)
  57. ret = 1;
  58. }
  59. _starpu_execute_registered_progression_hooks();
  60. return ret;
  61. }
  62. int __starpu_datawizard_progress(unsigned may_alloc, unsigned push_requests)
  63. {
  64. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  65. unsigned memnode;
  66. if (!worker)
  67. {
  68. /* Call from main application, only make RAM requests progress */
  69. int ret = 0;
  70. int nnumas = starpu_memory_nodes_get_numa_count();
  71. int numa;
  72. for (numa = 0; numa < nnumas; numa++)
  73. ret |= ___starpu_datawizard_progress(numa, may_alloc, push_requests);
  74. return ret;
  75. }
  76. if (worker->set)
  77. /* Runing one of the workers of a worker set. The reference for
  78. * driving memory is its worker 0 (see registrations in topology.c) */
  79. worker = &worker->set->workers[0];
  80. unsigned current_worker_id = worker->workerid;
  81. int ret = 0;
  82. unsigned nnodes = starpu_memory_nodes_get_count();
  83. for (memnode = 0; memnode < nnodes; memnode++)
  84. {
  85. if (_starpu_worker_drives_memory[current_worker_id][memnode] == 1)
  86. ret |= ___starpu_datawizard_progress(memnode, may_alloc, push_requests);
  87. }
  88. return ret;
  89. }
  90. void _starpu_datawizard_progress(unsigned may_alloc)
  91. {
  92. __starpu_datawizard_progress(may_alloc, 1);
  93. }