data_request.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2020 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 20
  31. #define MAX_PENDING_PREFETCH_REQUESTS_PER_NODE 10
  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. /** This represents a data request, i.e. we want some data to get transferred
  43. * from a source to a destination. */
  44. LIST_TYPE(_starpu_data_request,
  45. struct _starpu_spinlock lock;
  46. unsigned refcnt;
  47. const char *origin; /** Name of the function that triggered the request */
  48. starpu_data_handle_t handle;
  49. struct _starpu_data_replicate *src_replicate;
  50. struct _starpu_data_replicate *dst_replicate;
  51. /** Which memory node will actually perform the transfer.
  52. * This is important in the CUDA/OpenCL case, where only the worker for
  53. * the node can make the CUDA/OpenCL calls.
  54. */
  55. unsigned handling_node;
  56. /*
  57. * What the destination node wants to do with the data: write to it,
  58. * read it, or read and write to it. Only in the two latter cases we
  59. * need an actual transfer, the first only needs an allocation.
  60. *
  61. * With mapped buffers, an additional case is mode = 0, which means
  62. * unmapping the buffer.
  63. */
  64. enum starpu_data_access_mode mode;
  65. /** Elements needed to make the transfer asynchronous */
  66. struct _starpu_async_channel async_channel;
  67. /** Whether the transfer is completed. */
  68. unsigned completed;
  69. /** Whether this is just a prefetch request */
  70. enum _starpu_is_prefetch prefetch;
  71. /** Number of tasks which used this as a prefetch */
  72. unsigned nb_tasks_prefetch;
  73. /** Priority of the request. Default is 0 */
  74. int prio;
  75. /** The value returned by the transfer function */
  76. int retval;
  77. /** The request will not actually be submitted until there remains
  78. * dependencies. */
  79. unsigned ndeps;
  80. /** in case we have a chain of request (eg. for nvidia multi-GPU), this
  81. * is the list of requests which are waiting for this one. */
  82. struct _starpu_data_request *next_req[STARPU_MAXNODES+1];
  83. /** The number of requests in next_req */
  84. unsigned next_req_count;
  85. struct _starpu_callback_list *callbacks;
  86. unsigned long com_id;
  87. )
  88. PRIO_LIST_TYPE(_starpu_data_request, prio)
  89. /** Everyone that wants to access some piece of data will post a request.
  90. * Not only StarPU internals, but also the application may put such requests */
  91. LIST_TYPE(_starpu_data_requester,
  92. /** what kind of access is requested ? */
  93. enum starpu_data_access_mode mode;
  94. /** applications may also directly manipulate data */
  95. unsigned is_requested_by_codelet;
  96. /** in case this is a codelet that will do the access */
  97. struct _starpu_job *j;
  98. unsigned buffer_index;
  99. int prio;
  100. /** if this is more complicated ... (eg. application request)
  101. * NB: this callback is not called with the lock taken !
  102. */
  103. void (*ready_data_callback)(void *argcb);
  104. void *argcb;
  105. )
  106. PRIO_LIST_TYPE(_starpu_data_requester, prio)
  107. void _starpu_init_data_request_lists(void);
  108. void _starpu_deinit_data_request_lists(void);
  109. void _starpu_post_data_request(struct _starpu_data_request *r);
  110. /** returns 0 if we have pushed all requests, -EBUSY or -ENOMEM otherwise */
  111. int _starpu_handle_node_data_requests(unsigned src_node, unsigned may_alloc, unsigned *pushed);
  112. int _starpu_handle_node_prefetch_requests(unsigned src_node, unsigned may_alloc, unsigned *pushed);
  113. int _starpu_handle_node_idle_requests(unsigned src_node, unsigned may_alloc, unsigned *pushed);
  114. int _starpu_handle_pending_node_data_requests(unsigned src_node);
  115. int _starpu_handle_all_pending_node_data_requests(unsigned src_node);
  116. int _starpu_check_that_no_data_request_exists(unsigned node);
  117. int _starpu_check_that_no_data_request_is_pending(unsigned node);
  118. struct _starpu_data_request *_starpu_create_data_request(starpu_data_handle_t handle,
  119. struct _starpu_data_replicate *src_replicate,
  120. struct _starpu_data_replicate *dst_replicate,
  121. int handling_node,
  122. enum starpu_data_access_mode mode,
  123. unsigned ndeps,
  124. enum _starpu_is_prefetch is_prefetch,
  125. int prio,
  126. unsigned is_write_invalidation,
  127. const char *origin) STARPU_ATTRIBUTE_MALLOC;
  128. int _starpu_wait_data_request_completion(struct _starpu_data_request *r, unsigned may_alloc);
  129. void _starpu_data_request_append_callback(struct _starpu_data_request *r,
  130. void (*callback_func)(void *),
  131. void *callback_arg);
  132. void _starpu_update_prefetch_status(struct _starpu_data_request *r, enum _starpu_is_prefetch prefetch);
  133. #endif // __DATA_REQUEST_H__