Переглянути джерело

Add starpu_task_get_current_data_node

Samuel Thibault 6 роки тому
батько
коміт
c64152a198

+ 10 - 0
doc/doxygen/chapters/api/codelet_and_tasks.doxy

@@ -999,6 +999,16 @@ Return the task currently executed by the
 worker, or <c>NULL</c> if it is called either from a thread that is not a
 task or simply because there is no task being executed at the moment.
 
+\fn int starpu_task_get_current_data_node(unsigned i)
+\ingroup API_Codelet_And_Tasks
+Return the memory node number of parameter \p i of the task currently executed,
+or -1 if it is called either from a thread that is not a task or simply because
+there is no task being executed at the moment.
+
+Usually, the returned memory node number is simply the memory node
+for the current worker. That may however be different when using e.g.
+starpu_codelet::specific_nodes .
+
 \fn const char *starpu_task_get_name(struct starpu_task *task)
 \ingroup API_Codelet_And_Tasks
 Return the name of \p task, i.e. either its starpu_task::name field, or

+ 9 - 1
examples/filters/fmultiple_manual.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2017                                     CNRS
  * Copyright (C) 2017                                     Inria
- * Copyright (C) 2015                                     Université de Bordeaux
+ * Copyright (C) 2015,2018                                Université de Bordeaux
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -107,6 +107,14 @@ void empty(void *buffers[], void *cl_arg)
 	 * data, thus getting back all data pieces there.  */
 	(void)buffers;
 	(void)cl_arg;
+
+	/* This check is just for testsuite */
+	int node = starpu_task_get_current_data_node(0);
+	unsigned i;
+	unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(starpu_task_get_current());
+	STARPU_ASSERT(node >= 0);
+	for (i = 1; i < nbuffers; i++)
+		STARPU_ASSERT(starpu_task_get_current_data_node(i) == node);
 }
 
 struct starpu_codelet cl_switch =

+ 1 - 0
include/starpu_task.h

@@ -354,6 +354,7 @@ void starpu_codelet_init(struct starpu_codelet *cl);
 void starpu_codelet_display_stats(struct starpu_codelet *cl);
 
 struct starpu_task *starpu_task_get_current(void);
+int starpu_task_get_current_data_node(unsigned i);
 
 const char *starpu_task_get_model_name(struct starpu_task *task);
 const char *starpu_task_get_name(struct starpu_task *task);

+ 4 - 0
src/core/dependencies/data_concurrency.c

@@ -354,6 +354,10 @@ void _starpu_job_set_ordered_buffers(struct _starpu_job *j)
 		buffers[i].node = -1;
 	}
 	_starpu_sort_task_handles(buffers, nbuffers);
+	for (i=0 ; i<nbuffers; i++)
+	{
+		buffers[buffers[i].index].orderedindex = i;
+	}
 }
 
 /* Sort the data used by the given job by handle pointer value order, and

+ 4 - 0
src/core/jobs.h

@@ -65,6 +65,10 @@ struct _starpu_data_descr
 		     _starpu_fetch_task_input for coherency with
 		     __starpu_push_task_output */
 	int index;
+
+	int orderedindex; /* For this field the array is actually indexed by
+			     parameter order, and this provides the ordered
+			     index */
 };
 
 #ifdef STARPU_DEBUG

+ 12 - 0
src/core/task.c

@@ -1143,6 +1143,18 @@ void _starpu_set_current_task(struct starpu_task *task)
 	STARPU_PTHREAD_SETSPECIFIC(current_task_key, task);
 }
 
+int starpu_task_get_current_data_node(unsigned i)
+{
+	struct starpu_task *task = starpu_task_get_current();
+	if (!task)
+		return -1;
+
+	struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
+	struct _starpu_data_descr *descrs = _STARPU_JOB_GET_ORDERED_BUFFERS(j);
+	unsigned orderedindex = descrs[i].orderedindex;
+	return descrs[orderedindex].node;
+}
+
 #ifdef STARPU_OPENMP
 /* Prepare the fields of the currentl task for accepting a new set of
  * dependencies in anticipation of becoming a continuation.

+ 1 - 0
tests/datawizard/specific_node.c

@@ -35,6 +35,7 @@ unsigned data, data2;
 void specific_kernel(void *descr[], void *arg)
 {
 	(void)arg;
+	STARPU_ASSERT(starpu_task_get_current_data_node(0) == STARPU_MAIN_RAM);
 	unsigned *dataptr = (unsigned*) STARPU_VARIABLE_GET_PTR(descr[0]);
 
 	STARPU_ASSERT(dataptr == &data);