Browse Source

port of StarPU-1.2 rev 22600:
implement an alternate approach than r22589 by preventing prefetch on uninitialized data

Olivier Aumage 7 years ago
parent
commit
0fa6539bac
2 changed files with 34 additions and 48 deletions
  1. 25 30
      src/datawizard/coherency.c
  2. 9 18
      src/datawizard/memalloc.c

+ 25 - 30
src/datawizard/coherency.c

@@ -101,14 +101,8 @@ int _starpu_select_src_node(starpu_data_handle_t handle, unsigned destination)
 	{
 		/* Could estimate through cost, return that */
 		STARPU_ASSERT(handle->per_node[src_node].allocated);
-		if (handle->per_node[src_node].initialized)
-		{
-			return src_node;
-		}
-		else
-		{
-			return -1;
-		}
+		STARPU_ASSERT(handle->per_node[src_node].initialized);
+		return src_node;
 	}
 	
 	int i_ram = -1;
@@ -171,10 +165,7 @@ int _starpu_select_src_node(starpu_data_handle_t handle, unsigned destination)
 
 	STARPU_ASSERT(src_node != -1);
 	STARPU_ASSERT(handle->per_node[src_node].allocated);
-	if (!handle->per_node[src_node].initialized)
-	{
-		return -1;
-	}
+	STARPU_ASSERT(handle->per_node[src_node].initialized);
 	return src_node;
 }
 
@@ -587,25 +578,7 @@ struct _starpu_data_request *_starpu_create_request_to_fetch_data(starpu_data_ha
 	if (dst_replicate && mode & STARPU_R)
 	{
 		if (dst_replicate->state == STARPU_INVALID)
-		{
 			src_node = _starpu_select_src_node(handle, requesting_node);
-			if (src_node == -1 && requesting_node == STARPU_MAIN_RAM && !nwait)
-			{
-				/* And this is the main RAM, really no need for a
-				 * request, just allocate */
-				if (_starpu_allocate_memory_on_node(handle, dst_replicate, is_prefetch) == 0)
-				{
-					_starpu_update_data_state(handle, dst_replicate, mode);
-
-					_starpu_spin_unlock(&handle->header_lock);
-
-					if (callback_func)
-						callback_func(callback_arg);
-					_STARPU_LOG_OUT_TAG("data immediately allocated");
-					return NULL;
-				}
-			}
-		}
 		else
 			src_node = requesting_node;
 		if (src_node < 0)
@@ -785,6 +758,28 @@ int _starpu_fetch_data_on_node(starpu_data_handle_t handle, int node, struct _st
 	if (cpt == STARPU_SPIN_MAXTRY)
 		_starpu_spin_lock(&handle->header_lock);
 
+	if (is_prefetch > 0)
+	{
+		unsigned src_node_mask = 0;
+
+		unsigned nnodes = starpu_memory_nodes_get_count();
+		for (node = 0; node < nnodes; node++)
+		{
+			if (handle->per_node[node].state != STARPU_INVALID)
+			{
+				/* we found a copy ! */
+				src_node_mask |= (1<<node);
+			}
+		}
+
+		if (src_node_mask == 0)
+		{
+			/* no valid copy, nothing to prefetch */
+			_starpu_spin_unlock(&handle->header_lock);
+			return 0;
+		}
+	}
+
 	if (!detached)
 	{
 		/* Take references which will be released by _starpu_release_data_on_node */

+ 9 - 18
src/datawizard/memalloc.c

@@ -260,24 +260,15 @@ static int STARPU_ATTRIBUTE_WARN_UNUSED_RESULT transfer_subtree_to_node(starpu_d
 			/* This is the only copy, push it to destination */
 			struct _starpu_data_request *r;
 			r = _starpu_create_request_to_fetch_data(handle, dst_replicate, STARPU_R, 0, 0, NULL, NULL, 0, "transfer_subtree_to_node");
-			/* r may be NULL if we are tidying a replicate that was
-			 * allocated on a GPU but has not yet been initialized
-			 */
-			if (r != NULL)
-			{
-				/* Keep the handle alive while we are working on it */
-				handle->busy_count++;
-				_starpu_spin_unlock(&handle->header_lock);
-				_starpu_wait_data_request_completion(r, 1);
-				_starpu_spin_lock(&handle->header_lock);
-				handle->busy_count--;
-			}
-			else
-			{
-				/* _starpu_create_request_to_fetch_data unlocks the handle
-				 * when bailing out */
-				_starpu_spin_lock(&handle->header_lock);
-			}
+			/* There is no way we don't need a request, since
+			 * source is OWNER, destination can't be having it */
+			STARPU_ASSERT(r);
+			/* Keep the handle alive while we are working on it */
+			handle->busy_count++;
+			_starpu_spin_unlock(&handle->header_lock);
+			_starpu_wait_data_request_completion(r, 1);
+			_starpu_spin_lock(&handle->header_lock);
+			handle->busy_count--;
 			if (_starpu_data_check_not_busy(handle))
 				/* Actually disappeared, abort completely */
 				return -1;