starpu_disk.h 7.5 KB

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