Browse Source

- Factorize the code to register a new piece of data so that adding an
interface does not imply to manipulate too many internal structures.
- Remove deadcode

Cédric Augonnet 16 years ago
parent
commit
e081dedd94

+ 32 - 29
src/datawizard/interfaces/bcsr_interface.c

@@ -47,12 +47,14 @@ static const struct copy_data_methods_s bcsr_copy_data_methods_s = {
 	.spu_to_spu = NULL
 };
 
+static void register_bcsr_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
 static size_t allocate_bcsr_buffer_on_node(starpu_data_handle handle, uint32_t dst_node);
 static void liberate_bcsr_buffer_on_node(starpu_data_interface_t *interface, uint32_t node);
 static size_t bcsr_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_bcsr_interface_crc32(starpu_data_handle handle, uint32_t hstate);
 
 struct data_interface_ops_t interface_bcsr_ops = {
+	.register_data_handle = register_bcsr_handle,
 	.allocate_data_on_node = allocate_bcsr_buffer_on_node,
 	.liberate_data_on_node = liberate_bcsr_buffer_on_node,
 	.copy_methods = &bcsr_copy_data_methods_s,
@@ -62,14 +64,9 @@ struct data_interface_ops_t interface_bcsr_ops = {
 	.footprint = footprint_bcsr_interface_crc32
 };
 
-void starpu_register_bcsr_data(starpu_data_handle *handleptr, uint32_t home_node,
-		uint32_t nnz, uint32_t nrow, uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry,  uint32_t r, uint32_t c, size_t elemsize)
+static void register_bcsr_handle(starpu_data_handle handle, uint32_t home_node, void *interface)
 {
-	starpu_data_handle handle =
-		starpu_data_state_create(&interface_bcsr_ops);
-
-	STARPU_ASSERT(handleptr);
-	*handleptr = handle;
+	starpu_bcsr_interface_t *bcsr_interface = interface;
 
 	unsigned node;
 	for (node = 0; node < MAXNODES; node++)
@@ -78,9 +75,9 @@ void starpu_register_bcsr_data(starpu_data_handle *handleptr, uint32_t home_node
 			starpu_data_get_interface_on_node(handle, node);
 
 		if (node == home_node) {
-			local_interface->nzval = nzval;
-			local_interface->colind = colind;
-			local_interface->rowptr = rowptr;
+			local_interface->nzval = bcsr_interface->nzval;
+			local_interface->colind = bcsr_interface->colind;
+			local_interface->rowptr = bcsr_interface->rowptr;
 		}
 		else {
 			local_interface->nzval = 0;
@@ -88,15 +85,33 @@ void starpu_register_bcsr_data(starpu_data_handle *handleptr, uint32_t home_node
 			local_interface->rowptr = NULL;
 		}
 
-		local_interface->nnz = nnz;
-		local_interface->nrow = nrow;
-		local_interface->firstentry = firstentry;
-		local_interface->r = r;
-		local_interface->c = c;
-		local_interface->elemsize = elemsize;
+		local_interface->nnz = bcsr_interface->nnz;
+		local_interface->nrow = bcsr_interface->nrow;
+		local_interface->firstentry = bcsr_interface->firstentry;
+		local_interface->r = bcsr_interface->r;
+		local_interface->c = bcsr_interface->c;
+		local_interface->elemsize = bcsr_interface->elemsize;
 	}
+}
 
-	register_new_data(handle, home_node, 0);
+void starpu_register_bcsr_data(starpu_data_handle *handleptr, uint32_t home_node,
+		uint32_t nnz, uint32_t nrow, uintptr_t nzval, uint32_t *colind,
+		uint32_t *rowptr, uint32_t firstentry,
+		uint32_t r, uint32_t c, size_t elemsize)
+{
+	starpu_bcsr_interface_t interface = {
+		.nzval = nzval,
+		.colind = colind,
+		.rowptr = rowptr,
+		.nnz = nnz,
+		.nrow = nrow,
+		.firstentry = firstentry,
+		.r = r,
+		.c = c,
+		.elemsize = elemsize
+	};
+
+	register_data_handle(handleptr, home_node, &interface, &interface_bcsr_ops);
 }
 
 static inline uint32_t footprint_bcsr_interface_generic(uint32_t (*hash_func)(uint32_t input, uint32_t hstate), starpu_data_handle handle, uint32_t hstate)
@@ -116,18 +131,6 @@ static uint32_t footprint_bcsr_interface_crc32(starpu_data_handle handle, uint32
 	return footprint_bcsr_interface_generic(crc32_be, handle, hstate);
 }
 
-struct dumped_bcsr_interface_s {
-	uint32_t nnz;
-	uint32_t nrow;
-	uintptr_t nzval;
-	uint32_t *colind;
-	uint32_t *rowptr;
-	uint32_t firstentry;
-	uint32_t r;
-	uint32_t c;
-	uint32_t elemsize;
-}  __attribute__ ((packed));
-
 /* offer an access to the data parameters */
 uint32_t starpu_get_bcsr_nnz(starpu_data_handle handle)
 {

+ 24 - 22
src/datawizard/interfaces/blas_interface.c

@@ -54,6 +54,7 @@ static const struct copy_data_methods_s blas_copy_data_methods_s = {
 	.spu_to_spu = NULL
 };
 
+static void register_blas_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
 static size_t allocate_blas_buffer_on_node(starpu_data_handle handle, uint32_t dst_node);
 static void liberate_blas_buffer_on_node(starpu_data_interface_t *interface, uint32_t node);
 static size_t blas_interface_get_size(starpu_data_handle handle);
@@ -64,6 +65,7 @@ static int convert_blas_to_gordon(starpu_data_interface_t *interface, uint64_t *
 #endif
 
 struct data_interface_ops_t interface_blas_ops = {
+	.register_data_handle = register_blas_handle,
 	.allocate_data_on_node = allocate_blas_buffer_on_node,
 	.liberate_data_on_node = liberate_blas_buffer_on_node,
 	.copy_methods = &blas_copy_data_methods_s,
@@ -95,16 +97,9 @@ static int convert_blas_to_gordon(starpu_data_interface_t *interface, uint64_t *
 }
 #endif
 
-/* declare a new data with the BLAS interface */
-void starpu_register_blas_data(starpu_data_handle *handleptr, uint32_t home_node,
-			uintptr_t ptr, uint32_t ld, uint32_t nx,
-			uint32_t ny, size_t elemsize)
+static void register_blas_handle(starpu_data_handle handle, uint32_t home_node, void *interface)
 {
-	starpu_data_handle handle =
-		starpu_data_state_create(&interface_blas_ops);
-
-	STARPU_ASSERT(handleptr);
-	*handleptr = handle;
+	starpu_blas_interface_t *blas_interface = interface;
 
 	unsigned node;
 	for (node = 0; node < MAXNODES; node++)
@@ -113,20 +108,34 @@ void starpu_register_blas_data(starpu_data_handle *handleptr, uint32_t home_node
 			starpu_data_get_interface_on_node(handle, node);
 
 		if (node == home_node) {
-			local_interface->ptr = ptr;
-			local_interface->ld  = ld;
+			local_interface->ptr = blas_interface->ptr;
+			local_interface->ld  = blas_interface->ld;
 		}
 		else {
 			local_interface->ptr = 0;
 			local_interface->ld  = 0;
 		}
 
-		local_interface->nx = nx;
-		local_interface->ny = ny;
-		local_interface->elemsize = elemsize;
+		local_interface->nx = blas_interface->nx;
+		local_interface->ny = blas_interface->ny;
+		local_interface->elemsize = blas_interface->elemsize;
 	}
+}
 
-	register_new_data(handle, home_node, 0);
+/* declare a new data with the BLAS interface */
+void starpu_register_blas_data(starpu_data_handle *handleptr, uint32_t home_node,
+			uintptr_t ptr, uint32_t ld, uint32_t nx,
+			uint32_t ny, size_t elemsize)
+{
+	starpu_blas_interface_t interface = {
+		.ptr = ptr,
+		.ld = ld,
+		.nx = nx,
+		.ny = ny,
+		.elemsize = elemsize
+	};
+
+	register_data_handle(handleptr, home_node, &interface, &interface_blas_ops);
 }
 
 static inline uint32_t footprint_blas_interface_generic(uint32_t (*hash_func)(uint32_t input, uint32_t hstate), starpu_data_handle handle, uint32_t hstate)
@@ -145,13 +154,6 @@ static uint32_t footprint_blas_interface_crc32(starpu_data_handle handle, uint32
 	return footprint_blas_interface_generic(crc32_be, handle, hstate);
 }
 
-struct dumped_blas_interface_s {
-	uintptr_t ptr;
-	uint32_t nx;
-	uint32_t ny;
-	uint32_t ld;
-} __attribute__ ((packed));
-
 static void display_blas_interface(starpu_data_handle handle, FILE *f)
 {
 	starpu_blas_interface_t *interface =

+ 28 - 26
src/datawizard/interfaces/block_interface.c

@@ -48,6 +48,7 @@ static const struct copy_data_methods_s block_copy_data_methods_s = {
 };
 
 
+static void register_block_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
 static size_t allocate_block_buffer_on_node(starpu_data_handle handle, uint32_t dst_node);
 static void liberate_block_buffer_on_node(starpu_data_interface_t *interface, uint32_t node);
 static size_t block_interface_get_size(starpu_data_handle handle);
@@ -58,6 +59,7 @@ static int convert_block_to_gordon(starpu_data_interface_t *interface, uint64_t
 #endif
 
 struct data_interface_ops_t interface_block_ops = {
+	.register_data_handle = register_block_handle,
 	.allocate_data_on_node = allocate_block_buffer_on_node,
 	.liberate_data_on_node = liberate_block_buffer_on_node,
 	.copy_methods = &block_copy_data_methods_s,
@@ -81,16 +83,9 @@ int convert_block_to_gordon(starpu_data_interface_t *interface, uint64_t *ptr, g
 }
 #endif
 
-/* declare a new data with the BLAS interface */
-void starpu_register_block_data(starpu_data_handle *handleptr, uint32_t home_node,
-			uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
-			uint32_t ny, uint32_t nz, size_t elemsize)
+static void register_block_handle(starpu_data_handle handle, uint32_t home_node, void *interface)
 {
-	starpu_data_handle handle =
-		starpu_data_state_create(&interface_block_ops);
-
-	STARPU_ASSERT(handleptr);
-	*handleptr = handle;
+	starpu_block_interface_t *block_interface = interface;
 
 	unsigned node;
 	for (node = 0; node < MAXNODES; node++)
@@ -99,9 +94,9 @@ void starpu_register_block_data(starpu_data_handle *handleptr, uint32_t home_nod
 			starpu_data_get_interface_on_node(handle, node);
 
 		if (node == home_node) {
-			local_interface->ptr = ptr;
-			local_interface->ldy  = ldy;
-			local_interface->ldz  = ldz;
+			local_interface->ptr = block_interface->ptr;
+			local_interface->ldy  = block_interface->ldy;
+			local_interface->ldz  = block_interface->ldz;
 		}
 		else {
 			local_interface->ptr = 0;
@@ -109,13 +104,29 @@ void starpu_register_block_data(starpu_data_handle *handleptr, uint32_t home_nod
 			local_interface->ldz  = 0;
 		}
 
-		local_interface->nx = nx;
-		local_interface->ny = ny;
-		local_interface->nz = nz;
-		local_interface->elemsize = elemsize;
+		local_interface->nx = block_interface->nx;
+		local_interface->ny = block_interface->ny;
+		local_interface->nz = block_interface->nz;
+		local_interface->elemsize = block_interface->elemsize;
 	}
+}
 
-	register_new_data(handle, home_node, 0);
+/* declare a new data with the BLAS interface */
+void starpu_register_block_data(starpu_data_handle *handleptr, uint32_t home_node,
+			uintptr_t ptr, uint32_t ldy, uint32_t ldz, uint32_t nx,
+			uint32_t ny, uint32_t nz, size_t elemsize)
+{
+	starpu_block_interface_t interface = {
+		.ptr = ptr,
+		.ldy = ldy,
+		.ldz = ldz,
+		.nx = nx,
+		.ny = ny,
+		.nz = nz,
+		.elemsize = elemsize
+	};
+
+	register_data_handle(handleptr, home_node, &interface, &interface_block_ops);
 }
 
 static inline uint32_t footprint_block_interface_generic(uint32_t (*hash_func)(uint32_t input, uint32_t hstate), starpu_data_handle handle, uint32_t hstate)
@@ -135,15 +146,6 @@ static uint32_t footprint_block_interface_crc32(starpu_data_handle handle, uint3
 	return footprint_block_interface_generic(crc32_be, handle, hstate);
 }
 
-struct dumped_block_interface_s {
-	uintptr_t ptr;
-	uint32_t nx;
-	uint32_t ny;
-	uint32_t nz;
-	uint32_t ldy;
-	uint32_t ldz;
-} __attribute__ ((packed));
-
 static void display_block_interface(starpu_data_handle handle, FILE *f)
 {
 	starpu_block_interface_t *interface;

+ 27 - 27
src/datawizard/interfaces/csr_interface.c

@@ -43,13 +43,14 @@ static const struct copy_data_methods_s csr_copy_data_methods_s = {
 	.spu_to_spu = NULL
 };
 
-
+static void register_csr_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
 static size_t allocate_csr_buffer_on_node(starpu_data_handle handle, uint32_t dst_node);
 static void liberate_csr_buffer_on_node(starpu_data_interface_t *interface, uint32_t node);
 static size_t csr_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_csr_interface_crc32(starpu_data_handle handle, uint32_t hstate);
 
 struct data_interface_ops_t interface_csr_ops = {
+	.register_data_handle = register_csr_handle,
 	.allocate_data_on_node = allocate_csr_buffer_on_node,
 	.liberate_data_on_node = liberate_csr_buffer_on_node,
 	.copy_methods = &csr_copy_data_methods_s,
@@ -59,15 +60,9 @@ struct data_interface_ops_t interface_csr_ops = {
 	.footprint = footprint_csr_interface_crc32
 };
 
-/* declare a new data with the BLAS interface */
-void starpu_register_csr_data(starpu_data_handle *handleptr, uint32_t home_node,
-		uint32_t nnz, uint32_t nrow, uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize)
+static void register_csr_handle(starpu_data_handle handle, uint32_t home_node, void *interface)
 {
-	starpu_data_handle handle =
-		starpu_data_state_create(&interface_csr_ops);	
-
-	STARPU_ASSERT(handleptr);
-	*handleptr = handle;
+	starpu_csr_interface_t *csr_interface = interface;
 
 	unsigned node;
 	for (node = 0; node < MAXNODES; node++)
@@ -76,9 +71,9 @@ void starpu_register_csr_data(starpu_data_handle *handleptr, uint32_t home_node,
 			starpu_data_get_interface_on_node(handle, node);
 
 		if (node == home_node) {
-			local_interface->nzval = nzval;
-			local_interface->colind = colind;
-			local_interface->rowptr = rowptr;
+			local_interface->nzval = csr_interface->nzval;
+			local_interface->colind = csr_interface->colind;
+			local_interface->rowptr = csr_interface->rowptr;
 		}
 		else {
 			local_interface->nzval = 0;
@@ -86,14 +81,29 @@ void starpu_register_csr_data(starpu_data_handle *handleptr, uint32_t home_node,
 			local_interface->rowptr = NULL;
 		}
 
-		local_interface->nnz = nnz;
-		local_interface->nrow = nrow;
-		local_interface->firstentry = firstentry;
-		local_interface->elemsize = elemsize;
+		local_interface->nnz = csr_interface->nnz;
+		local_interface->nrow = csr_interface->nrow;
+		local_interface->firstentry = csr_interface->firstentry;
+		local_interface->elemsize = csr_interface->elemsize;
 
 	}
+}
 
-	register_new_data(handle, home_node, 0);
+/* declare a new data with the BLAS interface */
+void starpu_register_csr_data(starpu_data_handle *handleptr, uint32_t home_node,
+		uint32_t nnz, uint32_t nrow, uintptr_t nzval, uint32_t *colind, uint32_t *rowptr, uint32_t firstentry, size_t elemsize)
+{
+	starpu_csr_interface_t interface = {
+		.nnz = nnz,
+		.nrow = nrow,
+		.nzval = nzval,
+		.colind = colind,
+		.rowptr = rowptr,
+		.firstentry = firstentry,
+		.elemsize = elemsize
+	};
+
+	register_data_handle(handleptr, home_node, &interface, &interface_csr_ops);
 }
 
 static inline uint32_t footprint_csr_interface_generic(uint32_t (*hash_func)(uint32_t input, uint32_t hstate), starpu_data_handle handle, uint32_t hstate)
@@ -111,16 +121,6 @@ static uint32_t footprint_csr_interface_crc32(starpu_data_handle handle, uint32_
 	return footprint_csr_interface_generic(crc32_be, handle, hstate);
 }
 
-struct dumped_csr_interface_s {
-	uint32_t nnz;
-	uint32_t nrow;
-	uintptr_t nzval;
-	uint32_t *colind;
-	uint32_t *rowptr;
-	uint32_t firstentry;
-	uint32_t elemsize;
-}  __attribute__ ((packed));
-
 /* offer an access to the data parameters */
 uint32_t starpu_get_csr_nnz(starpu_data_handle handle)
 {

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

@@ -26,4 +26,19 @@ void *starpu_data_get_interface_on_node(starpu_data_handle handle, unsigned memo
 	return handle->interface[memory_node];
 }
 
+void register_data_handle(starpu_data_handle *handleptr, uint32_t home_node,
+				void *interface,
+				struct data_interface_ops_t *ops)
+{
+	starpu_data_handle handle =
+		starpu_data_state_create(ops);
+
+	STARPU_ASSERT(handleptr);
+	*handleptr = handle;
+
+	/* fill the interface fields with the appropriate method */
+	ops->register_data_handle(handle, home_node, interface);
+
+	register_new_data(handle, home_node, 0);
+}
 /* register data interface ? (do we need to register ?) descr =  type enum, required to get an id !  */

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

@@ -27,6 +27,8 @@
 #endif
 
 struct data_interface_ops_t {
+	void (*register_data_handle)(starpu_data_handle handle,
+					uint32_t home_node, void *interface);
 	size_t (*allocate_data_on_node)(starpu_data_handle handle, uint32_t node);
 	void (*liberate_data_on_node)(starpu_data_interface_t *interface,
 					uint32_t node);
@@ -42,4 +44,8 @@ struct data_interface_ops_t {
 	size_t interface_size;
 };
 
+void register_data_handle(starpu_data_handle *handleptr, uint32_t home_node,
+				void *interface,
+				struct data_interface_ops_t *ops);
+
 #endif // __DATA_INTERFACE_H__

+ 29 - 28
src/datawizard/interfaces/vector_interface.c

@@ -52,6 +52,7 @@ static const struct copy_data_methods_s vector_copy_data_methods_s = {
 	.spu_to_spu = NULL
 };
 
+static void register_vector_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
 static size_t allocate_vector_buffer_on_node(starpu_data_handle handle, uint32_t dst_node);
 static void liberate_vector_buffer_on_node(starpu_data_interface_t *interface, uint32_t node);
 static size_t vector_interface_get_size(starpu_data_handle handle);
@@ -62,6 +63,7 @@ static int convert_vector_to_gordon(starpu_data_interface_t *interface, uint64_t
 #endif
 
 struct data_interface_ops_t interface_vector_ops = {
+	.register_data_handle = register_vector_handle,
 	.allocate_data_on_node = allocate_vector_buffer_on_node,
 	.liberate_data_on_node = liberate_vector_buffer_on_node,
 	.copy_methods = &vector_copy_data_methods_s,
@@ -75,25 +77,9 @@ struct data_interface_ops_t interface_vector_ops = {
 	.display = display_vector_interface
 };
 
-#ifdef USE_GORDON
-int convert_vector_to_gordon(starpu_data_interface_t *interface, uint64_t *ptr, gordon_strideSize_t *ss) 
-{
-	*ptr = (*interface).vector.ptr;
-	(*ss).size = (*interface).vector.nx * (*interface).vector.elemsize;
-
-	return 0;
-}
-#endif
-
-/* declare a new data with the vector interface */
-void starpu_register_vector_data(starpu_data_handle *handleptr, uint32_t home_node,
-                        uintptr_t ptr, uint32_t nx, size_t elemsize)
+static void register_vector_handle(starpu_data_handle handle, uint32_t home_node, void *interface)
 {
-	starpu_data_handle handle =
-		starpu_data_state_create(&interface_vector_ops);
-
-	STARPU_ASSERT(handleptr);
-	*handleptr = handle;
+	starpu_vector_interface_t *vector_interface = interface;
 
 	unsigned node;
 	for (node = 0; node < MAXNODES; node++)
@@ -102,17 +88,38 @@ void starpu_register_vector_data(starpu_data_handle *handleptr, uint32_t home_no
 			starpu_data_get_interface_on_node(handle, node);
 
 		if (node == home_node) {
-			local_interface->ptr = ptr;
+			local_interface->ptr = vector_interface->ptr;
 		}
 		else {
 			local_interface->ptr = 0;
 		}
 
-		local_interface->nx = nx;
-		local_interface->elemsize = elemsize;
+		local_interface->nx = vector_interface->nx;
+		local_interface->elemsize = vector_interface->elemsize;
 	}
+}
 
-	register_new_data(handle, home_node, 0);
+#ifdef USE_GORDON
+int convert_vector_to_gordon(starpu_data_interface_t *interface, uint64_t *ptr, gordon_strideSize_t *ss) 
+{
+	*ptr = (*interface).vector.ptr;
+	(*ss).size = (*interface).vector.nx * (*interface).vector.elemsize;
+
+	return 0;
+}
+#endif
+
+/* declare a new data with the vector interface */
+void starpu_register_vector_data(starpu_data_handle *handleptr, uint32_t home_node,
+                        uintptr_t ptr, uint32_t nx, size_t elemsize)
+{
+	starpu_vector_interface_t vector = {
+		.ptr = ptr,
+		.nx = nx,
+		.elemsize = elemsize
+	};	
+
+	register_data_handle(handleptr, home_node, &vector, &interface_vector_ops); 
 }
 
 
@@ -131,12 +138,6 @@ uint32_t footprint_vector_interface_crc32(starpu_data_handle handle, uint32_t hs
 	return footprint_vector_interface_generic(crc32_be, handle, hstate);
 }
 
-struct dumped_vector_interface_s {
-	uintptr_t ptr;
-	uint32_t nx;
-	uint32_t elemsize;
-} __attribute__ ((packed));
-
 static void display_vector_interface(starpu_data_handle handle, FILE *f)
 {
 	starpu_vector_interface_t *interface =