starpu_worker.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. };
  35. struct starpu_sched_ctx_iterator
  36. {
  37. int cursor;
  38. };
  39. struct starpu_machine_topology
  40. {
  41. unsigned nworkers;
  42. unsigned ncombinedworkers;
  43. unsigned nsched_ctxs;
  44. #ifdef STARPU_HAVE_HWLOC
  45. hwloc_topology_t hwtopology;
  46. #else
  47. /* We maintain ABI compatibility with and without hwloc */
  48. void *dummy;
  49. #endif
  50. unsigned nhwcpus;
  51. unsigned nhwcudagpus;
  52. unsigned nhwopenclgpus;
  53. unsigned ncpus;
  54. unsigned ncudagpus;
  55. unsigned nopenclgpus;
  56. /* Where to bind workers ? */
  57. unsigned workers_bindid[STARPU_NMAXWORKERS];
  58. /* Which GPU(s) do we use for CUDA ? */
  59. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  60. /* Which GPU(s) do we use for OpenCL ? */
  61. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  62. };
  63. /* generic structure used by the scheduling contexts to iterate the workers */
  64. struct starpu_worker_collection
  65. {
  66. /* hidden data structure used to memorize the workers */
  67. void *workerids;
  68. /* the number of workers in the collection */
  69. unsigned nworkers;
  70. /* the type of structure (STARPU_WORKER_LIST,...) */
  71. int type;
  72. /* checks if there is another element in collection */
  73. unsigned (*has_next)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it);
  74. /* return the next element in the collection */
  75. int (*get_next)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it);
  76. /* add a new element in the collection */
  77. int (*add)(struct starpu_worker_collection *workers, int worker);
  78. /* remove an element from the collection */
  79. int (*remove)(struct starpu_worker_collection *workers, int worker);
  80. /* initialize the structure */
  81. void (*init)(struct starpu_worker_collection *workers);
  82. /* free the structure */
  83. void (*deinit)(struct starpu_worker_collection *workers);
  84. /* initialize the cursor if there is one */
  85. void (*init_iterator)(struct starpu_worker_collection *workers, struct starpu_sched_ctx_iterator *it);
  86. };
  87. enum starpu_node_kind
  88. {
  89. STARPU_UNUSED = 0x00,
  90. STARPU_CPU_RAM = 0x01,
  91. STARPU_CUDA_RAM = 0x02,
  92. STARPU_OPENCL_RAM = 0x03
  93. };
  94. unsigned starpu_worker_get_memory_node(unsigned workerid);
  95. unsigned starpu_memory_nodes_get_count(void);
  96. enum starpu_node_kind starpu_node_get_kind(unsigned node);
  97. /* types of structures the worker collection can implement */
  98. #define STARPU_WORKER_LIST 0
  99. /* This function returns the number of workers (ie. processing units executing
  100. * StarPU tasks). The returned value should be at most STARPU_NMAXWORKERS. */
  101. unsigned starpu_worker_get_count(void);
  102. unsigned starpu_combined_worker_get_count(void);
  103. unsigned starpu_worker_is_combined_worker(int id);
  104. unsigned starpu_cpu_worker_get_count(void);
  105. unsigned starpu_cuda_worker_get_count(void);
  106. unsigned starpu_opencl_worker_get_count(void);
  107. /* Return the identifier of the thread in case this is associated to a worker.
  108. * This will return -1 if this function is called directly from the application
  109. * or if it is a worker in which a single thread controls different devices. */
  110. int starpu_worker_get_id(void);
  111. int starpu_combined_worker_get_id(void);
  112. int starpu_combined_worker_get_size(void);
  113. int starpu_combined_worker_get_rank(void);
  114. /* This function returns the type of worker associated to an identifier (as
  115. * returned by the starpu_worker_get_id function). The returned value indicates
  116. * the architecture of the worker: STARPU_CPU_WORKER for a CPU core,
  117. * STARPU_CUDA_WORKER for a CUDA device. The value returned for an
  118. * invalid identifier is unspecified. */
  119. enum starpu_worker_archtype starpu_worker_get_type(int id);
  120. /* Returns the number of workers of the type indicated by the argument. A
  121. * positive (or null) value is returned in case of success, -EINVAL indicates
  122. * that the type is not valid otherwise. */
  123. int starpu_worker_get_count_by_type(enum starpu_worker_archtype type);
  124. /* Fill the workerids array with the identifiers of the workers that have the
  125. * type indicated in the first argument. The maxsize argument indicates the
  126. * size of the workids array. The returned value gives the number of
  127. * identifiers that were put in the array. -ERANGE is returned is maxsize is
  128. * lower than the number of workers with the appropriate type: in that case,
  129. * the array is filled with the maxsize first elements. To avoid such
  130. * overflows, the value of maxsize can be chosen by the means of the
  131. * starpu_worker_get_count_by_type function, or by passing a value greater or
  132. * equal to STARPU_NMAXWORKERS. */
  133. int starpu_worker_get_ids_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize);
  134. /* Return the identifier of the n-th worker of a specific type */
  135. int starpu_worker_get_by_type(enum starpu_worker_archtype type, int num);
  136. /* Return the identifier of the worker devid of a specific type */
  137. int starpu_worker_get_by_devid(enum starpu_worker_archtype type, int devid);
  138. /* StarPU associates a unique human readable string to each processing unit.
  139. * This function copies at most the "maxlen" first bytes of the unique
  140. * string associated to a worker identified by its identifier "id" into
  141. * the "dst" buffer. The caller is responsible for ensuring that the
  142. * "dst" is a valid pointer to a buffer of "maxlen" bytes at least.
  143. * Calling this function on an invalid identifier results in an unspecified
  144. * behaviour. */
  145. void starpu_worker_get_name(int id, char *dst, size_t maxlen);
  146. /* This functions returns the device id of the worker associated to an
  147. * identifier (as returned by the starpu_worker_get_id() function)
  148. */
  149. int starpu_worker_get_devid(int id);
  150. #ifdef __cplusplus
  151. }
  152. #endif
  153. #endif /* __STARPU_WORKER_H__ */