command.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 Inria
  4. * Copyright (C) 2012,2017 CNRS
  5. * Copyright (C) 2010-2011,2013 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include "socl.h"
  19. #ifndef SOCL_COMMANDS_H
  20. #define SOCL_COMMANDS_H
  21. typedef struct cl_command_t * cl_command;
  22. #define gc_entity_store_cmd(dest,cmd) gc_entity_store(dest, &cmd->_command)
  23. #define gc_entity_release_cmd(cmd) gc_entity_release(&cmd->_command)
  24. /**
  25. * Initialize a command structure
  26. *
  27. * Command constructors for each kind of command use this method
  28. * Implicit and explicit dependencies must be passed as parameters
  29. */
  30. void command_init_ex(cl_command cmd, cl_command_type typ, void (*cb)(void*));
  31. #define command_init(cmd,typ,cb) \
  32. command_init_ex((cl_command)cmd,typ,cb)
  33. void command_release(cl_command cmd);
  34. /** Submit a command for execution */
  35. void command_submit_ex(cl_command cmd);
  36. #define command_submit(cmd) \
  37. command_submit_ex(&(cmd)->_command)
  38. /** Submit a command and its dependencies */
  39. cl_int command_submit_deep_ex(cl_command cmd);
  40. #define command_submit_deep(cmd) (command_submit_deep_ex((cl_command)cmd))
  41. void command_graph_dump_ex(cl_command cmd);
  42. #define command_graph_dump(cmd) (command_graph_dump_ex((cl_command)cmd))
  43. /**************************
  44. * OpenCL Commands
  45. **************************/
  46. struct cl_command_t
  47. {
  48. CL_ENTITY;
  49. cl_command_type typ; /* Command type */
  50. cl_uint num_events; /* Number of dependencies */
  51. cl_event * events; /* Dependencies */
  52. cl_event event; /* Event for this command */
  53. starpu_task task; /* Associated StarPU task, if any */
  54. char submitted; /* True if the command has been submitted to StarPU */
  55. void (*release_callback)(void*); /* Command specific destructor */
  56. };
  57. #define command_type_get(cmd) (((cl_command)cmd)->typ)
  58. cl_event command_event_get_ex(cl_command cmd);
  59. #define command_event_get(cmd) command_event_get_ex(&cmd->_command)
  60. #define command_num_events_get_ex(cmd) (cmd->num_events)
  61. #define command_num_events_get(cmd) ((cmd)->_command.num_events)
  62. #define command_events_get_ex(cmd) ((cmd)->events)
  63. #define command_events_get(cmd) ((cmd)->_command.events)
  64. #define command_task_get(cmd) ((cmd)->_command.task)
  65. #define command_cq_get(cmd) ((cmd)->_command.cq)
  66. #define CL_COMMAND struct cl_command_t _command;
  67. typedef struct command_ndrange_kernel_t
  68. {
  69. CL_COMMAND
  70. cl_kernel kernel;
  71. struct starpu_codelet codelet;
  72. cl_uint work_dim;
  73. const size_t * global_work_offset;
  74. const size_t * global_work_size;
  75. const size_t * local_work_size;
  76. cl_uint num_args;
  77. size_t * arg_sizes;
  78. enum kernel_arg_type * arg_types;
  79. void ** args;
  80. cl_uint num_buffers;
  81. cl_mem * buffers;
  82. } * command_ndrange_kernel;
  83. typedef struct command_read_buffer_t
  84. {
  85. CL_COMMAND
  86. cl_mem buffer;
  87. size_t offset;
  88. size_t cb;
  89. void * ptr;
  90. } * command_read_buffer;
  91. typedef struct command_write_buffer_t
  92. {
  93. CL_COMMAND
  94. cl_mem buffer;
  95. size_t offset;
  96. size_t cb;
  97. const void * ptr;
  98. } * command_write_buffer;
  99. typedef struct command_copy_buffer_t
  100. {
  101. CL_COMMAND
  102. cl_mem src_buffer;
  103. cl_mem dst_buffer;
  104. size_t src_offset;
  105. size_t dst_offset;
  106. size_t cb;
  107. } * command_copy_buffer;
  108. typedef struct command_map_buffer_t
  109. {
  110. CL_COMMAND
  111. cl_mem buffer;
  112. cl_map_flags map_flags;
  113. size_t offset;
  114. size_t cb;
  115. } * command_map_buffer;
  116. typedef struct command_unmap_mem_object_t
  117. {
  118. CL_COMMAND
  119. cl_mem buffer;
  120. void * ptr;
  121. } * command_unmap_mem_object;
  122. typedef struct command_marker_t
  123. {
  124. CL_COMMAND
  125. } * command_marker;
  126. typedef struct command_barrier_t
  127. {
  128. CL_COMMAND
  129. } * command_barrier;
  130. /*************************
  131. * Constructor functions
  132. *************************/
  133. command_ndrange_kernel command_ndrange_kernel_create (cl_kernel kernel,
  134. cl_uint work_dim,
  135. const size_t * global_work_offset,
  136. const size_t * global_work_size,
  137. const size_t * local_work_size);
  138. command_ndrange_kernel command_task_create (cl_kernel kernel);
  139. command_barrier command_barrier_create ();
  140. command_marker command_marker_create ();
  141. command_map_buffer command_map_buffer_create(cl_mem buffer,
  142. cl_map_flags map_flags,
  143. size_t offset,
  144. size_t cb);
  145. command_unmap_mem_object command_unmap_mem_object_create(cl_mem buffer,
  146. void * ptr);
  147. command_read_buffer command_read_buffer_create(cl_mem buffer,
  148. size_t offset,
  149. size_t cb,
  150. void * ptr);
  151. command_write_buffer command_write_buffer_create(cl_mem buffer,
  152. size_t offset,
  153. size_t cb,
  154. const void * ptr);
  155. command_copy_buffer command_copy_buffer_create(cl_mem src_buffer,
  156. cl_mem dst_buffer,
  157. size_t src_offset,
  158. size_t dst_offset,
  159. size_t cb);
  160. /*************************
  161. * Submit functions
  162. *************************/
  163. cl_int command_ndrange_kernel_submit(command_ndrange_kernel cmd);
  164. cl_int command_read_buffer_submit(command_read_buffer cmd);
  165. cl_int command_write_buffer_submit(command_write_buffer cmd);
  166. cl_int command_copy_buffer_submit(command_copy_buffer cmd);
  167. cl_int command_map_buffer_submit(command_map_buffer cmd);
  168. cl_int command_unmap_mem_object_submit(command_unmap_mem_object cmd);
  169. cl_int command_marker_submit(command_marker cmd);
  170. cl_int command_barrier_submit(command_barrier cmd);
  171. #endif /* SOCL_COMMANDS_H */