command.h 5.2 KB

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