command.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2011 University of Bordeaux
  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. #include "socl.h"
  17. #ifndef SOCL_COMMANDS_H
  18. #define SOCL_COMMANDS_H
  19. typedef struct cl_command_t * cl_command;
  20. #define gc_entity_store_cmd(dest,cmd) gc_entity_store(dest, &cmd->_command)
  21. #define gc_entity_release_cmd(cmd) gc_entity_release(&cmd->_command)
  22. /**
  23. * Initialize a command structure
  24. *
  25. * Command constructors for each kind of command use this method
  26. * Implicit and explicit dependencies must be passed as parameters
  27. */
  28. void command_init_ex(cl_command cmd, cl_command_type typ, void (*cb)(void*));
  29. #define command_init(cmd,typ,cb) \
  30. command_init_ex((cl_command)cmd,typ,cb)
  31. void command_release(cl_command cmd);
  32. /** Submit a command for execution */
  33. void command_submit_ex(cl_command cmd);
  34. #define command_submit(cmd) \
  35. command_submit_ex(&(cmd)->_command)
  36. /** Submit a command and its dependencies */
  37. cl_int command_submit_deep_ex(cl_command cmd);
  38. #define command_submit_deep(cmd) (command_submit_deep_ex((cl_command)cmd))
  39. void command_graph_dump_ex(cl_command cmd);
  40. #define command_graph_dump(cmd) (command_graph_dump_ex((cl_command)cmd))
  41. /**************************
  42. * OpenCL Commands
  43. **************************/
  44. struct cl_command_t {
  45. CL_ENTITY;
  46. cl_command_type typ; /* Command type */
  47. cl_uint num_events; /* Number of dependencies */
  48. cl_event * events; /* Dependencies */
  49. cl_event event; /* Event for this command */
  50. starpu_task task; /* Associated StarPU task, if any */
  51. char submitted; /* True if the command has been submitted to StarPU */
  52. void (*release_callback)(void*); /* Command specific destructor */
  53. };
  54. #define command_type_get(cmd) (((cl_command)cmd)->typ)
  55. cl_event command_event_get_ex(cl_command cmd);
  56. #define command_event_get(cmd) command_event_get_ex(&cmd->_command)
  57. #define command_num_events_get_ex(cmd) (cmd->num_events)
  58. #define command_num_events_get(cmd) ((cmd)->_command.num_events)
  59. #define command_events_get_ex(cmd) ((cmd)->events)
  60. #define command_events_get(cmd) ((cmd)->_command.events)
  61. #define command_task_get(cmd) ((cmd)->_command.task)
  62. #define command_cq_get(cmd) ((cmd)->_command.cq)
  63. #define CL_COMMAND struct cl_command_t _command;
  64. typedef struct command_ndrange_kernel_t {
  65. CL_COMMAND
  66. cl_kernel kernel;
  67. struct starpu_codelet codelet;
  68. cl_uint work_dim;
  69. const size_t * global_work_offset;
  70. const size_t * global_work_size;
  71. const size_t * local_work_size;
  72. cl_uint num_args;
  73. size_t * arg_sizes;
  74. enum kernel_arg_type * arg_types;
  75. void ** args;
  76. cl_uint num_buffers;
  77. cl_mem * buffers;
  78. } * command_ndrange_kernel;
  79. typedef struct command_read_buffer_t {
  80. CL_COMMAND
  81. cl_mem buffer;
  82. size_t offset;
  83. size_t cb;
  84. void * ptr;
  85. } * command_read_buffer;
  86. typedef struct command_write_buffer_t {
  87. CL_COMMAND
  88. cl_mem buffer;
  89. size_t offset;
  90. size_t cb;
  91. const void * ptr;
  92. } * command_write_buffer;
  93. typedef struct command_copy_buffer_t {
  94. CL_COMMAND
  95. cl_mem src_buffer;
  96. cl_mem dst_buffer;
  97. size_t src_offset;
  98. size_t dst_offset;
  99. size_t cb;
  100. } * command_copy_buffer;
  101. typedef struct command_map_buffer_t {
  102. CL_COMMAND
  103. cl_mem buffer;
  104. cl_map_flags map_flags;
  105. size_t offset;
  106. size_t cb;
  107. } * command_map_buffer;
  108. typedef struct command_unmap_mem_object_t {
  109. CL_COMMAND
  110. cl_mem buffer;
  111. void * ptr;
  112. } * command_unmap_mem_object;
  113. typedef struct command_marker_t {
  114. CL_COMMAND
  115. } * command_marker;
  116. typedef struct command_barrier_t {
  117. CL_COMMAND
  118. } * command_barrier;
  119. /*************************
  120. * Constructor functions
  121. *************************/
  122. command_ndrange_kernel command_ndrange_kernel_create (
  123. cl_kernel kernel,
  124. cl_uint work_dim,
  125. const size_t * global_work_offset,
  126. const size_t * global_work_size,
  127. const size_t * local_work_size);
  128. command_ndrange_kernel command_task_create (cl_kernel kernel);
  129. command_barrier command_barrier_create ();
  130. command_marker command_marker_create ();
  131. command_map_buffer command_map_buffer_create(
  132. cl_mem buffer,
  133. cl_map_flags map_flags,
  134. size_t offset,
  135. size_t cb);
  136. command_unmap_mem_object command_unmap_mem_object_create(
  137. cl_mem buffer,
  138. void * ptr);
  139. command_read_buffer command_read_buffer_create(
  140. cl_mem buffer,
  141. size_t offset,
  142. size_t cb,
  143. void * ptr);
  144. command_write_buffer command_write_buffer_create(
  145. cl_mem buffer,
  146. size_t offset,
  147. size_t cb,
  148. const void * ptr);
  149. command_copy_buffer command_copy_buffer_create(
  150. cl_mem src_buffer,
  151. cl_mem dst_buffer,
  152. size_t src_offset,
  153. size_t dst_offset,
  154. size_t cb);
  155. /*************************
  156. * Submit functions
  157. *************************/
  158. cl_int command_ndrange_kernel_submit(command_ndrange_kernel cmd);
  159. cl_int command_read_buffer_submit(command_read_buffer cmd);
  160. cl_int command_write_buffer_submit(command_write_buffer cmd);
  161. cl_int command_copy_buffer_submit(command_copy_buffer cmd);
  162. cl_int command_map_buffer_submit(command_map_buffer cmd);
  163. cl_int command_unmap_mem_object_submit(command_unmap_mem_object cmd);
  164. cl_int command_marker_submit(command_marker cmd);
  165. cl_int command_barrier_submit(command_barrier cmd);
  166. #endif /* SOCL_COMMANDS_H */