瀏覽代碼

Optional data interface init function
- used by the vector and matrix interfaces : initialize the allocsize
field to -1 to make sure the value is correctly set

Nathalie Furmento 6 年之前
父節點
當前提交
3da2b69928

+ 2 - 0
ChangeLog

@@ -139,6 +139,8 @@ Small features:
     starpu_conf::catch_signals or through the environment variable
     STARPU_CATCH_SIGNALS
   * Support for OpenMP Taskloop directive
+  * Optional data interface init function (used by the vector and
+    matrix interfaces)
 
 Changes:
   * Vastly improve simgrid simulation time.

+ 2 - 0
examples/cpp/add_vectors_interface.cpp

@@ -277,6 +277,7 @@ static struct starpu_data_interface_ops interface_vector_cpp_ops =
 	.register_data_handle = register_vector_cpp_handle,
 	.allocate_data_on_node = allocate_vector_cpp_buffer_on_node,
 	.free_data_on_node = free_vector_cpp_buffer_on_node,
+	.init = NULL,
 	.copy_methods = &vector_cpp_copy_data_methods_s,
 	.handle_to_pointer = NULL,
 	.to_pointer = vector_cpp_to_pointer,
@@ -304,6 +305,7 @@ static struct starpu_data_interface_ops interface_vector_cpp_ops =
 	register_vector_cpp_handle,
 	allocate_vector_cpp_buffer_on_node,
 	free_vector_cpp_buffer_on_node,
+	NULL,
 	&vector_cpp_copy_data_methods_s,
 	vector_cpp_to_pointer,
 	vector_cpp_pointer_is_inside,

+ 7 - 0
include/starpu_data_interfaces.h

@@ -413,6 +413,13 @@ struct starpu_data_interface_ops
 	void 		 (*free_data_on_node)		(void *data_interface, unsigned node);
 
 	/**
+	   Initialize the interface.
+	   This method is optional. It is called when initializing the
+	   handler on all the memory nodes.
+	*/
+	void             (*init)                        (void *data_interface);
+
+	/**
 	   Struct with pointer to functions for performing ram/cuda/opencl synchronous and asynchronous transfers.
 	*/
 	const struct starpu_data_copy_methods *copy_methods;

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

@@ -468,6 +468,7 @@ int _starpu_data_handle_init(starpu_data_handle_t handle, struct starpu_data_int
 		replicate->handle = handle;
 
 		_STARPU_CALLOC(replicate->data_interface, 1, interfacesize);
+		if (handle->ops->init) handle->ops->init(replicate->data_interface);
 	}
 
 	return 0;

+ 11 - 1
src/datawizard/interfaces/matrix_interface.c

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2008-2019                                Université de Bordeaux
  * Copyright (C) 2011,2012,2017                           Inria
- * Copyright (C) 2010-2017                                CNRS
+ * Copyright (C) 2010-2017,2019                           CNRS
  *
  * 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
@@ -85,6 +85,7 @@ static const struct starpu_data_copy_methods matrix_copy_data_methods_s =
 	.any_to_any = copy_any_to_any,
 };
 
+static void matrix_init(void *data_interface);
 static void register_matrix_handle(starpu_data_handle_t handle, unsigned home_node, void *data_interface);
 static void *matrix_to_pointer(void *data_interface, unsigned node);
 static int matrix_pointer_is_inside(void *data_interface, unsigned node, void *ptr);
@@ -103,6 +104,7 @@ static starpu_ssize_t describe(void *data_interface, char *buf, size_t size);
 
 struct starpu_data_interface_ops starpu_interface_matrix_ops =
 {
+	.init = matrix_init,
 	.register_data_handle = register_matrix_handle,
 	.allocate_data_on_node = allocate_matrix_buffer_on_node,
 	.to_pointer = matrix_to_pointer,
@@ -124,6 +126,12 @@ struct starpu_data_interface_ops starpu_interface_matrix_ops =
 	.name = "STARPU_MATRIX_INTERFACE"
 };
 
+static void matrix_init(void *data_interface)
+{
+	struct starpu_matrix_interface *matrix_interface = data_interface;
+	matrix_interface->allocsize = -1;
+}
+
 static void register_matrix_handle(starpu_data_handle_t handle, unsigned home_node, void *data_interface)
 {
 	struct starpu_matrix_interface *matrix_interface = (struct starpu_matrix_interface *) data_interface;
@@ -335,6 +343,8 @@ static size_t matrix_interface_get_alloc_size(starpu_data_handle_t handle)
 	STARPU_ASSERT_MSG(matrix_interface->id == STARPU_MATRIX_INTERFACE_ID, "Error. The given data is not a matrix.");
 #endif
 
+	STARPU_ASSERT_MSG(matrix_interface->allocsize != (size_t)-1, "The matrix allocation size needs to be defined");
+
 	return matrix_interface->allocsize;
 }
 

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

@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2008-2019                                Université de Bordeaux
  * Copyright (C) 2011,2012,2014,2017                      Inria
- * Copyright (C) 2010-2015,2017                           CNRS
+ * Copyright (C) 2010-2015,2017,2019                      CNRS
  *
  * 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
@@ -37,6 +37,7 @@ static const struct starpu_data_copy_methods vector_copy_data_methods_s =
 	.any_to_any = copy_any_to_any,
 };
 
+static void vector_init(void *data_interface);
 static void register_vector_handle(starpu_data_handle_t handle, unsigned home_node, void *data_interface);
 static starpu_ssize_t allocate_vector_buffer_on_node(void *data_interface_, unsigned dst_node);
 static void *vector_to_pointer(void *data_interface, unsigned node);
@@ -55,6 +56,7 @@ static starpu_ssize_t describe(void *data_interface, char *buf, size_t size);
 
 struct starpu_data_interface_ops starpu_interface_vector_ops =
 {
+	.init = vector_init,
 	.register_data_handle = register_vector_handle,
 	.allocate_data_on_node = allocate_vector_buffer_on_node,
 	.to_pointer = vector_to_pointer,
@@ -76,6 +78,12 @@ struct starpu_data_interface_ops starpu_interface_vector_ops =
 	.name = "STARPU_VECTOR_INTERFACE"
 };
 
+static void vector_init(void *data_interface)
+{
+	struct starpu_vector_interface *vector_interface = data_interface;
+	vector_interface->allocsize = -1;
+}
+
 static void *vector_to_pointer(void *data_interface, unsigned node)
 {
 	(void) node;
@@ -265,6 +273,7 @@ static size_t vector_interface_get_alloc_size(starpu_data_handle_t handle)
 #endif
 
 	size = vector_interface->allocsize;
+	STARPU_ASSERT_MSG(size != (size_t)-1, "The vector allocation size needs to be defined");
 
 	return size;
 }