Browse Source

Fix confusion between local pointer, ram pointer, and home pointer:
- starpu_data_lookup actually wants the ram pointer.
- MPI actually wants the local pointer.

Make starpu_handle_to_pointer() take a node parameter instead of assuming local
pointer and documenting home pointer.

Samuel Thibault 14 years ago
parent
commit
febecc5fa2

+ 23 - 5
include/starpu_data_interfaces.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010  Université de Bordeaux 1
+ * Copyright (C) 2010-2011  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  * Copyright (C) 2011  Institut National de Recherche en Informatique et Automatique
  *
@@ -84,21 +84,34 @@ struct starpu_data_copy_methods {
 };
 
 struct starpu_data_interface_ops_t {
+	/* Register an existing interface into a data handle. */
 	void (*register_data_handle)(starpu_data_handle handle,
 					uint32_t home_node, void *data_interface);
+	/* Allocate data for the interface on a given node. */
 	starpu_ssize_t (*allocate_data_on_node)(void *data_interface, uint32_t node);
+	/* Free data of the interface on a given node. */
 	void (*free_data_on_node)(void *data_interface, uint32_t node);
+	/* ram/cuda/spu/opencl synchronous and asynchronous transfer methods */
 	const struct starpu_data_copy_methods *copy_methods;
-	void * (*handle_to_pointer)(starpu_data_handle handle);
+	/* Return the current pointer (if any) for the handle on the given node. */
+	void * (*handle_to_pointer)(starpu_data_handle handle, uint32_t node);
+	/* Return the pointer for the handle on the current worker node. */
+	uintptr_t (*get_local_ptr)(starpu_data_handle handle);
+	/* Return an estimation of the size of data, for performance models */
 	size_t (*get_size)(starpu_data_handle handle);
+	/* Return a 32bit footprint which characterizes the data size */
 	uint32_t (*footprint)(starpu_data_handle handle);
+	/* Compare the data size of two interfaces */
 	int (*compare)(void *data_interface_a, void *data_interface_b);
+	/* Dump the sizes of a handle to a file */
 	void (*display)(starpu_data_handle handle, FILE *f);
 #ifdef STARPU_USE_GORDON
+	/* Convert the data size to the spu size format */
 	int (*convert_to_gordon)(void *data_interface, uint64_t *ptr, gordon_strideSize_t *ss); 
 #endif
 	/* an identifier that is unique to each interface */
 	unsigned interfaceid;
+	/* The size of the interface data descriptor */
 	size_t interface_size;
 };
 
@@ -106,10 +119,14 @@ void starpu_data_register(starpu_data_handle *handleptr, uint32_t home_node,
 				void *data_interface,
 				struct starpu_data_interface_ops_t *ops);
 
+/* 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
+ * allocated on that node. */
+void *starpu_handle_to_pointer(starpu_data_handle handle, uint32_t node);
+
 /* Return the local pointer associated with HANDLE or NULL if HANDLE's
- * interface does not support this operation or if HANDLE has a "home node"
- * equal to -1.  */
-void *starpu_handle_to_pointer(starpu_data_handle handle);
+ * interface does not have data allocated locally */
+void *starpu_handle_get_local_ptr(starpu_data_handle handle);
 
 extern struct starpu_data_interface_ops_t _starpu_interface_matrix_ops;
 
@@ -306,6 +323,7 @@ size_t starpu_bcsr_get_elemsize(starpu_data_handle);
 
 unsigned starpu_get_handle_interface_id(starpu_data_handle);
 
+/* Lookup a ram pointer into a StarPU handle */
 extern starpu_data_handle starpu_data_lookup(const void *ptr);
 
 #ifdef __cplusplus

