datawizard.c 3.1 KB

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