starpu_disk.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Corentin Salingue
  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. #ifndef __STARPU_DISK_H__
  18. #define __STARPU_DISK_H__
  19. #include <sys/types.h>
  20. #include <starpu_config.h>
  21. /**
  22. @defgroup API_Out_Of_Core Out Of Core
  23. @{
  24. */
  25. /**
  26. Set of functions to manipulate datas on disk.
  27. */
  28. struct starpu_disk_ops
  29. {
  30. /**
  31. Connect a disk memory at location \p parameter with size \p size, and return a
  32. base as void*, which will be passed by StarPU to all other methods.
  33. */
  34. void * (*plug) (void *parameter, starpu_ssize_t size);
  35. /**
  36. Disconnect a disk memory \p base.
  37. */
  38. void (*unplug) (void *base);
  39. /**
  40. Measure the bandwidth and the latency for the disk \p node and save it. Returns
  41. 1 if it could measure it.
  42. */
  43. int (*bandwidth) (unsigned node, void *base);
  44. /**
  45. Create a new location for datas of size \p size. Return an opaque object pointer.
  46. */
  47. void * (*alloc) (void *base, size_t size);
  48. /**
  49. Free a data \p obj previously allocated with starpu_disk_ops::alloc.
  50. */
  51. void (*free) (void *base, void *obj, size_t size);
  52. /**
  53. Open an existing location of datas, at a specific position \p pos dependent on the backend.
  54. */
  55. void * (*open) (void *base, void *pos, size_t size);
  56. /**
  57. Close, without deleting it, a location of datas \p obj.
  58. */
  59. void (*close) (void *base, void *obj, size_t size);
  60. /**
  61. Read \p size bytes of data from \p obj in \p base, at offset \p offset, and put
  62. into \p buf. Return the actual number of read bytes.
  63. */
  64. int (*read) (void *base, void *obj, void *buf, off_t offset, size_t size);
  65. /**
  66. Write \p size bytes of data to \p obj in \p base, at offset \p offset, from \p buf. Return 0 on success.
  67. */
  68. int (*write) (void *base, void *obj, const void *buf, off_t offset, size_t size);
  69. /**
  70. Read all data from \p obj of \p base, from offset 0. Returns it in an allocated buffer \p ptr, of size \p size
  71. */
  72. int (*full_read) (void * base, void * obj, void ** ptr, size_t * size, unsigned dst_node);
  73. /**
  74. Write data in \p ptr to \p obj of \p base, from offset 0, and truncate \p obj to
  75. \p size, so that a \c full_read will get it.
  76. */
  77. int (*full_write) (void * base, void * obj, void * ptr, size_t size);
  78. /**
  79. Asynchronously write \p size bytes of data to \p obj in \p base, at offset \p
  80. offset, from \p buf. Return a void* pointer that StarPU will pass to \c
  81. xxx_request methods for testing for the completion.
  82. */
  83. void * (*async_write) (void *base, void *obj, void *buf, off_t offset, size_t size);
  84. /**
  85. Asynchronously read \p size bytes of data from \p obj in \p base, at offset \p
  86. offset, and put into \p buf. Return a void* pointer that StarPU will pass to \c
  87. xxx_request methods for testing for the completion.
  88. */
  89. void * (*async_read) (void *base, void *obj, void *buf, off_t offset, size_t size);
  90. /**
  91. Read all data from \p obj of \p base, from offset 0. Return it in an allocated buffer \p ptr, of size \p size
  92. */
  93. void * (*async_full_read) (void * base, void * obj, void ** ptr, size_t * size, unsigned dst_node);
  94. /**
  95. Write data in \p ptr to \p obj of \p base, from offset 0, and truncate \p obj to
  96. \p size, so that a starpu_disk_ops::full_read will get it.
  97. */
  98. void * (*async_full_write) (void * base, void * obj, void * ptr, size_t size);
  99. /**
  100. Copy from offset \p offset_src of disk object \p obj_src in \p base_src to
  101. offset \p offset_dst of disk object \p obj_dst in \p base_dst. Return a void*
  102. pointer that StarPU will pass to \c xxx_request methods for testing for the
  103. completion.
  104. */
  105. void * (*copy) (void *base_src, void* obj_src, off_t offset_src, void *base_dst, void* obj_dst, off_t offset_dst, size_t size);
  106. /**
  107. Wait for completion of request \p async_channel returned by a previous
  108. asynchronous read, write or copy.
  109. */
  110. void (*wait_request) (void * async_channel);
  111. /**
  112. Test for completion of request \p async_channel returned by a previous
  113. asynchronous read, write or copy. Return 1 on completion, 0 otherwise.
  114. */
  115. int (*test_request) (void * async_channel);
  116. /**
  117. Free the request allocated by a previous asynchronous read, write or copy.
  118. */
  119. void (*free_request)(void * async_channel);
  120. /* TODO: readv, writev, read2d, write2d, etc. */
  121. };
  122. /**
  123. Use the stdio library (fwrite, fread...) to read/write on disk.
  124. <strong>Warning: It creates one file per allocation !</strong>
  125. Do not support asynchronous transfers.
  126. */
  127. extern struct starpu_disk_ops starpu_disk_stdio_ops;
  128. /**
  129. Use the HDF5 library.
  130. <strong>It doesn't support multiple opening from different processes. </strong>
  131. You may only allow one process to write in the HDF5 file.
  132. <strong>If HDF5 library is not compiled with --thread-safe you can't open more than one HDF5 file at the same time. </strong>
  133. */
  134. extern struct starpu_disk_ops starpu_disk_hdf5_ops;
  135. /**
  136. Use the unistd library (write, read...) to read/write on disk.
  137. <strong>Warning: It creates one file per allocation !</strong>
  138. */
  139. extern struct starpu_disk_ops starpu_disk_unistd_ops;
  140. /**
  141. Use the unistd library (write, read...) to read/write on disk with the O_DIRECT flag.
  142. <strong>Warning: It creates one file per allocation !</strong>
  143. Only available on Linux systems.
  144. */
  145. extern struct starpu_disk_ops starpu_disk_unistd_o_direct_ops;
  146. /**
  147. Use the leveldb created by Google. More information at https://code.google.com/p/leveldb/
  148. Do not support asynchronous transfers.
  149. */
  150. extern struct starpu_disk_ops starpu_disk_leveldb_ops;
  151. /**
  152. Close an existing data opened with starpu_disk_open().
  153. */
  154. void starpu_disk_close(unsigned node, void *obj, size_t size);
  155. /**
  156. Open an existing file memory in a disk node. \p size is the size of
  157. the file. \p pos is the specific position dependent on the backend,
  158. given to the \c open method of the disk operations. Return an
  159. opaque object pointer.
  160. */
  161. void *starpu_disk_open(unsigned node, void *pos, size_t size);
  162. /**
  163. Register a disk memory node with a set of functions to manipulate
  164. datas. The \c plug member of \p func will be passed \p parameter,
  165. and return a \c base which will be passed to all \p func methods.
  166. <br />
  167. SUCCESS: return the disk node. <br />
  168. FAIL: return an error code. <br />
  169. \p size must be at least \ref STARPU_DISK_SIZE_MIN bytes ! \p size
  170. being negative means infinite size.
  171. */
  172. int starpu_disk_register(struct starpu_disk_ops *func, void *parameter, starpu_ssize_t size);
  173. /**
  174. Minimum size of a registered disk. The size of a disk is the last
  175. parameter of the function starpu_disk_register().
  176. */
  177. #define STARPU_DISK_SIZE_MIN (16*1024*1024)
  178. /**
  179. Contain the node number of the disk swap, if set up through the
  180. \ref STARPU_DISK_SWAP variable.
  181. */
  182. extern int starpu_disk_swap_node;
  183. /** @} */
  184. #endif /* __STARPU_DISK_H__ */