瀏覽代碼

memory: rename starpu_free_count in starpu_free_flags

Nathalie Furmento 12 年之前
父節點
當前提交
b4eb667ed3
共有 4 個文件被更改,包括 54 次插入49 次删除
  1. 1 3
      ChangeLog
  2. 6 6
      doc/chapters/basic-api.texi
  3. 2 2
      include/starpu_stdlib.h
  4. 45 38
      src/datawizard/malloc.c

+ 1 - 3
ChangeLog

@@ -103,9 +103,7 @@ New features:
       to reclaim memory from StarPU and returns -ENOMEM on failure.
   * starpu_malloc calls starpu_malloc_flags with a value of flag set
     to STARPU_MALLOC_PINNED
-  * Define new function starpu_free_count to
-    be used for freeing memory with a specified size. This is needed
-    to indicate the memory allocator the amount of memory.
+  * Define new function starpu_free_flags similarly to starpu_malloc_flags
 
 Small features:
   * Add starpu_worker_get_by_type and starpu_worker_get_by_devid

+ 6 - 6
doc/chapters/basic-api.texi

@@ -251,8 +251,8 @@ the environment variables @code{STARPU_LIMIT_CUDA_devid_MEM},
 @code{STARPU_LIMIT_CUDA_MEM}, @code{STARPU_LIMIT_OPENCL_devid_MEM},
 @code{STARPU_LIMIT_OPENCL_MEM} and @code{STARPU_LIMIT_CPU_MEM}
 (@pxref{Limit memory}). If no memory is available, it tries to reclaim
-memory from StarPU. Memory allocated this way needs to be freed thanks to the
-@code{starpu_free_count} function.
+memory from StarPU. Memory allocated this way needs to be freed by
+calling the @code{starpu_free_flags} function with the same flag.
 @end defmac
 
 @deftypefun int starpu_malloc_flags (void **@var{A}, size_t @var{dim}, int @var{flags})
@@ -278,10 +278,10 @@ This function frees memory which has previously been allocated with
 @code{starpu_malloc}.
 @end deftypefun
 
-@deftypefun int starpu_free_count (void *@var{A}, size_t @var{dim})
-This function frees memory by specifying its size. It should be used
-to free memory which was allocated by @code{starpu_malloc_flags} with the value
-@code{STARPU_MALLOC_COUNT}.
+@deftypefun int starpu_free_flags (void *@var{A}, size_t @var{dim}, int @var{flags})
+This function frees memory by specifying its size. The given
+@var{flags} should be consistent with the ones given to
+@code{starpu_malloc_flags} when allocating the memory.
 @end deftypefun
 
 @node Workers' Properties

+ 2 - 2
include/starpu_stdlib.h

@@ -29,12 +29,12 @@ extern "C"
 #define STARPU_MALLOC_COUNT	((1ULL)<<3)
 
 void starpu_malloc_set_align(size_t align);
+
 int starpu_malloc(void **A, size_t dim);
 int starpu_free(void *A);
 
 int starpu_malloc_flags(void **A, size_t dim, int flags);
-
-int starpu_free_count(void *A, size_t dim);
+int starpu_free_flags(void *A, size_t dim, int flags);
 
 #ifdef __cplusplus
 }

+ 45 - 38
src/datawizard/malloc.c

@@ -247,56 +247,66 @@ static struct starpu_codelet free_pinned_cl =
 };
 #endif
 
-int starpu_free(void *A)
+int starpu_free_flags(void *A, size_t dim, int flags)
 {
-	if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-		return -EDEADLK;
+	if (flags & STARPU_MALLOC_COUNT)
+	{
+		_starpu_memory_manager_deallocate_size(dim, 0);
+	}
 
+	if (flags & STARPU_MALLOC_PINNED)
+	{
 #ifndef STARPU_SIMGRID
+		if (_starpu_can_submit_cuda_task())
+		{
 #ifdef STARPU_USE_CUDA
-	if (_starpu_can_submit_cuda_task())
-	{
 #ifndef HAVE_CUDA_MEMCPY_PEER
-	if (!_starpu_is_initialized())
-	{
+			if (!_starpu_is_initialized())
+			{
 #endif
-		/* This is especially useful when starpu_free is called from
- 		 * the GCC-plugin. starpu_shutdown will probably have already
-		 * been called, so we will not be able to submit a task. */
-		cudaError_t err = cudaFreeHost(A);
-		if (STARPU_UNLIKELY(err))
-			STARPU_CUDA_REPORT_ERROR(err);
+				/* This is especially useful when starpu_free is called from
+				 * the GCC-plugin. starpu_shutdown will probably have already
+				 * been called, so we will not be able to submit a task. */
+				cudaError_t err = cudaFreeHost(A);
+				if (STARPU_UNLIKELY(err))
+					STARPU_CUDA_REPORT_ERROR(err);
 #ifndef HAVE_CUDA_MEMCPY_PEER
-	}
-	else
-	{
-		int push_res;
+			}
+			else
+			{
+				int push_res;
 
-                free_pinned_cl.where = STARPU_CUDA;
-		struct starpu_task *task = starpu_task_create();
-		task->callback_func = NULL;
-		task->cl = &free_pinned_cl;
-		task->cl_arg = A;
+				if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
+					return -EDEADLK;
 
-		task->synchronous = 1;
+				free_pinned_cl.where = STARPU_CUDA;
+				struct starpu_task *task = starpu_task_create();
+				task->callback_func = NULL;
+				task->cl = &free_pinned_cl;
+				task->cl_arg = A;
+				task->synchronous = 1;
 
-		_starpu_exclude_task_from_dag(task);
+				_starpu_exclude_task_from_dag(task);
 
-		push_res = _starpu_task_submit_internally(task);
-		STARPU_ASSERT(push_res != -ENODEV);
-	}
-#endif
+				push_res = _starpu_task_submit_internally(task);
+				STARPU_ASSERT(push_res != -ENODEV);
+			}
+#endif /* HAVE_CUDA_MEMCPY_PEER */
+#endif /* STARPU_USE_CUDA */
+		}
 //	else if (_starpu_can_submit_opencl_task())
 //	{
 //#ifdef STARPU_USE_OPENCL
 //		int push_res;
 //
+//		if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
+//			return -EDEADLK;
+//
 //                free_pinned_cl.where = STARPU_OPENCL;
 //		struct starpu_task *task = starpu_task_create();
-//			task->callback_func = NULL;
-//			task->cl = &free_pinned_cl;
-//			task->cl_arg = A;
-//
+//		task->callback_func = NULL;
+//		task->cl = &free_pinned_cl;
+//		task->cl_arg = A;
 //		task->synchronous = 1;
 //
 //		_starpu_exclude_task_from_dag(task);
@@ -306,8 +316,7 @@ int starpu_free(void *A)
 //#endif
 //	}
 	} else
-#endif
-#endif
+#endif /* STARPU_SIMGRID */
 	{
 		free(A);
 	}
@@ -315,11 +324,9 @@ int starpu_free(void *A)
 	return 0;
 }
 
-
-int starpu_free_count(void *A, size_t dim)
+int starpu_free(void *A)
 {
-	_starpu_memory_manager_deallocate_size(dim, 0);
-	return starpu_free(A);
+	return starpu_free_flags(A, 0, STARPU_MALLOC_PINNED);
 }
 
 #ifdef STARPU_SIMGRID