+ 2 - 2
mpi/starpu_mpi_datatype.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009-2011  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -144,5 +144,5 @@ int starpu_mpi_handle_to_datatype(starpu_data_handle data_handle, MPI_Datatype *
 
 void *starpu_mpi_handle_to_ptr(starpu_data_handle data_handle)
 {
-	return starpu_handle_to_pointer(data_handle);
+	return (void*) starpu_handle_get_local_ptr(data_handle);
 }

+ 3 - 3
src/datawizard/filters.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010  Université de Bordeaux 1
+ * Copyright (C) 2010-2011  Université de Bordeaux 1
  * Copyright (C) 2010  Mehdi Juhoor <mjuhoor@gmail.com>
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
@@ -222,10 +222,10 @@ void starpu_data_partition(starpu_data_handle initial_handle, struct starpu_data
 		child->footprint = _starpu_compute_data_footprint(child);
 
 		void *ptr;
-		ptr = starpu_handle_to_pointer(child);
+		ptr = starpu_handle_to_pointer(child, 0);
 		if (ptr != NULL)
 		{
-			_starpu_data_register_local_pointer(child, ptr);
+			_starpu_data_register_ram_pointer(child, ptr);
 		}
 	}
 	/* now let the header */

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

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009-2011  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -66,7 +66,7 @@ static const struct starpu_data_copy_methods block_copy_data_methods_s = {
 
 
 static void register_block_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface);
-static void *block_handle_to_pointer(starpu_data_handle data_handle);
+static void *block_handle_to_pointer(starpu_data_handle data_handle, uint32_t node);
 static ssize_t allocate_block_buffer_on_node(void *data_interface_, uint32_t dst_node);
 static void free_block_buffer_on_node(void *data_interface, uint32_t node);
 static size_t block_interface_get_size(starpu_data_handle handle);
@@ -81,6 +81,7 @@ static struct starpu_data_interface_ops_t interface_block_ops = {
 	.register_data_handle = register_block_handle,
 	.allocate_data_on_node = allocate_block_buffer_on_node,
 	.handle_to_pointer = block_handle_to_pointer,
+	.get_local_ptr = starpu_block_get_local_ptr,
 	.free_data_on_node = free_block_buffer_on_node,
 	.copy_methods = &block_copy_data_methods_s,
 	.get_size = block_interface_get_size,
@@ -104,9 +105,14 @@ int convert_block_to_gordon(void *data_interface, uint64_t *ptr, gordon_strideSi
 }
 #endif
 
-static void *block_handle_to_pointer(starpu_data_handle data_handle)
+static void *block_handle_to_pointer(starpu_data_handle handle, uint32_t node)
 {
-	return (void *)starpu_block_get_local_ptr(data_handle);
+	STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
+
+	starpu_block_interface_t *block_interface =
+		starpu_data_get_interface_on_node(handle, node);
+
+	return (void*) block_interface->ptr;
 }
 
 static void register_block_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface)

+ 23 - 10
src/datawizard/interfaces/data_interface.c

@@ -55,7 +55,7 @@ void _starpu_data_interface_shutdown()
 
 /* Register the mapping from PTR to HANDLE.  If PTR is already mapped to
  * some handle, the new mapping shadows the previous one.   */
-void _starpu_data_register_local_pointer(starpu_data_handle handle, void *ptr)
+void _starpu_data_register_ram_pointer(starpu_data_handle handle, void *ptr)
 {
 	struct handle_entry *entry;
 
@@ -204,10 +204,10 @@ static void _starpu_register_new_data(starpu_data_handle handle,
 	/* now the data is available ! */
 	_starpu_spin_unlock(&handle->header_lock);
 
-	ptr = starpu_handle_to_pointer(handle);
+	ptr = starpu_handle_to_pointer(handle, 0);
 	if (ptr != NULL)
 	{
-		_starpu_data_register_local_pointer(handle, ptr);
+		_starpu_data_register_ram_pointer(handle, ptr);
 	}
 }
 
@@ -269,7 +269,20 @@ void starpu_data_register(starpu_data_handle *handleptr, uint32_t home_node,
 	_starpu_register_new_data(handle, home_node, 0);
 }
 
-void *starpu_handle_to_pointer(starpu_data_handle handle)
+void *starpu_handle_to_pointer(starpu_data_handle handle, uint32_t node)
+{
+	/* Check whether the operation is supported and the node has actually
+	 * been allocated.  */
+	if (handle->ops->handle_to_pointer
+	    && starpu_data_test_if_allocated_on_node(handle, node))
+	{
+		return handle->ops->handle_to_pointer(handle, node);
+	}
+
+	return NULL;
+}
+
+void *starpu_handle_get_local_ptr(starpu_data_handle handle)
 {
 	unsigned int local_node;
 
@@ -277,10 +290,10 @@ void *starpu_handle_to_pointer(starpu_data_handle handle)
 
 	/* Check whether the operation is supported and the node has actually
 	 * been allocated.  */
-	if (handle->ops->handle_to_pointer
+	if (handle->ops->get_local_ptr
 	    && starpu_data_test_if_allocated_on_node(handle, local_node))
 	{
-		return handle->ops->handle_to_pointer(handle);
+		return (void*) handle->ops->get_local_ptr(handle);
 	}
 
 	return NULL;
@@ -303,12 +316,12 @@ int starpu_data_set_rank(starpu_data_handle handle, int rank)
 
 void _starpu_data_free_interfaces(starpu_data_handle handle)
 {
-	const void *ptr;
+	const void *ram_ptr;
 	unsigned node;
 	unsigned worker;
 	unsigned nworkers = starpu_worker_get_count();
 
-	ptr = starpu_handle_to_pointer(handle);
+	ram_ptr = starpu_handle_to_pointer(handle, 0);
 
 	for (node = 0; node < STARPU_MAXNODES; node++)
 		free(handle->per_node[node].data_interface);
@@ -316,7 +329,7 @@ void _starpu_data_free_interfaces(starpu_data_handle handle)
 	for (worker = 0; worker < nworkers; worker++)
 		free(handle->per_worker[worker].data_interface);
 
-	if (ptr != NULL)
+	if (ram_ptr != NULL)
 	{
 		/* Remove the PTR -> HANDLE mapping.  If a mapping from PTR
 		 * to another handle existed before (e.g., when using
@@ -324,7 +337,7 @@ void _starpu_data_free_interfaces(starpu_data_handle handle)
 		struct handle_entry *entry;
 
 		_starpu_spin_lock(&registered_handles_lock);
-		HASH_FIND_PTR(registered_handles, &ptr, entry);
+		HASH_FIND_PTR(registered_handles, &ram_ptr, entry);
 		STARPU_ASSERT(entry != NULL);
 
 		HASH_DEL(registered_handles, entry);

+ 2 - 2
src/datawizard/interfaces/data_interface.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009-2011  Université de Bordeaux 1
  * Copyright (C) 2010  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -29,7 +29,7 @@ void _starpu_data_free_interfaces(starpu_data_handle handle)
 extern void _starpu_data_interface_init(void) STARPU_ATTRIBUTE_INTERNAL;
 extern void _starpu_data_interface_shutdown(void) STARPU_ATTRIBUTE_INTERNAL;
 
-extern void _starpu_data_register_local_pointer(starpu_data_handle handle,
+extern void _starpu_data_register_ram_pointer(starpu_data_handle handle,
 						void *ptr)
 	STARPU_ATTRIBUTE_INTERNAL;
 

+ 10 - 4
src/datawizard/interfaces/matrix_interface.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010  Université de Bordeaux 1
+ * Copyright (C) 2010-2011  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -65,7 +65,7 @@ static const struct starpu_data_copy_methods matrix_copy_data_methods_s = {
 };
 
 static void register_matrix_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface);
-static void *matrix_handle_to_pointer(starpu_data_handle data_handle);
+static void *matrix_handle_to_pointer(starpu_data_handle data_handle, uint32_t node);
 static ssize_t allocate_matrix_buffer_on_node(void *data_interface_, uint32_t dst_node);
 static void free_matrix_buffer_on_node(void *data_interface, uint32_t node);
 static size_t matrix_interface_get_size(starpu_data_handle handle);
@@ -80,6 +80,7 @@ struct starpu_data_interface_ops_t _starpu_interface_matrix_ops = {
 	.register_data_handle = register_matrix_handle,
 	.allocate_data_on_node = allocate_matrix_buffer_on_node,
 	.handle_to_pointer = matrix_handle_to_pointer,
+	.get_local_ptr = starpu_matrix_get_local_ptr,
 	.free_data_on_node = free_matrix_buffer_on_node,
 	.copy_methods = &matrix_copy_data_methods_s,
 	.get_size = matrix_interface_get_size,
@@ -140,9 +141,14 @@ static void register_matrix_handle(starpu_data_handle handle, uint32_t home_node
 	}
 }
 
-static void *matrix_handle_to_pointer(starpu_data_handle data_handle)
+static void *matrix_handle_to_pointer(starpu_data_handle handle, uint32_t node)
 {
-	return (void *)starpu_matrix_get_local_ptr(data_handle);
+	STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
+
+	starpu_matrix_interface_t *matrix_interface =
+		starpu_data_get_interface_on_node(handle, node);
+
+	return (void*) matrix_interface->ptr;
 }
 
 

+ 7 - 4
src/datawizard/interfaces/variable_interface.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010  Université de Bordeaux 1
+ * Copyright (C) 2010-2011  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -68,7 +68,7 @@ static const struct starpu_data_copy_methods variable_copy_data_methods_s = {
 
 static void register_variable_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface);
 static ssize_t allocate_variable_buffer_on_node(void *data_interface_, uint32_t dst_node);
-static void *variable_handle_to_pointer(starpu_data_handle data_handle);
+static void *variable_handle_to_pointer(starpu_data_handle data_handle, uint32_t node);
 static void free_variable_buffer_on_node(void *data_interface, uint32_t node);
 static size_t variable_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_variable_interface_crc32(starpu_data_handle handle);
@@ -82,6 +82,7 @@ static struct starpu_data_interface_ops_t interface_variable_ops = {
 	.register_data_handle = register_variable_handle,
 	.allocate_data_on_node = allocate_variable_buffer_on_node,
 	.handle_to_pointer = variable_handle_to_pointer,
+	.get_local_ptr = starpu_variable_get_local_ptr,
 	.free_data_on_node = free_variable_buffer_on_node,
 	.copy_methods = &variable_copy_data_methods_s,
 	.get_size = variable_interface_get_size,
@@ -95,9 +96,11 @@ static struct starpu_data_interface_ops_t interface_variable_ops = {
 	.display = display_variable_interface
 };
 
-static void *variable_handle_to_pointer(starpu_data_handle data_handle)
+static void *variable_handle_to_pointer(starpu_data_handle handle, uint32_t node)
 {
-	return (void *)starpu_variable_get_local_ptr(data_handle);
+	STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
+
+	return (void*) STARPU_VARIABLE_GET_PTR(starpu_data_get_interface_on_node(handle, node));
 }
 
 static void register_variable_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface)

+ 10 - 4
src/datawizard/interfaces/vector_interface.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009-2011  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -68,7 +68,7 @@ static const struct starpu_data_copy_methods vector_copy_data_methods_s = {
 
 static void register_vector_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface);
 static ssize_t allocate_vector_buffer_on_node(void *data_interface_, uint32_t dst_node);
-static void *vector_handle_to_pointer(starpu_data_handle data_handle);
+static void *vector_handle_to_pointer(starpu_data_handle data_handle, uint32_t node);
 static void free_vector_buffer_on_node(void *data_interface, uint32_t node);
 static size_t vector_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_vector_interface_crc32(starpu_data_handle handle);
@@ -82,6 +82,7 @@ static struct starpu_data_interface_ops_t interface_vector_ops = {
 	.register_data_handle = register_vector_handle,
 	.allocate_data_on_node = allocate_vector_buffer_on_node,
 	.handle_to_pointer = vector_handle_to_pointer,
+	.get_local_ptr = starpu_vector_get_local_ptr,
 	.free_data_on_node = free_vector_buffer_on_node,
 	.copy_methods = &vector_copy_data_methods_s,
 	.get_size = vector_interface_get_size,
@@ -95,9 +96,14 @@ static struct starpu_data_interface_ops_t interface_vector_ops = {
 	.display = display_vector_interface
 };
 
-static void *vector_handle_to_pointer(starpu_data_handle data_handle)
+static void *vector_handle_to_pointer(starpu_data_handle handle, uint32_t node)
 {
-	return (void *)starpu_vector_get_local_ptr(data_handle);
+	STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
+
+	starpu_vector_interface_t *vector_interface =
+		starpu_data_get_interface_on_node(handle, node);
+
+	return (void*) vector_interface->ptr;
 }
 
 static void register_vector_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface)

+ 4 - 4
src/datawizard/memalloc.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009-2011  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -746,12 +746,12 @@ int _starpu_allocate_memory_on_node(starpu_data_handle handle, struct starpu_dat
 	replicate->allocated = 1;
 	replicate->automatically_allocated = 1;
 
-	if (dst_node == _starpu_get_local_memory_node())
+	if (dst_node == 0)
 	{
-		void *ptr = starpu_handle_to_pointer(handle);
+		void *ptr = starpu_handle_to_pointer(handle, 0);
 		if (ptr != NULL)
 		{
-			_starpu_data_register_local_pointer(handle, ptr);
+			_starpu_data_register_ram_pointer(handle, ptr);
 		}
 	}
 

+ 2 - 2
tests/datawizard/data_lookup.c

@@ -61,7 +61,7 @@ static void test_lazy_allocation()
 	starpu_data_acquire(handle, STARPU_R);
 
 	/* Make sure we have a local pointer to it.  */
-	pointer = starpu_handle_to_pointer(handle);
+	pointer = starpu_handle_get_local_ptr(handle);
 	assert(pointer != NULL);
 	for(i = 0; i < count; i++)
 	{
@@ -111,7 +111,7 @@ static void test_filters()
                 starpu_data_handle child;
 
 		child = starpu_data_get_sub_data(handle, 1, i);
-		children_pointers[i] = starpu_handle_to_pointer(child);
+		children_pointers[i] = starpu_handle_get_local_ptr(child);
 		assert(children_pointers[i] != NULL);
 
 		/* Make sure we have a pointer -> handle mapping for CHILD.  */

+ 5 - 5
tests/datawizard/handle_to_pointer.c

@@ -55,17 +55,17 @@ int main(int argc, char *argv[])
 
 	starpu_variable_data_register(&handle, 0, (uintptr_t)pointer,
 				      sizeof(float));
-	assert(starpu_handle_to_pointer(handle) == pointer);
+	assert(starpu_handle_to_pointer(handle, 0) == pointer);
 	starpu_data_unregister(handle);
 
 	starpu_vector_data_register(&handle, 0, (uintptr_t)pointer,
 				    count, sizeof(float));
-	assert(starpu_handle_to_pointer(handle) == pointer);
+	assert(starpu_handle_to_pointer(handle, 0) == pointer);
 	starpu_data_unregister(handle);
 
 	starpu_matrix_data_register(&handle, 0, (uintptr_t)pointer, 0,
 				    count, 1, sizeof(float));
-	assert(starpu_handle_to_pointer(handle) == pointer);
+	assert(starpu_handle_to_pointer(handle, 0) == pointer);
 	starpu_data_unregister(handle);
 
 	starpu_free(pointer);
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
 	/* Lazy allocation.  */
 	starpu_vector_data_register(&handle, -1, 0 /* NULL */,
 				    count, sizeof(float));
-	assert(starpu_handle_to_pointer(handle) == NULL);
+	assert(starpu_handle_to_pointer(handle, 0) == NULL);
 
 	/* Pass the handle to a task.  */
 	starpu_insert_task(&cl,
@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
 	starpu_data_acquire(handle, STARPU_R);
 
 	/* Make sure we have a local pointer to it.  */
-	pointer = starpu_handle_to_pointer(handle);
+	pointer = starpu_handle_to_pointer(handle, 0);
 	assert(pointer != NULL);
 	for(i = 0; i < count; i++)
 	{