Browse Source

Add `starpu_handle_to_pointer'.

Ludovic Courtès 14 years ago
parent
commit
f652759ae9

+ 1 - 0
.gitignore

@@ -22,3 +22,4 @@ Makefile.in
 *.la
 .dirstamp
 /gcc-plugin/src/starpu-gcc-config.h
+/tests/datawizard/handle_to_pointer

+ 6 - 0
include/starpu_data_interfaces.h

@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2010  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
  *
  * 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
@@ -87,6 +88,7 @@ struct starpu_data_interface_ops_t {
 	starpu_ssize_t (*allocate_data_on_node)(void *data_interface, uint32_t node);
 	void (*free_data_on_node)(void *data_interface, uint32_t node);
 	const struct starpu_data_copy_methods *copy_methods;
+	void * (*handle_to_pointer)(starpu_data_handle handle);
 	size_t (*get_size)(starpu_data_handle handle);
 	uint32_t (*footprint)(starpu_data_handle handle);
 	int (*compare)(void *data_interface_a, void *data_interface_b);
@@ -103,6 +105,10 @@ void starpu_data_register(starpu_data_handle *handleptr, uint32_t home_node,
 				void *data_interface,
 				struct starpu_data_interface_ops_t *ops);
 
+/* Return the local pointer associated with HANDLE or NULL if HANDLE's
+ * interface does not support this operation.  */
+void *starpu_handle_to_pointer(starpu_data_handle handle);
+
 extern struct starpu_data_interface_ops_t _starpu_interface_matrix_ops;
 
 /* "node" means memory node: 0 for main RAM, then 1, 2, etc. for various GPUs,

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

@@ -66,6 +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 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);
@@ -79,6 +80,7 @@ static int convert_block_to_gordon(void *data_interface, uint64_t *ptr, gordon_s
 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,
 	.free_data_on_node = free_block_buffer_on_node,
 	.copy_methods = &block_copy_data_methods_s,
 	.get_size = block_interface_get_size,
@@ -102,6 +104,11 @@ 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)
+{
+	return (void *)starpu_block_get_local_ptr(data_handle);
+}
+
 static void register_block_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface)
 {
 	starpu_block_interface_t *block_interface = data_interface;

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

@@ -191,6 +191,16 @@ 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)
+{
+	if (handle->ops->handle_to_pointer)
+	{
+		return handle->ops->handle_to_pointer(handle);
+	}
+
+	return NULL;
+}
+
 int starpu_data_get_rank(starpu_data_handle handle)
 {
 	return handle->rank;

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

@@ -65,6 +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 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);
@@ -78,6 +79,7 @@ static int convert_matrix_to_gordon(void *data_interface, uint64_t *ptr, gordon_
 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,
 	.free_data_on_node = free_matrix_buffer_on_node,
 	.copy_methods = &matrix_copy_data_methods_s,
 	.get_size = matrix_interface_get_size,
@@ -138,6 +140,12 @@ static void register_matrix_handle(starpu_data_handle handle, uint32_t home_node
 	}
 }
 
+static void *matrix_handle_to_pointer(starpu_data_handle data_handle)
+{
+	return (void *)starpu_matrix_get_local_ptr(data_handle);
+}
+
+
 /* declare a new data with the matrix interface */
 void starpu_matrix_data_register(starpu_data_handle *handleptr, uint32_t home_node,
 			uintptr_t ptr, uint32_t ld, uint32_t nx,

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

@@ -68,6 +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 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);
@@ -80,6 +81,7 @@ static int convert_variable_to_gordon(void *data_interface, uint64_t *ptr, gordo
 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,
 	.free_data_on_node = free_variable_buffer_on_node,
 	.copy_methods = &variable_copy_data_methods_s,
 	.get_size = variable_interface_get_size,
@@ -93,6 +95,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)
+{
+	return (void *)starpu_variable_get_local_ptr(data_handle);
+}
+
 static void register_variable_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface)
 {
 	unsigned node;

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

@@ -68,6 +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 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);
@@ -80,6 +81,7 @@ static int convert_vector_to_gordon(void *data_interface, uint64_t *ptr, gordon_
 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,
 	.free_data_on_node = free_vector_buffer_on_node,
 	.copy_methods = &vector_copy_data_methods_s,
 	.get_size = vector_interface_get_size,
@@ -93,6 +95,11 @@ 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)
+{
+	return (void *)starpu_vector_get_local_ptr(data_handle);
+}
+
 static void register_vector_handle(starpu_data_handle handle, uint32_t home_node, void *data_interface)
 {
 	starpu_vector_interface_t *vector_interface = data_interface;

+ 2 - 1
tests/Makefile.am

@@ -2,7 +2,7 @@
 #
 # Copyright (C) 2009, 2010, 2011  Université de Bordeaux 1
 # Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
-# Copyright (C) 2010  Institut National de Recherche en Informatique et Automatique
+# Copyright (C) 2010, 2011  Institut National de Recherche en Informatique et Automatique
 #
 # 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
@@ -135,6 +135,7 @@ check_PROGRAMS += 				\
 	datawizard/critical_section_with_void_interface\
 	datawizard/increment_redux		\
 	datawizard/increment_redux_v2		\
+	datawizard/handle_to_pointer		\
 	errorcheck/starpu_init_noworker		\
 	errorcheck/invalid_blocking_calls	\
 	errorcheck/invalid_tasks		\

+ 54 - 0
tests/datawizard/handle_to_pointer.c

@@ -0,0 +1,54 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2011  Institut National de Recherche en Informatique et Automatique
+ *
+ * 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
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#undef NDEBUG
+#include <assert.h>
+
+#include <starpu.h>
+#include <stdlib.h>
+
+#define COUNT 123
+
+int main(int argc, char *argv[])
+{
+	int err;
+	void *pointer;
+	starpu_data_handle handle;
+
+	starpu_init(NULL);
+
+	err = starpu_malloc(&pointer, COUNT * sizeof(float));
+	assert((err == 0) && (pointer != NULL));
+
+	starpu_variable_data_register(&handle, 0, (uintptr_t)pointer,
+				      sizeof(float));
+	assert(starpu_handle_to_pointer(handle) == pointer);
+	starpu_data_unregister(handle);
+
+	starpu_vector_data_register(&handle, 0, (uintptr_t)pointer,
+				    COUNT, sizeof(float));
+	assert(starpu_handle_to_pointer(handle) == 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);
+	starpu_data_unregister(handle);
+
+	starpu_shutdown();
+
+	return EXIT_SUCCESS;
+}