Browse Source

For unpack operations, move the memory deallocation from
starpu_data_unpack() to the interface function
starpu_data_interface_ops::unpack_data().

Pack and unpack functions of predefined interfaces use public API
starpu_malloc_on_node_flags() and starpu_free_on_node_flags() to
allocate and de-allocate memory.

Nathalie Furmento 6 years ago
parent
commit
a4077afc93

+ 6 - 0
ChangeLog

@@ -153,6 +153,12 @@ Changes:
   * Sort data access requests by priority.
   * Cluster support is disabled by default, unless the configure
     option --enable-cluster is specified
+  * For unpack operations, move the memory deallocation from
+    starpu_data_unpack() to the interface function
+    starpu_data_interface_ops::unpack_data(). Pack and unpack
+    functions of predefined interfaces
+    use public API starpu_malloc_on_node_flags() and
+    starpu_free_on_node_flags() to allocate and de-allocate memory
 
 Small changes:
   * Use asynchronous transfers for task data fetches with were not prefetched.

+ 3 - 1
examples/interface/complex_interface.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2012,2013                                Inria
- * Copyright (C) 2012-2015,2017,2018                      CNRS
+ * Copyright (C) 2012-2015,2017,2018,2019                 CNRS
  * Copyright (C) 2012-2015,2018                           Université de Bordeaux
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -161,6 +161,8 @@ static int complex_unpack_data(starpu_data_handle_t handle, unsigned node, void
 	memcpy(complex_interface->real, data, complex_interface->nx*sizeof(double));
 	memcpy(complex_interface->imaginary, data+complex_interface->nx*sizeof(double), complex_interface->nx*sizeof(double));
 
+	free(ptr);
+
 	return 0;
 }
 

+ 3 - 3
include/starpu_data_interfaces.h

@@ -536,7 +536,8 @@ struct starpu_data_interface_ops
 
 	/**
 	   Unpack the data handle from the contiguous buffer at the address
-	   \p ptr of size \p count
+	   \p ptr of size \p count.
+	   The memory at the address \p ptr should be freed after the data unpacking operation.
 	*/
 	int (*unpack_data) (starpu_data_handle_t handle, unsigned node, void *ptr, size_t count);
 
@@ -629,8 +630,7 @@ int starpu_data_pack(starpu_data_handle_t handle, void **ptr, starpu_ssize_t *co
    Unpack in handle the data located at \p ptr of size \p count as
    described by the interface of the data. The interface registered at
    \p handle must define a unpacking operation (see
-   starpu_data_interface_ops). The memory at the address \p ptr is freed
-   after calling the data unpacking operation.
+   starpu_data_interface_ops).
 */
 int starpu_data_unpack(starpu_data_handle_t handle, void *ptr, size_t count);
 

+ 0 - 1
mpi/src/mpi/starpu_mpi_mpi.c

@@ -868,7 +868,6 @@ static void _starpu_mpi_early_data_cb(void* arg)
 		struct starpu_data_interface_ops *itf_dst = starpu_data_get_interface_ops(args->data_handle);
 		STARPU_MPI_ASSERT_MSG(itf_dst->unpack_data, "The data interface does not define an unpack function\n");
 		itf_dst->unpack_data(args->data_handle, STARPU_MAIN_RAM, args->buffer, itf_src->get_size(args->early_handle));
-		free(args->buffer);
 		args->buffer = NULL;
 	}
 	else

+ 1 - 7
src/datawizard/copy_driver.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2008-2019                                Université de Bordeaux
  * Copyright (C) 2011-2013,2016,2017                      Inria
- * Copyright (C) 2010,2011,2013,2015-2018                 CNRS
+ * Copyright (C) 2010,2011,2013,2015-2019                 CNRS
  *
  * 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
