浏览代码

starpu_worker_get_count_by_type and starpu_worker_get_ids_by_type respectively
give the count and the identifier list of workers of a given type.

Cédric Augonnet 14 年之前
父节点
当前提交
62262166d6
共有 3 个文件被更改,包括 92 次插入0 次删除
  1. 33 0
      doc/starpu.texi
  2. 16 0
      include/starpu.h
  3. 43 0
      src/core/workers.c

+ 33 - 0
doc/starpu.texi

@@ -2568,11 +2568,13 @@ guaranteed to be available until this method has been called.
 
 @menu
 * starpu_worker_get_count::     Get the number of processing units
+* starpu_worker_get_count_by_type:: Get the number of processing units of a given type
 * starpu_cpu_worker_get_count::  Get the number of CPU controlled by StarPU
 * starpu_cuda_worker_get_count::  Get the number of CUDA devices controlled by StarPU
 * starpu_opencl_worker_get_count::  Get the number of OpenCL devices controlled by StarPU
 * starpu_spu_worker_get_count::  Get the number of Cell SPUs controlled by StarPU
 * starpu_worker_get_id::        Get the identifier of the current worker
+* starpu_worker_get_ids_by_type:: Get the list of identifiers of workers with a given type
 * starpu_worker_get_devid::        Get the device identifier of a worker
 * starpu_worker_get_type::      Get the type of processing unit associated to a worker
 * starpu_worker_get_name::      Get the name of a worker
@@ -2591,6 +2593,19 @@ StarPU tasks). The returned value should be at most @code{STARPU_NMAXWORKERS}.
 @code{unsigned starpu_worker_get_count(void);}
 @end table
 
+@node starpu_worker_get_count_by_type
+@subsection @code{starpu_worker_get_count_by_type} -- Get the number of processing units of a given type
+@table @asis
+
+@item @emph{Description}:
+Returns the number of workers of the type indicated by the argument. A positive
+(or null) value is returned in case of success, @code{-EINVAL} indicates that
+the type is not valid otherwise.
+
+@item @emph{Prototype}:
+@code{int starpu_worker_get_count_by_type(enum starpu_archtype type);}
+@end table
+
 @node starpu_cpu_worker_get_count
 @subsection @code{starpu_cpu_worker_get_count} -- Get the number of CPU controlled by StarPU
 @table @asis
@@ -2653,6 +2668,24 @@ an integer between 0 and @code{starpu_worker_get_count() - 1}.
 @code{int starpu_worker_get_id(void);}
 @end table
 
+@node starpu_worker_get_ids_by_type
+@subsection @code{starpu_worker_get_ids_by_type} -- Get the list of identifiers of workers with a given type
+@table @asis
+
+@item @emph{Description}:
+Fill the workerids array with the identifiers of the workers that have the type
+indicated in the first argument. The maxsize argument indicates the size of the
+workids array. The returned value gives the number of identifiers that were put
+in the array. @code{-ERANGE} is returned is maxsize is lower than the number of
+workers with the appropriate type: in that case, the array is filled with the
+maxsize first elements. To avoid such overflows, the value of maxsize can be
+chosen by the means of the @code{starpu_worker_get_count_by_type} function, or
+by passing a value greater or equal to @code{STARPU_NMAXWORKERS}.
+
+@item @emph{Prototype}:
+@code{int starpu_worker_get_ids_by_type(enum starpu_archtype type, int *workerids, int maxsize);}
+@end table
+
 @node starpu_worker_get_devid
 @subsection @code{starpu_worker_get_devid} -- Get the device identifier of a worker
 @table @asis

+ 16 - 0
include/starpu.h

@@ -114,6 +114,22 @@ enum starpu_archtype {
  * SPU. The value returned for an invalid identifier is unspecified.  */
 enum starpu_archtype starpu_worker_get_type(int id);
 
+/* Returns the number of workers of the type indicated by the argument. A
+ * positive (or null) value is returned in case of success, -EINVAL indicates
+ * that the type is not valid otherwise. */
+int starpu_worker_get_count_by_type(enum starpu_archtype type);
+
+/* Fill the workerids array with the identifiers of the workers that have the
+ * type indicated in the first argument. The maxsize argument indicates the
+ * size of the workids array. The returned value gives the number of
+ * identifiers that were put in the array. -ERANGE is returned is maxsize is
+ * lower than the number of workers with the appropriate type: in that case,
+ * the array is filled with the maxsize first elements. To avoid such
+ * overflows, the value of maxsize can be chosen by the means of the
+ * starpu_worker_get_count_by_type function, or by passing a value greater or
+ * equal to STARPU_NMAXWORKERS. */
+int starpu_worker_get_ids_by_type(enum starpu_archtype type, int *workerids, int maxsize);
+
 /* StarPU associates a unique human readable string to each processing unit.
  * This function copies at most the "maxlen" first bytes of the unique
  * string associated to a worker identified by its identifier "id" into

+ 43 - 0
src/core/workers.c

@@ -498,6 +498,27 @@ unsigned starpu_worker_get_count(void)
 	return config.topology.nworkers;
 }
 
+int starpu_worker_get_count_by_type(enum starpu_archtype type)
+{
+	switch (type)
+	{
+		case STARPU_CPU_WORKER:
+			return config.topology.ncpus;
+
+		case STARPU_CUDA_WORKER:
+			return config.topology.ncudagpus;
+
+		case STARPU_OPENCL_WORKER:
+			return config.topology.nopenclgpus;
+
+		case STARPU_GORDON_WORKER:
+			return config.topology.ngordon_spus;
+
+		default:
+			return -EINVAL;
+	}
+}
+
 unsigned starpu_combined_worker_get_count(void)
 {
 	return config.topology.ncombinedworkers;
@@ -615,6 +636,28 @@ enum starpu_archtype starpu_worker_get_type(int id)
 	return config.workers[id].arch;
 }
 
+int starpu_worker_get_ids_by_type(enum starpu_archtype type, int *workerids, int maxsize)
+{
+	unsigned nworkers = starpu_worker_get_count();
+
+	int cnt = 0;
+
+	unsigned id;
+	for (id = 0; id < nworkers; id++)
+	{
+		if (starpu_worker_get_type(id) == type)
+		{
+			/* Perhaps the array is too small ? */
+			if (cnt + 1 >= maxsize)
+				return -ERANGE;
+
+			workerids[cnt++] = id;
+		}
+	}
+
+	return cnt;
+}
+
 void starpu_worker_get_name(int id, char *dst, size_t maxlen)
 {
 	char *name = config.workers[id].name;