data_request.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-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. /** @file */
  17. /* This one includes us, so make sure to include it first */
  18. #include <datawizard/coherency.h>
  19. #ifndef __DATA_REQUEST_H__
  20. #define __DATA_REQUEST_H__
  21. #include <semaphore.h>
  22. #include <datawizard/copy_driver.h>
  23. #include <common/list.h>
  24. #include <common/prio_list.h>
  25. #include <common/starpu_spinlock.h>
  26. #pragma GCC visibility push(hidden)
  27. /* TODO: This should be tuned according to driver capabilities
  28. * Data interfaces should also have to declare how many asynchronous requests
  29. * they have actually started (think of e.g. csr).
  30. */
  31. #define MAX_PENDING_REQUESTS_PER_NODE 5
  32. #define MAX_PENDING_PREFETCH_REQUESTS_PER_NODE 2
  33. #define MAX_PENDING_IDLE_REQUESTS_PER_NODE 1
  34. /** Maximum time in us that we can afford pushing requests before going back to the driver loop, e.g. for checking GPU task termination */
  35. #define MAX_PUSH_TIME 1000
  36. struct _starpu_data_replicate;
  37. struct _starpu_callback_list
  38. {
  39. void (*callback_func)(void *);
  40. void *callback_arg;
  41. struct _starpu_callback_list *next;
  42. };
  43. enum _starpu_data_request_inout
  44. {
  45. _STARPU_DATA_REQUEST_IN, _STARPU_DATA_REQUEST_OUT
  46. };
  47. /** This represents a data request, i.e. we want some data to get transferred
  48. * from a source to a destination. */
  49. LIST_TYPE(_starpu_data_request,
  50. struct _starpu_spinlock lock;
  51. unsigned refcnt;
  52. const char *origin; /** Name of the function that triggered the request */
  53. starpu_data_handle_t handle;
  54. struct _starpu_data_replicate *src_replicate;
  55. struct _starpu_data_replicate *dst_replicate;
  56. /** Which memory node will actually perform the transfer.
  57. * This is important in the CUDA/OpenCL case, where only the worker for
  58. * the node can make the CUDA/OpenCL calls.
  59. */
  60. unsigned handling_node;
  61. unsigned peer_node;
  62. enum _starpu_data_request_inout inout;
  63. /*
  64. * What the destination node wants to do with the data: write to it,
  65. * read it, or read and write to it. Only in the two latter cases we
  66. * need an actual transfer, the first only needs an allocation.
  67. *
  68. * With mapped buffers, an additional case is mode = 0, which means
  69. * unmapping the buffer.
  70. */
  71. enum starpu_data_access_mode mode;
  72. /** Elements needed to make the transfer asynchronous */
  73. struct _starpu_async_channel async_channel;
  74. /** Whether the transfer is completed. */
  75. unsigned completed:1;
  76. /** Whether we have already added our reference to the dst replicate. */
  77. unsigned added_ref:1;
  78. /** Whether the request was canceled before being handled (because the transfer already happened another way). */
  79. unsigned canceled:2;
  80. /** Whether this is just a prefetch request */
  81. enum starpu_is_prefetch prefetch:3;
  82. /** Task this request is for */
  83. struct starpu_task *task;
  84. /** Number of tasks which used this as a prefetch */
  85. unsigned nb_tasks_prefetch;
  86. /** Priority of the request. Default is 0 */
  87. int prio;
  88. /** The value returned by the transfer function */
  89. int retval;
  90. /** The request will not actually be submitted until there remains
  91. * dependencies. */
  92. unsigned ndeps;
  93. /** Some further tasks may have requested prefetches for the same data
  94. * much later on, link with them */
  95. struct _starpu_data_request *next_same_req;
  96. /** in case we have a chain of request (eg. for nvidia multi-GPU), this
  97. * is the list of requests which are waiting for this one. */
  98. struct _starpu_data_request *next_req[STARPU_MAXNODES+1];
  99. /** The number of requests in next_req */
  100. unsigned next_req_count;
  101. struct _starpu_callback_list *callbacks;
  102. unsigned long com_id;
  103. )
  104. PRIO_LIST_TYPE(_starpu_data_request, prio)
  105. /** Everyone that wants to access some piece of data will post a request.
  106. * Not only StarPU internals, but also the application may put such requests */
  107. LIST_TYPE(_starpu_data_requester,
  108. /** what kind of access is requested ? */
  109. enum starpu_data_access_mode mode;
  110. /** applications may also directly manipulate data */
  111. unsigned is_requested_by_codelet;
  112. /** in case this is a codelet that will do the access */
  113. struct _starpu_job *j;
  114. unsigned buffer_index;
  115. int prio;
  116. /** if this is more complicated ... (eg. application request)
  117. * NB: this callback is not called with the lock taken !
  118. */
  119. void (*ready_data_callback)(void *argcb);
  120. void *argcb;
  121. )
  122. PRIO_LIST_TYPE(_starpu_data_requester, prio)
  123. void _starpu_init_data_request_lists(void);
  124. void _starpu_deinit_data_request_lists(void);
  125. void _starpu_post_data_request(struct _starpu_data_request *r);
  126. /** returns 0 if we have pushed all requests, -EBUSY or -ENOMEM otherwise */
  127. int _starpu_handle_node_data_requests(unsigned handling_node, unsigned peer_node, enum _starpu_data_request_inout inout, enum _starpu_may_alloc may_alloc, unsigned *pushed);
  128. int _starpu_handle_node_prefetch_requests(unsigned handling_node, unsigned peer_node, enum _starpu_data_request_inout inout, enum _starpu_may_alloc may_alloc, unsigned *pushed);
  129. int _starpu_handle_node_idle_requests(unsigned handling_node, unsigned peer_node, enum _starpu_data_request_inout inout, enum _starpu_may_alloc may_alloc, unsigned *pushed);
  130. int _starpu_handle_pending_node_data_requests(unsigned handling_node, unsigned peer_node, enum _starpu_data_request_inout inout);
  131. int _starpu_handle_all_pending_node_data_requests(unsigned handling_node, unsigned peer_node, enum _starpu_data_request_inout inout);
  132. int _starpu_check_that_no_data_request_exists(unsigned handling_node);
  133. int _starpu_check_that_no_data_request_is_pending(unsigned handling_node, unsigned peer_node, enum _starpu_data_request_inout inout);
  134. struct _starpu_data_request *_starpu_create_data_request(starpu_data_handle_t handle,
  135. struct _starpu_data_replicate *src_replicate,
  136. struct _starpu_data_replicate *dst_replicate,
  137. int handling_node,
  138. enum starpu_data_access_mode mode,
  139. unsigned ndeps,
  140. struct starpu_task *task,
  141. enum starpu_is_prefetch is_prefetch,
  142. int prio,
  143. unsigned is_write_invalidation,
  144. const char *origin) STARPU_ATTRIBUTE_MALLOC;
  145. int _starpu_wait_data_request_completion(struct _starpu_data_request *r, enum _starpu_may_alloc may_alloc);
  146. void _starpu_data_request_append_callback(struct _starpu_data_request *r,
  147. void (*callback_func)(void *),
  148. void *callback_arg);
  149. void _starpu_update_prefetch_status(struct _starpu_data_request *r, enum starpu_is_prefetch prefetch);
  150. #pragma GCC visibility pop
  151. #endif // __DATA_REQUEST_H__