HParallel.h 13 KB

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