command.h 5.1 KB

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