瀏覽代碼

Add unregister_data_handle handle ops

Samuel Thibault 4 年之前
父節點
當前提交
fa47310961

+ 1 - 0
ChangeLog

@@ -87,6 +87,7 @@ Small features:
     variables.
   * Add STARPU_SCHED_SIMPLE_PRE_DECISION.
   * Add starpu_bcsr_filter_canonical_block_get_nchildren.
+  * Add unregister_data_handle handle ops.
 
 StarPU 1.3.7
 ====================================================================

+ 3 - 0
doc/doxygen/chapters/310_data_management.doxy

@@ -959,6 +959,9 @@ static void complex_register_data_handle(starpu_data_handle_t handle, unsigned h
 
 If the application provided a home node, the corresponding pointers will be
 recorded for that node. Others have no buffer allocated yet.
+Possibly the interface needs some dynamic allocation (e.g. to store an array of
+dimensions that can have variable size). The corresponding deallocation will then be
+done in starpu_data_interface_ops::unregister_data_handle.
 
 Different operations need to be defined for a data interface through
 the type starpu_data_interface_ops. We only define here the basic

+ 2 - 0
examples/cpp/add_vectors_interface.cpp

@@ -260,6 +260,7 @@ static starpu_ssize_t vector_cpp_describe(void *data_interface, char *buf, size_
 static struct starpu_data_interface_ops interface_vector_cpp_ops =
 {
 	.register_data_handle = register_vector_cpp_handle,
+	.unregister_data_handle = NULL,
 	.allocate_data_on_node = allocate_vector_cpp_buffer_on_node,
 	.free_data_on_node = free_vector_cpp_buffer_on_node,
 	.init = NULL,
@@ -290,6 +291,7 @@ static struct starpu_data_interface_ops interface_vector_cpp_ops =
 static struct starpu_data_interface_ops interface_vector_cpp_ops =
 {
 	register_vector_cpp_handle,
+	NULL,
 	allocate_vector_cpp_buffer_on_node,
 	free_vector_cpp_buffer_on_node,
 	NULL,

+ 11 - 0
include/starpu_data_interfaces.h

@@ -331,6 +331,17 @@ struct starpu_data_interface_ops
 	void		 (*register_data_handle)	(starpu_data_handle_t handle, unsigned home_node, void *data_interface);
 
 	/**
+	   Unregister a data handle.
+
+	   This iterates over all memory nodes to free any pointer in the data
+	   interface on each of them.
+
+	   At this point, free_data_on_node has been already called on each of them.
+	   This just clears anything that would still be left.
+	*/
+	void		 (*unregister_data_handle)	(starpu_data_handle_t handle);
+
+	/**
 	   Allocate data for the interface on a given node. This should use
 	   starpu_malloc_on_node() to perform the allocation(s), and fill the pointers
 	   in the data interface. It should return the size of the allocated memory, or

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

@@ -711,6 +711,9 @@ void _starpu_data_free_interfaces(starpu_data_handle_t handle)
 	unsigned node;
 	unsigned nworkers = starpu_worker_get_count();
 
+	if (handle->ops->unregister_data_handle)
+		handle->ops->unregister_data_handle(handle);
+
 	for (node = 0; node < STARPU_MAXNODES; node++)
 		free(handle->per_node[node].data_interface);