@@ -592,8 +592,6 @@ static int copy_data_1_to_1_generic(starpu_data_handle_t handle,
 			{
 				/* read is already finished, we can already unpack */
 				handle->ops->unpack_data(handle, dst_node, ptr, size);
-				/* ptr is allocated in full_read */
-				_starpu_free_flags_on_node(dst_node, ptr, size, 0);
 			}
 			else if (ret == -EAGAIN)
 			{
@@ -936,8 +934,6 @@ void _starpu_driver_wait_request_completion(struct _starpu_async_channel *async_
 			{
 				/* read is finished, we can already unpack */
 				async_channel->event.disk_event.handle->ops->unpack_data(async_channel->event.disk_event.handle, async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size);
-				/* ptr is allocated in full_read */
-				_starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
 			}
 			else
 			{
@@ -1016,8 +1012,6 @@ unsigned _starpu_driver_test_request_completion(struct _starpu_async_channel *as
 			{
 				/* read is finished, we can already unpack */
 				async_channel->event.disk_event.handle->ops->unpack_data(async_channel->event.disk_event.handle, async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size);
-				/* ptr is allocated in full_read */
-				_starpu_free_flags_on_node(async_channel->event.disk_event.node, async_channel->event.disk_event.ptr, async_channel->event.disk_event.size, 0);
 			}
 			else
 			{

+ 5 - 2
src/datawizard/interfaces/bcsr_interface.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2008-2018                                Université de Bordeaux
  * Copyright (C) 2011,2012,2017                           Inria
- * Copyright (C) 2010-2015,2017                           CNRS
+ * Copyright (C) 2010-2015,2017,2019                      CNRS
  *
  * 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
@@ -439,7 +439,7 @@ static int pack_data(starpu_data_handle_t handle, unsigned node, void **ptr, sta
 
 	if (ptr != NULL)
 	{
-		_starpu_malloc_flags_on_node(node, ptr, *count, 0);
+		*ptr = (void *)starpu_malloc_on_node_flags(node, *count, 0);
 		char *tmp = *ptr;
 		memcpy(tmp, (void*)bcsr->colind, bcsr->nnz * sizeof(bcsr->colind[0]));
 		tmp += bcsr->nnz * sizeof(bcsr->colind[0]);
@@ -465,6 +465,9 @@ static int unpack_data(starpu_data_handle_t handle, unsigned node, void *ptr, si
 	memcpy((void*)bcsr->rowptr, tmp, (bcsr->nrow + 1) * sizeof(bcsr->rowptr[0]));
 	tmp += (bcsr->nrow + 1) * sizeof(bcsr->rowptr[0]);
 	memcpy((void*)bcsr->nzval, tmp, bcsr->r * bcsr->c * bcsr->nnz * bcsr->elemsize);
+
+	starpu_free_on_node_flags(node, ptr, count, 0);
+
 	return 0;
 }
 

+ 4 - 2
src/datawizard/interfaces/block_interface.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2009-2019                                Université de Bordeaux
  * Copyright (C) 2011,2012,2017                           Inria
- * Copyright (C) 2010-2017                                CNRS
+ * Copyright (C) 2010-2017,2019                           CNRS
  *
  * 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
@@ -247,7 +247,7 @@ static int pack_block_handle(starpu_data_handle_t handle, unsigned node, void **
 		uint32_t z, y;
 		char *block = (void *)block_interface->ptr;
 
-		_starpu_malloc_flags_on_node(node, ptr, *count, 0);
+		*ptr = (void *)starpu_malloc_on_node_flags(node, *count, 0);
 
 		char *cur = *ptr;
 		for(z=0 ; z<block_interface->nz ; z++)
@@ -290,6 +290,8 @@ static int unpack_block_handle(starpu_data_handle_t handle, unsigned node, void
 		block = block_z + block_interface->ldz * block_interface->elemsize;
 	}
 
+	starpu_free_on_node_flags(node, ptr, count, 0);
+
 	return 0;
 }
 

+ 5 - 2
src/datawizard/interfaces/csr_interface.c

@@ -3,7 +3,7 @@
  * Copyright (C) 2008-2018                                Université de Bordeaux
  * Copyright (C) 2011,2012,2017                           Inria
  * Copyright (C) 2010                                     Mehdi Juhoor
- * Copyright (C) 2010-2015,2017                           CNRS
+ * Copyright (C) 2010-2015,2017,2019                      CNRS
  *
  * 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
@@ -379,7 +379,7 @@ static int pack_data(starpu_data_handle_t handle, unsigned node, void **ptr, sta
 
 	if (ptr != NULL)
 	{
-		_starpu_malloc_flags_on_node(node, ptr, *count, 0);
+		*ptr = (void *)starpu_malloc_on_node_flags(node, *count, 0);
 		char *tmp = *ptr;
 		memcpy(tmp, (void*)csr->colind, csr->nnz * sizeof(csr->colind[0]));
 		tmp += csr->nnz * sizeof(csr->colind[0]);
@@ -405,5 +405,8 @@ static int unpack_data(starpu_data_handle_t handle, unsigned node, void *ptr, si
 	memcpy((void*)csr->rowptr, tmp, (csr->nrow + 1) * sizeof(csr->rowptr[0]));
 	tmp += (csr->nrow + 1) * sizeof(csr->rowptr[0]);
 	memcpy((void*)csr->nzval, tmp, csr->nnz * csr->elemsize);
+
+	starpu_free_on_node_flags(node, ptr, count, 0);
+
 	return 0;
 }

+ 0 - 1
src/datawizard/interfaces/data_interface.c

@@ -1099,7 +1099,6 @@ int starpu_data_unpack(starpu_data_handle_t handle, void *ptr, size_t count)
 	STARPU_ASSERT_MSG(handle->ops->unpack_data, "The datatype interface %s (%d) does not have an unpack operation", handle->ops->name, handle->ops->interfaceid);
 	int ret;
 	ret = handle->ops->unpack_data(handle, _starpu_memory_node_get_local_key(), ptr, count);
-	_starpu_free_flags_on_node(_starpu_memory_node_get_local_key(), ptr, count, 0);
 	return ret;
 }
 

+ 3 - 1
src/datawizard/interfaces/matrix_interface.c

@@ -286,7 +286,7 @@ static int pack_matrix_handle(starpu_data_handle_t handle, unsigned node, void *
 		uint32_t y;
 		char *matrix = (void *)matrix_interface->ptr;
 
-		_starpu_malloc_flags_on_node(node, ptr, *count, 0);
+		*ptr = (void *)starpu_malloc_on_node_flags(node, *count, 0);
 
 		char *cur = *ptr;
 		for(y=0 ; y<matrix_interface->ny ; y++)
@@ -319,6 +319,8 @@ static int unpack_matrix_handle(starpu_data_handle_t handle, unsigned node, void
 		matrix += matrix_interface->ld * matrix_interface->elemsize;
 	}
 
+	starpu_free_on_node_flags(node, ptr, count, 0);
+
 	return 0;
 }
 

+ 5 - 2
src/datawizard/interfaces/variable_interface.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2010-2018                                Université de Bordeaux
  * Copyright (C) 2011,2012,2017                           Inria
- * Copyright (C) 2010-2015,2017                           CNRS
+ * Copyright (C) 2010-2015,2017,2019                      CNRS
  *
  * 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
@@ -183,7 +183,7 @@ static int pack_variable_handle(starpu_data_handle_t handle, unsigned node, void
 
 	if (ptr != NULL)
 	{
-		_starpu_malloc_flags_on_node(node, ptr, *count, 0);
+		*ptr = (void *)starpu_malloc_on_node_flags(node, *count, 0);
 		memcpy(*ptr, (void*)variable_interface->ptr, variable_interface->elemsize);
 	}
 
@@ -200,6 +200,9 @@ static int unpack_variable_handle(starpu_data_handle_t handle, unsigned node, vo
 	STARPU_ASSERT(count == variable_interface->elemsize);
 
 	memcpy((void*)variable_interface->ptr, ptr, variable_interface->elemsize);
+
+	starpu_free_on_node_flags(node, ptr, count, 0);
+
 	return 0;
 }
 

+ 3 - 1
src/datawizard/interfaces/vector_interface.c

@@ -227,7 +227,7 @@ static int pack_vector_handle(starpu_data_handle_t handle, unsigned node, void *
 
 	if (ptr != NULL)
 	{
-		_starpu_malloc_flags_on_node(node, ptr, *count, 0);
+		*ptr = (void *)starpu_malloc_on_node_flags(node, *count, 0);
 		memcpy(*ptr, (void*)vector_interface->ptr, vector_interface->elemsize*vector_interface->nx);
 	}
 
@@ -244,6 +244,8 @@ static int unpack_vector_handle(starpu_data_handle_t handle, unsigned node, void
 	STARPU_ASSERT(count == vector_interface->elemsize * vector_interface->nx);
 	memcpy((void*)vector_interface->ptr, ptr, count);
 
+	starpu_free_on_node_flags(node, ptr, count, 0);
+
 	return 0;
 }