Selaa lähdekoodia

Get rid off operation allocate_new_data defined in struct starpu_data_interface_ops, and define instead a generic function

   void starpu_data_register_same(starpu_data_handle_t *handledst, starpu_data_handle_t handlesrc);

which creates a new handle based on the given handle
Nathalie Furmento 13 vuotta sitten
vanhempi
commit
4442d47422

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

@@ -68,8 +68,6 @@ An identifier that is unique to each interface.
 @item @code{size_t interface_size}
 The size of the interface data descriptor.
 
-@item @code{ void (*allocate_new_data)(starpu_data_handle_t handle, void **data_interface)}
-Create a new data interface of the given type based on the handle @var{handle}.
 @end table
 @end deftp
 

+ 1 - 3
include/starpu_data_interfaces.h

@@ -130,9 +130,6 @@ struct starpu_data_interface_ops
 	/* The size of the interface data descriptor */
 	size_t interface_size;
 
-	/* */
-	void (*allocate_new_data)(starpu_data_handle_t handle, void **data_interface);
-
 	int is_multiformat;
 	struct starpu_multiformat_data_interface_ops* (*get_mf_ops)(void *data_interface);
 };
@@ -141,6 +138,7 @@ struct starpu_data_interface_ops
 int starpu_data_interface_get_next_id();
 
 void starpu_data_register(starpu_data_handle_t *handleptr, uint32_t home_node, void *data_interface, struct starpu_data_interface_ops *ops);
