Browse Source

port r11183 from 1.1: document callback_arg_free and prologue_callback_arg_free

Samuel Thibault 11 years ago
parent
commit
489766f3ff

+ 3 - 2
ChangeLog

@@ -52,8 +52,6 @@ New features:
     scheduled.
     scheduled.
 
 
 Small features:
 Small features:
-  * Add cl_arg_free field to enable automatic free(cl_arg) on task
-    destroy.
   * New functions starpu_data_acquire_cb_sequential_consistency() and
   * New functions starpu_data_acquire_cb_sequential_consistency() and
     starpu_data_acquire_on_node_cb_sequential_consistency() which allows
     starpu_data_acquire_on_node_cb_sequential_consistency() which allows
     to enable or disable sequential consistency
     to enable or disable sequential consistency
@@ -64,6 +62,9 @@ Small features:
     the tool starpu_perfmodel_display
     the tool starpu_perfmodel_display
   * New batch files to execute StarPU applications under Microsoft
   * New batch files to execute StarPU applications under Microsoft
     Visual Studio (They are installed in path_to_starpu/bin/mvsc)/
     Visual Studio (They are installed in path_to_starpu/bin/mvsc)/
+  * Add cl_arg_free, callback_arg_free, prologue_callback_arg_free fields to
+    enable automatic free(cl_arg); free(callback_arg);
+    free(prologue_callback_arg) on task destroy.
 
 
 Changes:
 Changes:
   * Fix of the livelock issue discovered while executing applications
   * Fix of the livelock issue discovered while executing applications

+ 12 - 0
doc/doxygen/chapters/api/codelet_and_tasks.doxy

@@ -406,6 +406,12 @@ Optional field, the default value is <c>NULL</c>. This is the pointer
 passed to the callback function. This field is ignored if the field
 passed to the callback function. This field is ignored if the field
 starpu_task::callback_func is set to <c>NULL</c>.
 starpu_task::callback_func is set to <c>NULL</c>.
 
 
+\var starpu_task::callback_arg_free
+Optional field. In case starpu_task::callback_arg was allocated by the
+application through <c>malloc()</c>, setting starpu_task::callback_arg_free
+to 1 makes StarPU automatically call <c>free(callback_arg)</c> when
+destroying the task.
+
 \var starpu_task::prologue_func
 \var starpu_task::prologue_func
 Optional field, the default value is <c>NULL</c>. This is a function
 Optional field, the default value is <c>NULL</c>. This is a function
 pointer of prototype <c>void (*f)(void *)</c> which specifies a
 pointer of prototype <c>void (*f)(void *)</c> which specifies a
@@ -421,6 +427,12 @@ Optional field, the default value is <c>NULL</c>. This is the pointer
 passed to the prologue function. This field is ignored if the field
 passed to the prologue function. This field is ignored if the field
 starpu_task::prologue_func is set to <c>NULL</c>.
 starpu_task::prologue_func is set to <c>NULL</c>.
 
 
+\var starpu_task::prologue_callback__arg_free
+Optional field. In case starpu_task::prologue_callback__arg was allocated by the
+application through <c>malloc()</c>, setting starpu_task::prologue_callback__arg_free
+to 1 makes StarPU automatically call <c>free(prologue_callback__arg)</c> when
+destroying the task.
+
 \var starpu_task::use_tag
 \var starpu_task::use_tag
 Optional field, the default value is 0. If set, this flag indicates
 Optional field, the default value is 0. If set, this flag indicates
 that the task should be associated with the tag contained in the
 that the task should be associated with the tag contained in the

+ 4 - 0
include/starpu_task.h

@@ -125,9 +125,13 @@ struct starpu_task
 
 
 	void (*callback_func)(void *);
 	void (*callback_func)(void *);
 	void *callback_arg;
 	void *callback_arg;
+	/* must StarPU release callback_arg ? - 0 by default */
+	unsigned callback_arg_free;
 
 
 	void (*prologue_callback_func)(void *);
 	void (*prologue_callback_func)(void *);
 	void *prologue_callback_arg;
 	void *prologue_callback_arg;
+	/* must StarPU release prologue_callback_arg ? - 0 by default */
+	unsigned prologue_callback_arg_free;
 
 
 	unsigned use_tag;
 	unsigned use_tag;
 	starpu_tag_t tag_id;
 	starpu_tag_t tag_id;

+ 8 - 0
src/core/task.c

@@ -160,6 +160,14 @@ void _starpu_task_destroy(struct starpu_task *task)
 		if (task->cl_arg_free)
 		if (task->cl_arg_free)
 			free(task->cl_arg);
 			free(task->cl_arg);
 
 
+		/* Does user want StarPU release callback_arg ? */
+		if (task->callback_arg_free)
+			free(task->callback_arg);
+
+		/* Does user want StarPU release prologue_callback_arg ? */
+		if (task->prologue_callback_arg_free)
+			free(task->prologue_callback_arg);
+
 		free(task);
 		free(task);
 	}
 	}
 }
 }

+ 2 - 2
src/util/starpu_insert_task_utils.c

@@ -39,8 +39,6 @@ void starpu_task_insert_callback_wrapper(void *_cl_arg_wrapper)
 	/* Execute the callback specified by the application */
 	/* Execute the callback specified by the application */
 	if (cl_arg_wrapper->callback_func)
 	if (cl_arg_wrapper->callback_func)
 		cl_arg_wrapper->callback_func(cl_arg_wrapper->callback_arg);
 		cl_arg_wrapper->callback_func(cl_arg_wrapper->callback_arg);
-
-	free(cl_arg_wrapper);
 }
 }
 
 
 size_t _starpu_insert_task_get_arg_size(va_list varg_list)
 size_t _starpu_insert_task_get_arg_size(va_list varg_list)
@@ -379,9 +377,11 @@ int _starpu_insert_task_create_and_submit(void *arg_buffer, size_t arg_buffer_si
 	 * application's callback, if any. */
 	 * application's callback, if any. */
 	(*task)->callback_func = starpu_task_insert_callback_wrapper;
 	(*task)->callback_func = starpu_task_insert_callback_wrapper;
 	(*task)->callback_arg = cl_arg_wrapper;
 	(*task)->callback_arg = cl_arg_wrapper;
+	(*task)->callback_arg_free = 1;
 
 
 	(*task)->prologue_callback_func = starpu_task_insert_callback_wrapper;
 	(*task)->prologue_callback_func = starpu_task_insert_callback_wrapper;
 	(*task)->prologue_callback_arg = prologue_cl_arg_wrapper;
 	(*task)->prologue_callback_arg = prologue_cl_arg_wrapper;
+	(*task)->prologue_callback_arg_free = 1;
 
 
 	int ret = starpu_task_submit(*task);
 	int ret = starpu_task_submit(*task);