Преглед изворни кода

src: add a memory manager module (does not do much for now)

Nathalie Furmento пре 12 година
родитељ
комит
dd02d53824

+ 2 - 0
src/Makefile.am

@@ -85,6 +85,7 @@ noinst_HEADERS = 						\
 	datawizard/write_back.h					\
 	datawizard/datastats.h					\
 	datawizard/memstats.h					\
+	datawizard/memory_manager.h				\
 	datawizard/memalloc.h					\
 	datawizard/copy_driver.h				\
 	datawizard/coherency.h					\
@@ -173,6 +174,7 @@ libstarpu_@STARPU_EFFECTIVE_VERSION@_la_SOURCES = 						\
 	datawizard/filters.c					\
 	datawizard/sort_data_handles.c				\
 	datawizard/malloc.c					\
+	datawizard/memory_manager.c				\
 	datawizard/memalloc.c					\
 	datawizard/memstats.c					\
 	datawizard/footprint.c					\

+ 5 - 0
src/datawizard/memalloc.c

@@ -15,6 +15,7 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
 
+#include <datawizard/memory_manager.h>
 #include <datawizard/memalloc.h>
 #include <datawizard/footprint.h>
 #include <starpu_cuda.h>
@@ -772,8 +773,11 @@ starpu_allocate_buffer_on_node(uint32_t dst_node, size_t size)
 	switch(starpu_node_get_kind(dst_node))
 	{
 		case STARPU_CPU_RAM:
+		{
 			addr = (uintptr_t)malloc(size);
+			_starpu_memory_manager_add_size(size);
 			break;
+		}
 #ifdef STARPU_USE_CUDA
 		case STARPU_CUDA_RAM:
 #ifdef STARPU_SIMGRID
@@ -838,6 +842,7 @@ starpu_free_buffer_on_node(uint32_t dst_node, uintptr_t addr, size_t size)
 #endif
 		case STARPU_CPU_RAM:
 			free((void*)addr);
+			_starpu_memory_manager_add_size(-size);
 			break;
 #ifdef STARPU_USE_CUDA
 		case STARPU_CUDA_RAM:

+ 38 - 0
src/datawizard/memory_manager.c

@@ -0,0 +1,38 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2012  Centre National de la Recherche Scientifique
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu.h>
+#include <common/config.h>
+#include <datawizard/memory_manager.h>
+
+static size_t global_size;
+static size_t used_size;
+
+int _starpu_memory_manager_init()
+{
+#ifdef STARPU_DEVEL
+#  warning use hwloc to get global size
+#endif
+     global_size = 0;
+     used_size = 0;
+     return 0;
+}
+
+int _starpu_memory_manager_add_size(size_t size)
+{
+     used_size += size;
+     return 0;
+}

+ 26 - 0
src/datawizard/memory_manager.h

@@ -0,0 +1,26 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2012  Centre National de la Recherche Scientifique
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#ifndef __MEMORY_MANAGER_H__
+#define __MEMORY_MANAGER_H__
+
+#include <starpu.h>
+#include <common/config.h>
+
+int _starpu_memory_manager_init();
+int _starpu_memory_manager_add_size(size_t size);
+
+#endif /* __MEMORY_MANAGER_H__ */

+ 3 - 1
src/datawizard/memory_nodes.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2012  Université de Bordeaux 1
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -19,6 +19,7 @@
 #include <common/config.h>
 #include <core/sched_policy.h>
 #include <datawizard/datastats.h>
+#include <datawizard/memory_manager.h>
 #include <common/fxt.h>
 #include "copy_driver.h"
 #include "memalloc.h"
@@ -43,6 +44,7 @@ void _starpu_init_memory_nodes(void)
 
 	_starpu_init_mem_chunk_lists();
 	_starpu_init_data_request_lists();
+	_starpu_memory_manager_init();
 
 	_STARPU_PTHREAD_RWLOCK_INIT(&descr.conditions_rwlock, NULL);
 	descr.total_condition_count = 0;