Browse Source

data interfaces: the pack operation of user-defined data interfaces now defines a count parameter which should be set to thesize of the buffer created by the packing of the data

Nathalie Furmento 13 years ago
parent
commit
4403f33f43

+ 2 - 2
doc/chapters/advanced-api.texi

@@ -72,8 +72,8 @@ todo
 @item @code{struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface)}
 @item @code{struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface)}
 todo
 todo
 
 
-@item @code{int (*pack_data)(starpu_data_handle_t handle, uint32_t node, void **ptr)}
-Pack the data handle into a contiguous buffer at the address @code{ptr}
+@item @code{int (*pack_data)(starpu_data_handle_t handle, uint32_t node, void **ptr, size_t *count)}
+Pack the data handle into a contiguous buffer at the address @code{ptr} and set the size of the newly created buffer in @code{count}
 
 
 @item @code{int (*unpack_data)(starpu_data_handle_t handle, uint32_t node, void *ptr)}
 @item @code{int (*unpack_data)(starpu_data_handle_t handle, uint32_t node, void *ptr)}
 Unpack the data handle from the contiguous buffer at the address @code{ptr}
 Unpack the data handle from the contiguous buffer at the address @code{ptr}

+ 4 - 3
doc/chapters/mpi-support.texi

@@ -259,21 +259,22 @@ of data interface} can also be used within StarPU-MPI and exchanged
 between nodes. Two functions needs to be defined through
 between nodes. Two functions needs to be defined through
 the type @code{struct starpu_data_interface_ops} (@pxref{Data
 the type @code{struct starpu_data_interface_ops} (@pxref{Data
 Interface API}). The pack function takes a handle and returns a
 Interface API}). The pack function takes a handle and returns a
-contiguous memory buffer where data to be conveyed to another node
+contiguous memory buffer along with its size where data to be conveyed to another node
 should be copied. The reversed operation is implemented in the unpack
 should be copied. The reversed operation is implemented in the unpack
 function which takes a contiguous memory buffer and recreates the data
 function which takes a contiguous memory buffer and recreates the data
 handle.
 handle.
 
 
 @cartouche
 @cartouche
 @smallexample
 @smallexample
-static int complex_pack_data(starpu_data_handle_t handle, uint32_t node, void **ptr)
+static int complex_pack_data(starpu_data_handle_t handle, uint32_t node, void **ptr, size_t *count)
 @{
 @{
   STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
   STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
 
 
   struct starpu_complex_interface *complex_interface =
   struct starpu_complex_interface *complex_interface =
     (struct starpu_complex_interface *) starpu_data_get_interface_on_node(handle, node);
     (struct starpu_complex_interface *) starpu_data_get_interface_on_node(handle, node);
 
 
-  *ptr = malloc(complex_get_size(handle));
+  *count = complex_get_size(handle);
+  *ptr = malloc(*count);
   memcpy(*ptr, complex_interface->real, complex_interface->nx*sizeof(double));
   memcpy(*ptr, complex_interface->real, complex_interface->nx*sizeof(double));
   memcpy(*ptr+complex_interface->nx*sizeof(double), complex_interface->imaginary,
   memcpy(*ptr+complex_interface->nx*sizeof(double), complex_interface->imaginary,
          complex_interface->nx*sizeof(double));
          complex_interface->nx*sizeof(double));

+ 3 - 2
examples/interface/complex_interface.c

@@ -171,14 +171,15 @@ static void *complex_handle_to_pointer(starpu_data_handle_t handle, uint32_t nod
 	return (void*) complex_interface->real;
 	return (void*) complex_interface->real;
 }
 }
 
 
-static int complex_pack_data(starpu_data_handle_t handle, uint32_t node, void **ptr)
+static int complex_pack_data(starpu_data_handle_t handle, uint32_t node, void **ptr, size_t *count)
 {
 {
 	STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
 	STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
 
 
 	struct starpu_complex_interface *complex_interface = (struct starpu_complex_interface *)
 	struct starpu_complex_interface *complex_interface = (struct starpu_complex_interface *)
 		starpu_data_get_interface_on_node(handle, node);
 		starpu_data_get_interface_on_node(handle, node);
 
 
-	*ptr = malloc(complex_get_size(handle));
+	*count = complex_get_size(handle);
+	*ptr = malloc(*count);
 	memcpy(*ptr, complex_interface->real, complex_interface->nx*sizeof(double));
 	memcpy(*ptr, complex_interface->real, complex_interface->nx*sizeof(double));
 	memcpy(*ptr+complex_interface->nx*sizeof(double), complex_interface->imaginary, complex_interface->nx*sizeof(double));
 	memcpy(*ptr+complex_interface->nx*sizeof(double), complex_interface->imaginary, complex_interface->nx*sizeof(double));
 
 

+ 1 - 1
include/starpu_data_interfaces.h

@@ -133,7 +133,7 @@ struct starpu_data_interface_ops
 	struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface);
 	struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface);
 
 
 	/* Pack the data handle into a contiguous buffer at the address ptr and store the size of the buffer in count */
 	/* Pack the data handle into a contiguous buffer at the address ptr and store the size of the buffer in count */
-	int (*pack_data)(starpu_data_handle_t handle, uint32_t node, void **ptr);
+        int (*pack_data)(starpu_data_handle_t handle, uint32_t node, void **ptr, size_t *count);
 	/* Unpack the data handle from the contiguous buffer at the address ptr */
 	/* Unpack the data handle from the contiguous buffer at the address ptr */
 	int (*unpack_data)(starpu_data_handle_t handle, uint32_t node, void *ptr);
 	int (*unpack_data)(starpu_data_handle_t handle, uint32_t node, void *ptr);
 };
 };

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

@@ -684,8 +684,7 @@ int starpu_data_interface_get_next_id(void)
 int starpu_handle_pack_data(starpu_data_handle_t handle, void **ptr, size_t *count)
 int starpu_handle_pack_data(starpu_data_handle_t handle, void **ptr, size_t *count)
 {
 {
 	STARPU_ASSERT(handle->ops->pack_data);
 	STARPU_ASSERT(handle->ops->pack_data);
-	*count = starpu_handle_get_size(handle);
-	return handle->ops->pack_data(handle, _starpu_get_local_memory_node(), ptr);
+	return handle->ops->pack_data(handle, _starpu_get_local_memory_node(), ptr, count);
 }
 }
 
 
 int starpu_handle_unpack_data(starpu_data_handle_t handle, void *ptr)
 int starpu_handle_unpack_data(starpu_data_handle_t handle, void *ptr)