Procházet zdrojové kódy

port r11183 from 1.1: document callback_arg_free and prologue_callback_arg_free

Samuel Thibault před 11 roky
rodič
revize
489766f3ff

+ 3 - 2
ChangeLog

@@ -52,8 +52,6 @@ New features:
     scheduled.
 
 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
     starpu_data_acquire_on_node_cb_sequential_consistency() which allows
     to enable or disable sequential consistency
@@ -64,6 +62,9 @@ Small features:
     the tool starpu_perfmodel_display
   * New batch files to execute StarPU applications under Microsoft
     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:
   * 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
 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
 Optional field, the default value is <c>NULL</c>. This is a function
 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
 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
 Optional field, the default value is 0. If set, this flag indicates
 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_arg;
+	/* must StarPU release callback_arg ? - 0 by default */
+	unsigned callback_arg_free;
 
 	void (*prologue_callback_func)(void *);
 	void *prologue_callback_arg;
+	/* must StarPU release prologue_callback_arg ? - 0 by default */
+	unsigned prologue_callback_arg_free;
 
 	unsigned use_tag;
 	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)
 			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);
 	}
 }

+ 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 */
 	if (cl_arg_wrapper->callback_func)
 		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)
@@ -379,9 +377,11 @@ int _starpu_insert_task_create_and_submit(void *arg_buffer, size_t arg_buffer_si
 	 * application's callback, if any. */
 	(*task)->callback_func = starpu_task_insert_callback_wrapper;
 	(*task)->callback_arg = cl_arg_wrapper;
+	(*task)->callback_arg_free = 1;
 
 	(*task)->prologue_callback_func = starpu_task_insert_callback_wrapper;
 	(*task)->prologue_callback_arg = prologue_cl_arg_wrapper;
+	(*task)->prologue_callback_arg_free = 1;
 
 	int ret = starpu_task_submit(*task);