data_request.h 5.2 KB

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