starpu_worker.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010-2013 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __STARPU_WORKER_H__
  18. #define __STARPU_WORKER_H__
  19. #include <stdlib.h>
  20. #include <starpu_config.h>
  21. #ifdef STARPU_HAVE_HWLOC
  22. #include <hwloc.h>
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. enum starpu_worker_archtype
  29. {
  30. STARPU_ANY_WORKER, /* any worker, used in the hypervisor */
  31. STARPU_CPU_WORKER, /* CPU core */
  32. STARPU_CUDA_WORKER, /* NVIDIA CUDA device */
  33. STARPU_OPENCL_WORKER, /* OpenCL device */
  34. STARPU_MIC_WORKER, /* Intel MIC device */
  35. STARPU_SCC_WORKER /* Intel SCC device */
  36. };
  37. /* Represent the topology of sink devices, contains useful informations about
  38. * their capabilities */
  39. // XXX: unused.
  40. struct starpu_sink_topology
  41. {
  42. unsigned nb_cpus;
  43. };
  44. struct starpu_sched_ctx_iterator
  45. {
  46. int cursor;
  47. };
  48. struct starpu_machine_topology
  49. {
  50. unsigned nworkers;
  51. unsigned ncombinedworkers;
  52. unsigned nsched_ctxs;
  53. #ifdef STARPU_HAVE_HWLOC
  54. hwloc_topology_t hwtopology;
  55. #else
  56. /* We maintain ABI compatibility with and without hwloc */
  57. void *dummy;
  58. #endif
  59. unsigned nhwcpus;
  60. unsigned nhwcudagpus;
  61. unsigned nhwopenclgpus;
  62. unsigned nhwscc;
  63. unsigned ncpus;
  64. unsigned ncudagpus;
  65. unsigned nopenclgpus;
  66. unsigned nsccdevices;
  67. /* Topology of MP nodes (mainly MIC and SCC) as well as necessary
  68. * objects to communicate with them. */
  69. unsigned nhwmicdevices;
  70. unsigned nmicdevices;
  71. unsigned nhwmiccores[STARPU_MAXMICDEVS]; // Each MIC node has its set of cores.
  72. unsigned nmiccores[STARPU_MAXMICDEVS];
  73. /* Where to bind workers ? */
  74. unsigned workers_bindid[STARPU_NMAXWORKERS];
  75. /* Which GPU(s) do we use for CUDA ? */
  76. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  77. /* Which GPU(s) do we use for OpenCL ? */
  78. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  79. /* Which MIC core(s) do we use ? */
  80. /* unsigned workers_mic_deviceid[STARPU_NMAXWORKERS]; */
  81. /* Which SCC(s) do we use ? */
  82. unsigned workers_scc_deviceid[STARPU_NMAXWORKERS];
  83. };
  84. /* types of structures the worker collection can implement */
  85. enum starpu_worker_collection_type
  86. {
  87. STARPU_WORKER_LIST
  88. };
  89. /* generic structure used by the scheduling contexts to iterate the workers */
  90. struct starpu_worker_collection
  91. {
  92. /* hidden data structure used to memorize the workers */
  93. void *workerids;
  94. /* the number of workers in the collection */
  95. unsigned nworkers;
  96. /* the type of structure */
  97. enum starpu_worker_collection_type type;
  98. /* checks if there is another element in collection */
  99. unsigned (*has_next)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it);
  100. /* return the next element in the collection */
  101. int (*get_next)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it);
  102. /* add a new element in the collection */
  103. int (*add)(struct starpu_worker_collection *workers, int worker);
  104. /* remove an element from the collection */
  105. int (*remove)(struct starpu_worker_collection *workers, int worker);
  106. /* initialize the structure */
  107. void (*init)(struct starpu_worker_collection *workers);
  108. /* free the structure */
  109. void (*deinit)(struct starpu_worker_collection *workers);
  110. /* initialize the cursor if there is one */
  111. void (*init_iterator)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it);
  112. };
  113. /* This function returns the number of workers (ie. processing units executing
  114. * StarPU tasks). The returned value should be at most STARPU_NMAXWORKERS. */
  115. unsigned starpu_worker_get_count(void);
  116. unsigned starpu_combined_worker_get_count(void);
  117. unsigned starpu_worker_is_combined_worker(int id);
  118. unsigned starpu_cpu_worker_get_count(void);
  119. unsigned starpu_cuda_worker_get_count(void);
  120. unsigned starpu_opencl_worker_get_count(void);
  121. unsigned starpu_mic_worker_get_count(void);
  122. unsigned starpu_scc_worker_get_count(void);
  123. unsigned starpu_mic_device_get_count(void);
  124. /* Return the identifier of the thread in case this is associated to a worker.
  125. * This will return -1 if this function is called directly from the application
  126. * or if it is a worker in which a single thread controls different devices. */
  127. int starpu_worker_get_id(void);
  128. int starpu_combined_worker_get_id(void);
  129. int starpu_combined_worker_get_size(void);
  130. int starpu_combined_worker_get_rank(void);
  131. /* This function returns the type of worker associated to an identifier (as
  132. * returned by the starpu_worker_get_id function). The returned value indicates
  133. * the architecture of the worker: STARPU_CPU_WORKER for a CPU core,
  134. * STARPU_CUDA_WORKER for a CUDA device. The value returned for an
  135. * invalid identifier is unspecified. */
  136. enum starpu_worker_archtype starpu_worker_get_type(int id);
  137. /* Returns the number of workers of the type indicated by the argument. A
  138. * positive (or null) value is returned in case of success, -EINVAL indicates
  139. * that the type is not valid otherwise. */
  140. int starpu_worker_get_count_by_type(enum starpu_worker_archtype type);
  141. /* Fill the workerids array with the identifiers of the workers that have the
  142. * type indicated in the first argument. The maxsize argument indicates the
  143. * size of the workids array. The returned value gives the number of
  144. * identifiers that were put in the array. -ERANGE is returned is maxsize is
  145. * lower than the number of workers with the appropriate type: in that case,
  146. * the array is filled with the maxsize first elements. To avoid such
  147. * overflows, the value of maxsize can be chosen by the means of the
  148. * starpu_worker_get_count_by_type function, or by passing a value greater or
  149. * equal to STARPU_NMAXWORKERS. */
  150. int starpu_worker_get_ids_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize);
  151. /* Return the identifier of the n-th worker of a specific type */
  152. int starpu_worker_get_by_type(enum starpu_worker_archtype type, int num);
  153. /* Return the identifier of the worker devid of a specific type */
  154. int starpu_worker_get_by_devid(enum starpu_worker_archtype type, int devid);
  155. /* StarPU associates a unique human readable string to each processing unit.
  156. * This function copies at most the "maxlen" first bytes of the unique
  157. * string associated to a worker identified by its identifier "id" into
  158. * the "dst" buffer. The caller is responsible for ensuring that the
  159. * "dst" is a valid pointer to a buffer of "maxlen" bytes at least.
  160. * Calling this function on an invalid identifier results in an unspecified
  161. * behaviour. */
  162. void starpu_worker_get_name(int id, char *dst, size_t maxlen);
  163. /* This functions returns the device id of the worker associated to an
  164. * identifier (as returned by the starpu_worker_get_id() function)
  165. */
  166. int starpu_worker_get_devid(int id);
  167. int starpu_worker_get_mp_nodeid(int id);
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171. #endif /* __STARPU_WORKER_H__ */