data_request.h 6.8 KB

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