Kaynağa Gözat

Factorize choosing the target memory node for task data

Samuel Thibault 7 yıl önce
ebeveyn
işleme
b0bd9f0f44

+ 1 - 6
src/core/perfmodel/perfmodel.c

@@ -342,12 +342,7 @@ double starpu_task_expected_data_transfer_time(unsigned memory_node, struct star
 	{
 		starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, buffer);
 		enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, buffer);
-		int node = -1;
-		/* TODO: factorize node choice */
-		if (task->cl->specific_nodes)
-			node = STARPU_CODELET_GET_NODE(task->cl, buffer);
-		if (node == -1)
-			node = memory_node;
+		int node = _starpu_task_data_get_node_on_node(task, buffer, memory_node);
 
 		penalty += starpu_data_expected_transfer_time(handle, node, mode);
 	}

+ 17 - 0
src/core/topology.c

@@ -107,6 +107,23 @@ static struct _starpu_worker_set mic_worker_set[STARPU_MAXMICDEVS];
 struct _starpu_worker_set mpi_worker_set[STARPU_MAXMPIDEVS];
 #endif
 
+/* Avoid using this one, prefer _starpu_task_data_get_node_on_worker */
+int _starpu_task_data_get_node_on_node(struct starpu_task *task, unsigned index, unsigned target_node)
+{
+	int node = -1;
+	if (task->cl->specific_nodes)
+		node = STARPU_CODELET_GET_NODE(task->cl, index);
+	if (node == -1)
+		node = target_node;
+	return node;
+}
+
+int _starpu_task_data_get_node_on_worker(struct starpu_task *task, unsigned index, unsigned worker)
+{
+	unsigned target_node = starpu_worker_get_memory_node(worker);
+	return _starpu_task_data_get_node_on_node(task, index, target_node);
+}
+
 int starpu_memory_nodes_get_numa_count(void)
 {
 	return nb_numa_nodes;

+ 5 - 1
src/core/topology.h

@@ -76,5 +76,9 @@ struct _starpu_worker *_starpu_get_worker_from_driver(struct starpu_driver *d);
 
 int starpu_memory_nodes_get_numa_count(void);
 int starpu_memory_nodes_numa_id_to_hwloclogid(unsigned id);
-	
+
+/* Get the memory node for data number i when task is to be executed on memory node target_node */
+int _starpu_task_data_get_node_on_node(struct starpu_task *task, unsigned index, unsigned target_node);
+int _starpu_task_data_get_node_on_worker(struct starpu_task *task, unsigned index, unsigned worker);
+
 #endif // __TOPOLOGY_H__

+ 6 - 22
src/datawizard/coherency.c

@@ -923,12 +923,6 @@ int starpu_prefetch_task_input_on_node_prio(struct starpu_task *task, unsigned t
 	{
 		starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, index);
 		enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, index);
-		int node = -1;
-		/* TODO: factorize node choice */
-		if (task->cl->specific_nodes)
-			node = STARPU_CODELET_GET_NODE(task->cl, index);
-		if (node == -1)
-			node = target_node;
 
 		if (mode & (STARPU_SCRATCH|STARPU_REDUX))
 			continue;
@@ -937,6 +931,8 @@ int starpu_prefetch_task_input_on_node_prio(struct starpu_task *task, unsigned t
 			/* Don't bother prefetching some data which will be overwritten */
 			continue;
 
+		int node = _starpu_task_data_get_node_on_node(task, index, target_node);
+
 		struct _starpu_data_replicate *replicate = &handle->per_node[node];
 		prefetch_data_on_node(handle, node, replicate, mode, prio);
 
@@ -963,11 +959,6 @@ int starpu_idle_prefetch_task_input_on_node_prio(struct starpu_task *task, unsig
 	{
 		starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, index);
 		enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, index);
-		int node = -1;
-		if (task->cl->specific_nodes)
-			node = STARPU_CODELET_GET_NODE(task->cl, index);
-		if (node == -1)
-			node = target_node;
 
 		if (mode & (STARPU_SCRATCH|STARPU_REDUX))
 			continue;
@@ -976,6 +967,8 @@ int starpu_idle_prefetch_task_input_on_node_prio(struct starpu_task *task, unsig
 			/* Don't bother prefetching some data which will be overwritten */
 			continue;
 
+		int node = _starpu_task_data_get_node_on_node(task, index, target_node);
+
 		struct _starpu_data_replicate *replicate = &handle->per_node[node];
 		idle_prefetch_data_on_node(handle, node, replicate, mode, prio);
 	}
@@ -1058,8 +1051,6 @@ int _starpu_fetch_task_input(struct starpu_task *task, struct _starpu_job *j, in
 	unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
 	unsigned nacquires;
 
-	unsigned local_memory_node = worker->memory_node;
-
 	unsigned index;
 
 	nacquires = 0;
@@ -1068,12 +1059,7 @@ int _starpu_fetch_task_input(struct starpu_task *task, struct _starpu_job *j, in
 		int ret;
 		starpu_data_handle_t handle = descrs[index].handle;
 		enum starpu_data_access_mode mode = descrs[index].mode;
-		/* TODO: factorize node choice */
-		int node = -1;
-		if (task->cl->specific_nodes)
-			node = STARPU_CODELET_GET_NODE(task->cl, descrs[index].index);
-		if (node == -1)
-			node = local_memory_node;
+		int node = _starpu_task_data_get_node_on_worker(task, descrs[index].index, workerid);
 		/* We set this here for coherency with __starpu_push_task_output */
 		descrs[index].node = node;
 		if (mode == STARPU_NONE ||
@@ -1142,8 +1128,6 @@ enomem:
 		starpu_data_handle_t handle = descrs[index2].handle;
 		enum starpu_data_access_mode mode = descrs[index2].mode;
 		int node = descrs[index].node;
-		if (node == -1)
-			node = local_memory_node;
 
 		struct _starpu_data_replicate *local_replicate;
 
@@ -1293,7 +1277,7 @@ void _starpu_fetch_nowhere_task_input(struct _starpu_job *j)
 	unsigned index;
 	for (index = 0; index < nbuffers; index++)
 	{
-		/* TODO: do not change */
+		/* Note here we just follow what was requested, and not use _starpu_task_data_get_node* */
 		int node = -1;
 		if (task->cl->specific_nodes)
 			node = STARPU_CODELET_GET_NODE(task->cl, descrs[index].index);

+ 1 - 1
src/datawizard/coherency.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2011,2014-2017                           Inria
- * Copyright (C) 2008-2017                                Université de Bordeaux
+ * Copyright (C) 2008-2018                                Université de Bordeaux
  * Copyright (C) 2010-2015,2017                           CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify

+ 1 - 6
src/sched_policies/deque_modeling_policy_data_aware.c

@@ -95,12 +95,7 @@ static int count_non_ready_buffers(struct starpu_task *task, unsigned node)
 	for (index = 0; index < nbuffers; index++)
 	{
 		starpu_data_handle_t handle;
-		unsigned buffer_node = -1;
-		/* TODO: factorize node choice */
-		if (task->cl->specific_nodes)
-			buffer_node = STARPU_CODELET_GET_NODE(task->cl, index);
-		if (buffer_node == -1)
-			buffer_node = node;
+		unsigned buffer_node = _starpu_task_data_get_node_on_node(task, index, node);
 
 		handle = STARPU_TASK_GET_HANDLE(task, index);