浏览代码

New functions starpu_malloc_set_flags and starpu_malloc_get_flags to
define flags to be used by the memory allocator.
- STARPU_MALLOC_PINNED specifies memory should be pinned
- STARPU_MALLOC_COUNT specifies memory allocations should be in the
limits defined by the environment variables STARPU_LIMIT_xxx. When
no memory is left, starpu_malloc tries to reclaim memory from StarPU
and returns -ENOMEM on failure.

For now, the flag is not taken into account. Keep tuned for next
commit.

Nathalie Furmento 12 年之前
父节点
当前提交
3ef25bc89f
共有 4 个文件被更改,包括 54 次插入5 次删除
  1. 7 0
      ChangeLog
  2. 30 5
      doc/chapters/basic-api.texi
  3. 6 0
      include/starpu_stdlib.h
  4. 11 0
      src/datawizard/malloc.c

+ 7 - 0
ChangeLog

@@ -99,6 +99,13 @@ New features:
     environment variables STARPU_LIMIT_xxx (see above). When no memory
     environment variables STARPU_LIMIT_xxx (see above). When no memory
     is left, starpu_malloc_count tries to reclaim memory from StarPU
     is left, starpu_malloc_count tries to reclaim memory from StarPU
     and returns -ENOMEM on failure.
     and returns -ENOMEM on failure.
+  * New functions starpu_malloc_set_flags and starpu_malloc_get_flags
+    to define flags to be used by the memory allocator.
+    - STARPU_MALLOC_PINNED specifies memory should be pinned
+    - STARPU_MALLOC_COUNT specifies memory allocations should be in
+      the limits defined by the environment variables STARPU_LIMIT_xxx
+      (see above). When no memory is left, starpu_malloc tries
+      to reclaim memory from StarPU and returns -ENOMEM on failure.
 
 
 Small features:
 Small features:
   * Add starpu_worker_get_by_type and starpu_worker_get_by_devid
   * Add starpu_worker_get_by_type and starpu_worker_get_by_devid

+ 30 - 5
doc/chapters/basic-api.texi

@@ -239,11 +239,29 @@ are disabled.
 @node Standard memory library
 @node Standard memory library
 @section Standard memory library
 @section Standard memory library
 
 
-@deftypefun int starpu_malloc (void **@var{A}, size_t @var{dim})
-This function allocates data of the given size in main memory. It will also try to pin it in
-CUDA or OpenCL, so that data transfers from this buffer can be asynchronous, and
-thus permit data transfer and computation overlapping. The allocated buffer must
-be freed thanks to the @code{starpu_free} function.
+@defmac STARPU_MALLOC_PINNED
+Value passed to the function @code{starpu_malloc_set_flags} to
+indicate further memory allocations should be pinned
+@end defmac
+
+@defmac STARPU_MALLOC_COUNT
+Value passed to the function @code{starpu_malloc_set_flags} to
+indicate further memory allocations should be in the limit defined by
+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.
+@end defmac
+
+@deftypefun int starpu_malloc_set_flags (int @var{flags})
+Set the current flags used by the memory allocator. @var{flag} must be
+ a combinaison of the values defined above.
+@end deftypefun
+
+@deftypefun int starpu_malloc_get_flags ()
+Return the current value of the flags used by the memory allocator.
 @end deftypefun
 @end deftypefun
 
 
 @deftypefun void starpu_malloc_set_align (size_t @var{align})
 @deftypefun void starpu_malloc_set_align (size_t @var{align})
@@ -252,6 +270,13 @@ allocations. @var{align} must be a power of two. This is for instance called
 automatically by the OpenCL driver to specify its own alignment constraints.
 automatically by the OpenCL driver to specify its own alignment constraints.
 @end deftypefun
 @end deftypefun
 
 
+@deftypefun int starpu_malloc (void **@var{A}, size_t @var{dim})
+This function allocates data of the given size in main memory. It will also try to pin it in
+CUDA or OpenCL, so that data transfers from this buffer can be asynchronous, and
+thus permit data transfer and computation overlapping. The allocated buffer must
+be freed thanks to the @code{starpu_free} function.
+@end deftypefun
+
 @deftypefun int starpu_free (void *@var{A})
 @deftypefun int starpu_free (void *@var{A})
 This function frees memory which has previously allocated with
 This function frees memory which has previously allocated with
 @code{starpu_malloc}.
 @code{starpu_malloc}.

+ 6 - 0
include/starpu_stdlib.h

@@ -25,6 +25,12 @@ extern "C"
 {
 {
 #endif
 #endif
 
 
+#define STARPU_MALLOC_PINNED	((1ULL)<<1)
+#define STARPU_MALLOC_COUNT	((1ULL)<<3)
+
+int starpu_malloc_set_flags(int flags);
+int starpu_malloc_get_flags();
+
 void starpu_malloc_set_align(size_t align);
 void starpu_malloc_set_align(size_t align);
 int starpu_malloc(void **A, size_t dim);
 int starpu_malloc(void **A, size_t dim);
 int starpu_free(void *A);
 int starpu_free(void *A);

+ 11 - 0
src/datawizard/malloc.c

@@ -24,6 +24,17 @@
 #include <datawizard/memory_manager.h>
 #include <datawizard/memory_manager.h>
 
 
 static size_t _malloc_align = sizeof(void*);
 static size_t _malloc_align = sizeof(void*);
+static int _malloc_flags = 0;
+
+int starpu_malloc_set_flags(int flags)
+{
+	_malloc_flags = flags;
+}
+
+int starpu_malloc_get_flags()
+{
+	return _malloc_flags;
+}
 
 
 void starpu_malloc_set_align(size_t align)
 void starpu_malloc_set_align(size_t align)
 {
 {