Selaa lähdekoodia

The starpu_data_unregister_no_coherency does the same as starpu_data_unregister
except that it does not make sure a valid copy of the data is put in the home
node.

Cédric Augonnet 14 vuotta sitten
vanhempi
commit
78faf9849a
2 muutettua tiedostoa jossa 43 lisäystä ja 25 poistoa
  1. 4 0
      include/starpu_data.h
  2. 39 25
      src/datawizard/interfaces/data_interface.c

+ 4 - 0
include/starpu_data.h

@@ -44,7 +44,11 @@ typedef struct starpu_buffer_descr_t {
 
 struct starpu_data_interface_ops_t;
 
+/* Destroy the data handle, in case we don't need to update the value of the
+ * data in the home node, we can use starpu_data_unregister_no_coherency
+ * instead. */
 void starpu_data_unregister(starpu_data_handle handle);
+void starpu_data_unregister_no_coherency(starpu_data_handle handle);
 
 /* Destroy all data replicates. After data invalidation, the first access to
  * the handle must be performed in write-only mode. */

+ 39 - 25
src/datawizard/interfaces/data_interface.c

@@ -217,39 +217,43 @@ static void _starpu_data_unregister_fetch_data_callback(void *_arg)
 	PTHREAD_MUTEX_UNLOCK(&arg->mutex);
 }
 
-
-void starpu_data_unregister(starpu_data_handle handle)
+/* Unregister the data handle, perhaps we don't need to update the home_node
+ * (in that case coherent is set to 0) */
+static void _starpu_data_unregister(starpu_data_handle handle, unsigned coherent)
 {
 	STARPU_ASSERT(handle);
 
 	/* If sequential consistency is enabled, wait until data is available */
 	_starpu_data_wait_until_available(handle, STARPU_RW);
 
-	/* Fetch data in the home of the data to ensure we have a valid copy
-	 * where we registered it */
-	int home_node = handle->home_node; 
-	if (home_node >= 0)
+	if (coherent)
 	{
-		struct unregister_callback_arg arg;
-		arg.handle = handle;
-		arg.memory_node = (unsigned)home_node;
-		arg.terminated = 0;
-		PTHREAD_MUTEX_INIT(&arg.mutex, NULL);
-		PTHREAD_COND_INIT(&arg.cond, NULL);
-
-		if (!_starpu_attempt_to_submit_data_request_from_apps(handle, STARPU_R,
-				_starpu_data_unregister_fetch_data_callback, &arg))
+		/* Fetch data in the home of the data to ensure we have a valid copy
+		 * where we registered it */
+		int home_node = handle->home_node; 
+		if (home_node >= 0)
 		{
-			/* no one has locked this data yet, so we proceed immediately */
-			struct starpu_data_replicate_s *home_replicate = &handle->per_node[home_node];
-			int ret = _starpu_fetch_data_on_node(handle, home_replicate, STARPU_R, 0, NULL, NULL);
-			STARPU_ASSERT(!ret);
-		}
-		else {
-			PTHREAD_MUTEX_LOCK(&arg.mutex);
-			while (!arg.terminated)
-				PTHREAD_COND_WAIT(&arg.cond, &arg.mutex);
-			PTHREAD_MUTEX_UNLOCK(&arg.mutex);
+			struct unregister_callback_arg arg;
+			arg.handle = handle;
+			arg.memory_node = (unsigned)home_node;
+			arg.terminated = 0;
+			PTHREAD_MUTEX_INIT(&arg.mutex, NULL);
+			PTHREAD_COND_INIT(&arg.cond, NULL);
+	
+			if (!_starpu_attempt_to_submit_data_request_from_apps(handle, STARPU_R,
+					_starpu_data_unregister_fetch_data_callback, &arg))
+			{
+				/* no one has locked this data yet, so we proceed immediately */
+				struct starpu_data_replicate_s *home_replicate = &handle->per_node[home_node];
+				int ret = _starpu_fetch_data_on_node(handle, home_replicate, STARPU_R, 0, NULL, NULL);
+				STARPU_ASSERT(!ret);
+			}
+			else {
+				PTHREAD_MUTEX_LOCK(&arg.mutex);
+				while (!arg.terminated)
+					PTHREAD_COND_WAIT(&arg.cond, &arg.mutex);
+				PTHREAD_MUTEX_UNLOCK(&arg.mutex);
+			}
 		}
 	}
 
@@ -272,6 +276,16 @@ void starpu_data_unregister(starpu_data_handle handle)
 	free(handle);
 }
 
+void starpu_data_unregister(starpu_data_handle handle)
+{
+	_starpu_data_unregister(handle, 1);
+}
+
+void starpu_data_unregister_no_coherency(starpu_data_handle handle)
+{
+	_starpu_data_unregister(handle, 0);
+}
+
 void starpu_data_invalidate(starpu_data_handle handle)
 {
 	STARPU_ASSERT(handle);