+void starpu_data_register_same(starpu_data_handle_t *handledst, starpu_data_handle_t handlesrc);
 
 /* Return the pointer associated with HANDLE on node NODE or NULL if HANDLE's
  * interface does not support this operation or data for this handle is not

+ 1 - 5
mpi/starpu_mpi_insert_task.c

@@ -446,15 +446,11 @@ void starpu_mpi_redux_data(MPI_Comm comm, starpu_data_handle_t data_handle)
 	if (me == rank) {
 		int i;
 
-		STARPU_ASSERT(data_handle->ops->allocate_new_data);
-
 		for(i=0 ; i<nb_nodes ; i++) {
 			if (i != rank) {
-				void *data_interface;
 				starpu_data_handle_t new_handle;
 
-				data_handle->ops->allocate_new_data(data_handle, &data_interface);
-				starpu_data_register(&new_handle, -1, data_interface, data_handle->ops);
+				starpu_data_register_same(&new_handle, data_handle);
 
 				_STARPU_MPI_DEBUG("Receiving redux handle from %d in %p ...\n", i, new_handle);
 

+ 0 - 17
src/datawizard/interfaces/block_interface.c

@@ -77,7 +77,6 @@ static void display_block_interface(starpu_data_handle_t handle, FILE *f);
 #ifdef STARPU_USE_GORDON
 static int convert_block_to_gordon(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss);
 #endif
-static void allocate_new_block(starpu_data_handle_t handle, void **data_interface);
 
 static struct starpu_data_interface_ops interface_block_ops =
 {
@@ -95,7 +94,6 @@ static struct starpu_data_interface_ops interface_block_ops =
 	.interfaceid = STARPU_BLOCK_INTERFACE_ID,
 	.interface_size = sizeof(struct starpu_block_interface),
 	.display = display_block_interface,
-	.allocate_new_data = allocate_new_block
 };
 
 #ifdef STARPU_USE_GORDON
@@ -407,21 +405,6 @@ static void free_block_buffer_on_node(void *data_interface, uint32_t node)
 	}
 }
 
-static void allocate_new_block(starpu_data_handle_t handle, void **data_interface)
-{
-	struct starpu_block_interface *block_interface = (struct starpu_block_interface *)malloc(sizeof(struct starpu_block_interface));
-	block_interface->ptr = (uintptr_t) NULL;
-	block_interface->dev_handle = (uintptr_t) NULL;
-	block_interface->offset = 0;
-	block_interface->nx = starpu_block_get_nx(handle);
-	block_interface->ny = starpu_block_get_ny(handle);
-	block_interface->nz = starpu_block_get_nz(handle);
-	block_interface->ldy = starpu_block_get_local_ldy(handle);
-	block_interface->ldz = starpu_block_get_local_ldz(handle);
-	block_interface->elemsize = starpu_block_get_elemsize(handle);
-	*data_interface = block_interface;
-}
-
 #ifdef STARPU_USE_CUDA
 static int copy_cuda_common(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, enum cudaMemcpyKind kind)
 {

+ 0 - 14
src/datawizard/interfaces/csr_interface.c

@@ -70,7 +70,6 @@ static void free_csr_buffer_on_node(void *data_interface, uint32_t node);
 static size_t csr_interface_get_size(starpu_data_handle_t handle);
 static int csr_compare(void *data_interface_a, void *data_interface_b);
 static uint32_t footprint_csr_interface_crc32(starpu_data_handle_t handle);
-static void allocate_new_csr(starpu_data_handle_t handle, void **data_interface);
 
 static struct starpu_data_interface_ops interface_csr_ops =
 {
@@ -83,7 +82,6 @@ static struct starpu_data_interface_ops interface_csr_ops =
 	.interface_size = sizeof(struct starpu_csr_interface),
 	.footprint = footprint_csr_interface_crc32,
 	.compare = csr_compare,
-	.allocate_new_data = allocate_new_csr
 };
 
 static void register_csr_handle(starpu_data_handle_t handle, uint32_t home_node, void *data_interface)
@@ -415,18 +413,6 @@ static void free_csr_buffer_on_node(void *data_interface, uint32_t node)
 	}
 }
 
-static void allocate_new_csr(starpu_data_handle_t handle, void **data_interface)
-{
-	struct starpu_csr_interface *csr_interface = (struct starpu_csr_interface *)malloc(sizeof(struct starpu_csr_interface));
-	csr_interface->nnz = starpu_csr_get_nnz(handle);
-	csr_interface->nrow = starpu_csr_get_nrow(handle);
-	csr_interface->nzval = starpu_csr_get_local_nzval(handle);
-	csr_interface->colind = starpu_csr_get_local_colind(handle);
-	csr_interface->rowptr = starpu_csr_get_local_rowptr(handle);
-	csr_interface->elemsize = starpu_csr_get_elemsize(handle);
-	*data_interface = csr_interface;
-}
-
 #ifdef STARPU_USE_CUDA
 static int copy_cuda_common(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, enum cudaMemcpyKind kind)
 {

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

@@ -295,6 +295,12 @@ void starpu_data_register(starpu_data_handle_t *handleptr, uint32_t home_node,
 	_starpu_register_new_data(handle, home_node, 0);
 }
 
+void starpu_data_register_same(starpu_data_handle_t *handledst, starpu_data_handle_t handlesrc)
+{
+	void *local_interface = starpu_data_get_interface_on_node(handlesrc, 0);
+	starpu_data_register(handledst, -1, local_interface, handlesrc->ops);
+}
+
 void *starpu_handle_to_pointer(starpu_data_handle_t handle, uint32_t node)
 {
 	/* Check whether the operation is supported and the node has actually

+ 0 - 15
src/datawizard/interfaces/matrix_interface.c

@@ -83,7 +83,6 @@ static void display_matrix_interface(starpu_data_handle_t handle, FILE *f);
 #ifdef STARPU_USE_GORDON
 static int convert_matrix_to_gordon(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss);
 #endif
-static void allocate_new_matrix(starpu_data_handle_t handle, void **data_interface);
 
 struct starpu_data_interface_ops _starpu_interface_matrix_ops =
 {
@@ -101,7 +100,6 @@ struct starpu_data_interface_ops _starpu_interface_matrix_ops =
 	.interfaceid = STARPU_MATRIX_INTERFACE_ID,
 	.interface_size = sizeof(struct starpu_matrix_interface),
 	.display = display_matrix_interface,
-	.allocate_new_data = allocate_new_matrix
 };
 
 #ifdef STARPU_USE_GORDON
@@ -385,19 +383,6 @@ static void free_matrix_buffer_on_node(void *data_interface, uint32_t node)
 	}
 }
 
-static void allocate_new_matrix(starpu_data_handle_t handle, void **data_interface)
-{
-	struct starpu_matrix_interface *matrix_interface = (struct starpu_matrix_interface *)malloc(sizeof(struct starpu_matrix_interface));
-	matrix_interface->ptr = (uintptr_t) NULL;
-	matrix_interface->dev_handle = (uintptr_t) NULL;
-	matrix_interface->offset = 0;
-	matrix_interface->nx = starpu_matrix_get_nx(handle);
-	matrix_interface->ny = starpu_matrix_get_ny(handle);
-	matrix_interface->ld = starpu_matrix_get_local_ld(handle);
-	matrix_interface->elemsize = starpu_matrix_get_elemsize(handle);
-	*data_interface = matrix_interface;
-}
-
 #ifdef STARPU_USE_CUDA
 static int copy_cuda_common(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED, void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, enum cudaMemcpyKind kind, int is_async, cudaStream_t stream)
 {

+ 0 - 10
src/datawizard/interfaces/variable_interface.c

@@ -78,7 +78,6 @@ static void display_variable_interface(starpu_data_handle_t handle, FILE *f);
 #ifdef STARPU_USE_GORDON
 static int convert_variable_to_gordon(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss);
 #endif
-static void allocate_new_variable(starpu_data_handle_t handle, void **data_interface);
 
 static struct starpu_data_interface_ops interface_variable_ops =
 {
@@ -96,7 +95,6 @@ static struct starpu_data_interface_ops interface_variable_ops =
 	.interfaceid = STARPU_VARIABLE_INTERFACE_ID,
 	.interface_size = sizeof(struct starpu_variable_interface),
 	.display = display_variable_interface,
-	.allocate_new_data = allocate_new_variable
 };
 
 static void *variable_handle_to_pointer(starpu_data_handle_t handle, uint32_t node)
@@ -287,14 +285,6 @@ static void free_variable_buffer_on_node(void *data_interface, uint32_t node)
 	}
 }
 
-static void allocate_new_variable(starpu_data_handle_t handle, void **data_interface)
-{
-	struct starpu_variable_interface *variable_interface = (struct starpu_variable_interface *)malloc(sizeof(struct starpu_variable_interface));
-	variable_interface->ptr = (uintptr_t) NULL;
-	variable_interface->elemsize = handle->ops->get_size(handle);
-	*data_interface = variable_interface;
-}
-
 #ifdef STARPU_USE_CUDA
 static int copy_cuda_common(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
 				void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, enum cudaMemcpyKind kind)

+ 0 - 13
src/datawizard/interfaces/vector_interface.c

@@ -78,7 +78,6 @@ static void display_vector_interface(starpu_data_handle_t handle, FILE *f);
 #ifdef STARPU_USE_GORDON
 static int convert_vector_to_gordon(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss);
 #endif
-static void allocate_new_vector(starpu_data_handle_t handle, void **data_interface);
 
 static struct starpu_data_interface_ops interface_vector_ops =
 {
@@ -96,7 +95,6 @@ static struct starpu_data_interface_ops interface_vector_ops =
 	.interfaceid = STARPU_VECTOR_INTERFACE_ID,
 	.interface_size = sizeof(struct starpu_vector_interface),
 	.display = display_vector_interface,
-	.allocate_new_data = allocate_new_vector
 };
 
 static void *vector_handle_to_pointer(starpu_data_handle_t handle, uint32_t node)
@@ -332,17 +330,6 @@ static void free_vector_buffer_on_node(void *data_interface, uint32_t node)
 	}
 }
 
-static void allocate_new_vector(starpu_data_handle_t handle, void **data_interface)
-{
-	struct starpu_vector_interface *vector_interface = (struct starpu_vector_interface *)malloc(sizeof(struct starpu_vector_interface));
-	vector_interface->ptr = (uintptr_t) NULL;
-	vector_interface->dev_handle = (uintptr_t) NULL;
-	vector_interface->offset = 0;
-	vector_interface->nx = starpu_vector_get_nx(handle);
-	vector_interface->elemsize = starpu_vector_get_elemsize(handle);
-	*data_interface = vector_interface;
-}
-
 #ifdef STARPU_USE_CUDA
 static int copy_cuda_common(void *src_interface, unsigned src_node STARPU_ATTRIBUTE_UNUSED,
 				void *dst_interface, unsigned dst_node STARPU_ATTRIBUTE_UNUSED, enum cudaMemcpyKind kind)

+ 3 - 3
tests/datawizard/interfaces/copy_interfaces.c

@@ -24,9 +24,7 @@ static int check_copy(starpu_data_handle_t handle, char *header)
 	starpu_data_handle_t new_handle;
 	int ret=0;
 
-	STARPU_ASSERT(handle->ops->allocate_new_data);
-	handle->ops->allocate_new_data(handle, &new_interface);
-	starpu_data_register(&new_handle, -1, new_interface, handle->ops);
+	starpu_data_register_same(&new_handle, handle);
 
 	if (!getenv("STARPU_SSILENT") && new_handle->ops->display)
 	{
@@ -36,6 +34,8 @@ static int check_copy(starpu_data_handle_t handle, char *header)
 	}
 
 	old_interface = starpu_data_get_interface_on_node(handle, 0);
+	new_interface = starpu_data_get_interface_on_node(new_handle, 0);
+
 	if (new_handle->ops->compare(old_interface, new_interface) == 0)
 	{
 		FPRINTF(stderr, "Error when copying %s data\n", header);