Ver código fonte

Add cl_arg_free field to enable automatic free(cl_arg) on task destroy.

Samuel Thibault 12 anos atrás
pai
commit
c8f8cfea95
5 arquivos alterados com 20 adições e 1 exclusões
  1. 4 0
      ChangeLog
  2. 8 0
      doc/chapters/api.texi
  3. 2 0
      include/starpu_task.h
  4. 5 0
      src/core/task.c
  5. 1 1
      src/util/starpu_insert_task.c

+ 4 - 0
ChangeLog

@@ -29,6 +29,10 @@ New features:
 	  allocate data correctly, and to submit the matching receive of
 	  the envelope.
 
+Small features:
+  * Add cl_arg_free field to enable automatic free(cl_arg) on task
+    destroy.
+
 StarPU 1.1.0 (svn revision xxxx)
 ==============================================
 

+ 8 - 0
doc/chapters/api.texi

@@ -2038,6 +2038,14 @@ this case, the argument given to the codelet is therefore not the
 This field is ignored for CPU, CUDA and OpenCL codelets, where the
 @code{cl_arg} pointer is given as such.
 
+@item @code{unsigned cl_arg_free} (optional)
+In case @code{cl_arg} was allocated by the application through @code{malloc},
+setting @code{cl_arg_free} to 1 makes StarPU automatically call
+@code{free(cl_arg)} when destroying the task. This saves the user from
+defining a callback just for that. This is mostly useful when targetting MIC or
+SCC, where the codelet does not execute in the same memory space as the main
+thread.
+
 @item @code{void (*callback_func)(void *)} (optional) (default: @code{NULL})
 This is a function pointer of prototype @code{void (*f)(void *)} which
 specifies a possible callback. If this pointer is non-null, the callback

+ 2 - 0
include/starpu_task.h

@@ -128,6 +128,8 @@ struct starpu_task
 	void *cl_arg;
 	/* in case the argument buffer has to be uploaded explicitely */
 	size_t cl_arg_size;
+	/* must StarPU release cl_arg ? - 0 by default */
+	unsigned cl_arg_free;
 
 	/* when the task is done, callback_func(callback_arg) is called */
 	void (*callback_func)(void *);

+ 5 - 0
src/core/task.c

@@ -155,6 +155,11 @@ void _starpu_task_destroy(struct starpu_task *task)
 		starpu_task_clean(task);
 		/* TODO handle the case of task with detach = 1 and destroy = 1 */
 		/* TODO handle the case of non terminated tasks -> return -EINVAL */
+
+		/* Does user want StarPU release cl_arg ? */
+		if (task->cl_arg_free)
+			free(task->cl_arg);
+
 		free(task);
 	}
 }

+ 1 - 1
src/util/starpu_insert_task.c

@@ -60,7 +60,6 @@ void starpu_codelet_unpack_args(void *_cl_arg, ...)
 	}
 
 	va_end(varg_list);
-	free(cl_arg);
 }
 
 int starpu_insert_task(struct starpu_codelet *cl, ...)
@@ -80,6 +79,7 @@ int starpu_insert_task(struct starpu_codelet *cl, ...)
 	}
 
 	struct starpu_task *task = starpu_task_create();
+	task->cl_arg_free = 1;
 
 	if (cl && cl->nbuffers > STARPU_NMAXBUFS)
 	{