HParallel.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*****************************************************************************
  2. * HParallel.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/HLib
  6. * Description: Basic constants for controlling the automatic
  7. * parallelization of HALCON operators and
  8. * programs (operator sequences)
  9. *
  10. * (c) 1996-2020 by MVTec Software GmbH
  11. * www.mvtec.com
  12. *
  13. *****************************************************************************/
  14. #ifndef HCPAR_H
  15. #define HCPAR_H
  16. #if defined(__cplusplus)
  17. extern "C" {
  18. #endif
  19. /* --- Defines -------------------------------------------------- */
  20. #if defined(_POSIX_THREADS)
  21. # define H_POSIX_THREADS
  22. #elif defined(_WIN32)
  23. # define H_WIN32_THREADS
  24. #endif
  25. /* else: no synchronization and threads used */
  26. #if !defined(H_PARALLEL) || \
  27. !(defined(H_WIN32_THREADS) || defined(H_POSIX_THREADS))
  28. /* Sequential HALCON or no synchronization specified */
  29. # define H_NO_SPIN_LOCK
  30. # if defined H_TSD
  31. # undef H_TSD /* no thread specific data */
  32. # endif
  33. #else
  34. # define H_TSD /* use thread specific data */
  35. #endif
  36. /*===========================================================================*/
  37. /* Constants */
  38. /*===========================================================================*/
  39. /* -------- (knowledge default values and control weights) ----------------- */
  40. /* constants for describing how to process an operator: */
  41. #define HAG_PAR_INDEPENDENT \
  42. 0 /* completely independent of other \
  43. * operators, i.e., can run with \
  44. * exclusive operators in parallel*/
  45. #define HAG_PAR_NO_RESTRICT 1 << 0 /* no restriction */
  46. #define HAG_PAR_LOCAL 1 << 1 /* force local processing */
  47. /* by main thread/process */
  48. #define HAG_PAR_MUTUAL 1 << 2 /* force processing under mutual */
  49. /* exclusion, i.e. the same */
  50. /* operator may only run once at */
  51. /* a time */
  52. #define HAG_PAR_EXCLUSIVE 1 << 3 /* force exclusive processing, */
  53. /* i.e. no other operator may run */
  54. /* while this operator works */
  55. /* default control values: */
  56. #define HAG_KW_CHORD_NUM 1 /* minimal num. of chords for par.*/
  57. #define HAG_KW_MIN_COSTS 16300 /* minimal costs for which to par.*/
  58. #define HAG_KW_PAR_COSTS 308 /* weight of ctrl. par. costs */
  59. #define HAG_KW_CPU_RATING 10 /* threshold for assigning a cpu */
  60. /* -------- (postprocessing of control parameters) ------------------------- */
  61. #define HAG_PAR_NOCT 1 /* no need of ctrl. par. postproc.*/
  62. /* =>adopt par. of 1. H. thread */
  63. #define HAG_PAR_TUCT_ADD 2 /* add ctrl. par.s ; tuple */
  64. #define HAG_PAR_CHCT_ADD 4 /* add ctrl. par.s ; channel*/
  65. /* (must be 2*HAG_PAR_TUCT_ADD) */
  66. #define HAG_PAR_RECT_ADD 8 /* add ctrl. par.s ; res.de.*/
  67. /* (must be 4*HAG_PAR_TUCT_ADD) */
  68. #define HAG_PAR_TUCT_MIN 16 /* minimum of ctrl. par.s; tuple */
  69. #define HAG_PAR_CHCT_MIN 32 /* minimum of ctrl. par.s; channel*/
  70. #define HAG_PAR_RECT_MIN 64 /* minimum of ctrl. par.s; res.de.*/
  71. #define HAG_PAR_TUCT_MAX 128 /* maximum of ctrl. par.s; tuple */
  72. #define HAG_PAR_CHCT_MAX 256 /* maximum of ctrl. par.s; channel*/
  73. #define HAG_PAR_RECT_MAX 512 /* maximum of ctrl. par.s; res.de.*/
  74. #define HAG_PAR_TUCT_CON 1024 /* concatenate ctrl. par.s;tuple */
  75. #define HAG_PAR_CHCT_CON 2048 /* concatenate ctrl. par.s;channel*/
  76. #define HAG_PAR_RECT_CON 4096 /* concatenate ctrl. par.s;res.de.*/
  77. /* ATTENTION: the difference in */
  78. /* the codes for tuples/channels/ */
  79. /* resources must always show the */
  80. /* above scheme of *2 and *4! */
  81. /* Because this is used in the */
  82. /* HAgent-source code; e.g.: */
  83. /* HAG_PAR_CHCT_MIN is assumed to */
  84. /* be HAG_PAR_TUCT_MIN*2 */
  85. #define HAG_PAR_TUCT 1170 /* postprocess ctrl. par.; tuple */
  86. /* remark: this is a shortcut for: HAG_PAR_TUCT_ADD | HAG_PAR_TUCT_MIN | */
  87. /* HAG_PAR_TUCT_MAX | HAG_PAR_TUCT_CON */
  88. #define HAG_PAR_CHCT 2340 /* postprocess ctrl. par.; channel*/
  89. /* (must be 2*HAG_PAR_TUCT) */
  90. #define HAG_PAR_RECT 4680 /* postprocess ctrl. par.; res.de.*/
  91. /* (must be 4*HAG_PAR_TUCT) */
  92. /* -------- (postprocessing of domains/region components of output objects) */
  93. #define HAG_PAR_REG_NONE 0 /* no post processing */
  94. #define HAG_PAR_REG_CONSI (1 << 0) /* concatenation of (disjuntive) */
  95. /* result regions for single */
  96. /* input iconic parameter */
  97. #define HAG_PAR_REG_CONMU (1 << 1) /* concatenation of (disjuntive) */
  98. /* result regions for multiple */
  99. /* input iconic parameters */
  100. #define HAG_PAR_REG_CONMAN (1 << 2) /* manual concatenation of */
  101. /* result regions for multiple */
  102. /* input iconic parameters */
  103. /* Use HAG_PAR_REG_CONMAN if your */
  104. /* the output region is variable, */
  105. /* and not dependent on the input */
  106. /* iconic parameters */
  107. /* -------- (task-/operator-/thread-parallelization; chances and states) --- */
  108. /* -------- (and postprocessing of control parameters) --------------------- */
  109. /* The following constants symbolize different methods of parallelization. */
  110. /* Their values are built up according to the following rules: */
  111. /* Bit 0 signals multithreading ability (see HAG_PAR_MT) */
  112. /* Bits 1-6 signal which method of parallelization can be used: */
  113. #define HAG_PAR_SEQ 0 /* all operators are called */
  114. /* sequentially => no need of */
  115. /* synchronization; no automatic */
  116. /* parallelization */
  117. #define HAG_PAR_MT (1 << 0) /* "multithreading" context; */
  118. /* operators may called in */
  119. /* parallel use synchronization */
  120. /* mechanisms for reentrancy, */
  121. /* but don't use automatic par. */
  122. #define HAG_PAR_FORCE \
  123. (1 << 1) /* force parallelization if \
  124. * supported */
  125. #define HAG_PAR_NONE (1 << 2) /* no parallelization 'lucrative' */
  126. /* is set explicitely, if the
  127. * hardware/operator training
  128. * showed that the processing does
  129. * not speed up by parallelization*/
  130. #define HAG_PAR_TUPL (1 << 5) /* tuple parallelization possible */
  131. #define HAG_PAR_CHNL (1 << 6) /* channel paralleli. is possible */
  132. #define HAG_PAR_RESC (1 << 7) /* resource decomposition possible*/
  133. #define HAG_PAR_REIF (1 << 8) /* res. dec. at image filtering */
  134. #define HAG_PAR_PART \
  135. (1 << 9) /* partial automatic parallelization: \
  136. * an operator is parallelized \
  137. * manually within the hlib */
  138. #define HAG_PAR_PAIF (1 << 10) /* internal domain parallelization */
  139. /* constants for describing the overall processing context: */
  140. #define HAG_PAR_SPLIT_NONE 0
  141. #define HAG_PAR_SPLIT_DOMAIN (HAG_PAR_RESC | HAG_PAR_REIF)
  142. /* ^domain parallelization */
  143. #define HAG_PAR_INTERFACE (HAG_PAR_TUPL | HAG_PAR_CHNL | HAG_PAR_REIF)
  144. /* ^parallelization by interface */
  145. #define HAG_PAR_INTERNAL (HAG_PAR_PART | HAG_PAR_PAIF)
  146. /* ^manual, internal parallelization */
  147. #define HAG_PAR_ALL \
  148. (HAG_PAR_TUPL | HAG_PAR_CHNL | HAG_PAR_RESC | HAG_PAR_REIF | HAG_PAR_PART | \
  149. HAG_PAR_PAIF)
  150. /* remark: all following "true" values (!=0) mean in any case that HALCON */
  151. /* works in a parallel manner and needs synchronization mechanisms */
  152. #define HAG_PAR_TUPL_MT (HAG_PAR_TUPL | HAG_PAR_MT)
  153. #define HAG_PAR_CHNL_MT (HAG_PAR_CHNL | HAG_PAR_MT)
  154. #define HAG_PAR_RESC_MT (HAG_PAR_RESC | HAG_PAR_MT)
  155. #define HAG_PAR_REIF_MT (HAG_PAR_REIF | HAG_PAR_MT)
  156. #define HAG_PAR_DOM_MT (HAG_PAR_REIF_MT | HAG_PAR_RESC_MT)
  157. #define HAG_PAR_PART_MT (HAG_PAR_PART | HAG_PAR_MT)
  158. #define HAG_PAR_PAIF_MT (HAG_PAR_PAIF | HAG_PAR_MT)
  159. #define HAG_PAR_DPAR_MT \
  160. (HAG_PAR_TUPL_MT | HAG_PAR_CHNL_MT | HAG_PAR_RESC_MT | HAG_PAR_REIF_MT | \
  161. HAG_PAR_PART_MT | HAG_PAR_PAIF_MT)
  162. /* "multithreading" context (see */
  163. /* above) AND use automatic */
  164. /* data parallelization for */
  165. /* processing operators (default) */
  166. /* tuple & channel p. & res. dec. */
  167. /* Bits 8-23 currently not used */
  168. /* #define 128 * */
  169. /* #define 256 * */
  170. /* #define 512 * */
  171. /* #define 1024 * */
  172. /* #define 2048 * */
  173. /* #define 4096 * */
  174. /* #define 8192 * */
  175. /* #define 16384 * */
  176. /* #define 32768 * */
  177. /* #define 65536 * */
  178. /* #define 131072 * */
  179. /* #define 262144 * */
  180. /* #define 524288 * */
  181. /* #define 1048576 * */
  182. /* #define 2097152 * */
  183. /* #define 4194304 * */
  184. /* Bits 24-31 signal which parallelization steps have already been */
  185. /* done for the actual task/operator/thread: */
  186. #define HAG_PAR_TUPLED (1 << 24) /* tuple parallelized */
  187. #define HAG_PAR_CHNLED (1 << 25) /* channel parallelized */
  188. #define HAG_PAR_RESCED (1 << 26) /* resources already decomposed */
  189. #define HAG_PAR_REIFED (1 << 27) /* res. decom. at image filtering */
  190. /*-------------------- Compute Device constants ---------------------*/
  191. #define COMPUTE_DEVICE_NONE 0
  192. #define COMPUTE_DEVICE_OpenCL 1
  193. /* H_OPERATOR_INFO.compute_device bit field defines */
  194. #define COMPUTE_DEVICE_BIT_NONE 0
  195. #define COMPUTE_DEVICE_BIT_OpenCL (1 << (COMPUTE_DEVICE_OpenCL))
  196. #if defined(__cplusplus)
  197. }
  198. #endif
  199. #endif