Browse Source

create a seperate file for memory node management

Cédric Augonnet 16 years ago
parent
commit
75e19d081f

+ 2 - 0
src/Makefile.am

@@ -55,6 +55,7 @@ noinst_HEADERS = 						\
 	datawizard/data_parameters.h				\
 	datawizard/copy-driver.h				\
 	datawizard/coherency.h					\
+	datawizard/memory_nodes.h				\
 	datawizard/interfaces/blas_interface.h			\
 	datawizard/interfaces/csr_filters.h			\
 	datawizard/interfaces/csc_interface.h			\
@@ -104,6 +105,7 @@ libstarpu_la_SOURCES = 						\
 	core/policies/deque-modeling-policy.c			\
 	core/policies/random-policy.c				\
 	core/policies/deque-modeling-policy-data-aware.c	\
+	datawizard/memory_nodes.c				\
 	datawizard/write_back.c					\
 	datawizard/coherency.c					\
 	datawizard/data_request.c				\

+ 3 - 111
src/datawizard/copy-driver.c

@@ -15,74 +15,15 @@
  */
 
 #include <pthread.h>
+#include <common/config.h>
 #include <core/policies/sched_policy.h>
 #include <datawizard/datastats.h>
 #include <common/fxt.h>
 #include "copy-driver.h"
 #include "memalloc.h"
 
-mem_node_descr descr;
-static pthread_key_t memory_node_key;
-
-unsigned register_memory_node(node_kind kind)
-{
-	unsigned nnodes;
-	/* ATOMIC_ADD returns the new value ... */
-	nnodes = STARPU_ATOMIC_ADD(&descr.nnodes, 1);
-
-	descr.nodes[nnodes-1] = kind;
-	TRACE_NEW_MEM_NODE(nnodes-1);
-
-	/* for now, there is no queue related to that newly created node */
-	descr.queues_count[nnodes-1] = 0;
-
-	return (nnodes-1);
-}
-
-
-/* TODO move in a more appropriate file  !! */
-/* attach a queue to a memory node (if it's not already attached) */
-void memory_node_attach_queue(struct jobq_s *q, unsigned nodeid)
-{
-	unsigned queue;
-	unsigned nqueues_total, nqueues;
-	
-	take_mutex(&descr.attached_queues_mutex);
-
-	/* we only insert the queue if it's not already in the list */
-	nqueues = descr.queues_count[nodeid];
-	for (queue = 0; queue < nqueues; queue++)
-	{
-		if (descr.attached_queues_per_node[nodeid][queue] == q)
-		{
-			/* the queue is already in the list */
-			release_mutex(&descr.attached_queues_mutex);
-			return;
-		}
-	}
-
-	/* it was not found locally */
-	descr.attached_queues_per_node[nodeid][nqueues] = q;
-	descr.queues_count[nodeid]++;
-
-	/* do we have to add it in the global list as well ? */
-	nqueues_total = descr.total_queues_count; 
-	for (queue = 0; queue < nqueues_total; queue++)
-	{
-		if (descr.attached_queues_all[queue] == q)
-		{
-			/* the queue is already in the global list */
-			release_mutex(&descr.attached_queues_mutex);
-			return;
-		}
-	} 
-
-	/* it was not in the global queue either */
-	descr.attached_queues_all[nqueues_total] = q;
-	descr.total_queues_count++;
-
-	release_mutex(&descr.attached_queues_mutex);
-}
+/* TODO write an accessor */
+extern mem_node_descr descr;
 
 void wake_all_blocked_workers_on_node(unsigned nodeid)
 {
@@ -125,55 +66,6 @@ void wake_all_blocked_workers(void)
 	}
 }
 
-void init_memory_nodes(void)
-{
-	/* there is no node yet, subsequent nodes will be 
-	 * added using register_memory_node */
-	descr.nnodes = 0;
-
-	pthread_key_create(&memory_node_key, NULL);
-
-	unsigned i;
-	for (i = 0; i < MAXNODES; i++) 
-	{
-		descr.nodes[i] = UNUSED; 
-	}
-
-	init_mem_chunk_lists();
-	init_data_request_lists();
-}
-
-void deinit_memory_nodes(void)
-{
-	deinit_data_request_lists();
-	deinit_mem_chunk_lists();
-
-	pthread_key_delete(memory_node_key);
-}
-
-void set_local_memory_node_key(unsigned *node)
-{
-	pthread_setspecific(memory_node_key, node);
-}
-
-unsigned get_local_memory_node(void)
-{
-	unsigned *memory_node;
-	memory_node = pthread_getspecific(memory_node_key);
-	
-	/* in case this is called by the programmer, we assume the RAM node 
-	   is the appropriate memory node ... so we return 0 XXX */
-	if (STARPU_UNLIKELY(!memory_node))
-		return 0;
-
-	return *memory_node;
-}
-
-inline node_kind get_node_kind(uint32_t node)
-{
-	return descr.nodes[node];
-}
-
 int allocate_per_node_buffer(data_state *state, uint32_t node)
 {
 	int ret;

+ 6 - 32
src/datawizard/copy-driver.h

@@ -17,6 +17,8 @@
 #ifndef __COPY_DRIVER_H__
 #define __COPY_DRIVER_H__
 
+#include <common/config.h>
+#include <datawizard/memory_nodes.h>
 #include "coherency.h"
 #include "memalloc.h"
 
@@ -24,45 +26,17 @@
 #include <cublas.h>
 #endif
 
-
-typedef enum {
-	UNUSED,
-	SPU_LS,
-	RAM,
-	CUDA_RAM
-} node_kind;
-
-typedef struct {
-	unsigned nnodes;
-	node_kind nodes[MAXNODES];
-
-	/* the list of queues that are attached to a given node */
-	// XXX 32 is set randomly !
-	// TODO move this 2 lists outside mem_node_descr
-	struct starpu_mutex_t attached_queues_mutex;
-	struct jobq_s *attached_queues_per_node[MAXNODES][32];
-	struct jobq_s *attached_queues_all[MAXNODES*32];
-	/* the number of queues attached to each node */
-	unsigned total_queues_count;
-	unsigned queues_count[MAXNODES];
-} mem_node_descr;
-
 struct starpu_data_state_t;
 
 __attribute__((warn_unused_result))
-int driver_copy_data(struct starpu_data_state_t *state, uint32_t src_node_mask, uint32_t dst_node, unsigned donotread);
+int driver_copy_data(struct starpu_data_state_t *state, 
+			uint32_t src_node_mask,
+			uint32_t dst_node,
+			unsigned donotread);
 
-void init_memory_nodes(void);
-void deinit_memory_nodes(void);
-void set_local_memory_node_key(unsigned *node);
-unsigned get_local_memory_node(void);
-unsigned register_memory_node(node_kind kind);
-void memory_node_attach_queue(struct jobq_s *q, unsigned nodeid);
 void wake_all_blocked_workers(void);
 void wake_all_blocked_workers_on_node(unsigned nodeid);
 
-node_kind get_node_kind(uint32_t node);
-
 __attribute__((warn_unused_result))
 int driver_copy_data_1_to_1(struct starpu_data_state_t *state, uint32_t node, 
 				uint32_t requesting_node, unsigned donotread);

+ 139 - 0
src/datawizard/memory_nodes.c

@@ -0,0 +1,139 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
+ *
+ * This program 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.
+ *
+ * This program 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 <pthread.h>
+#include <common/config.h>
+#include <core/policies/sched_policy.h>
+#include <datawizard/datastats.h>
+#include <common/fxt.h>
+#include "copy-driver.h"
+#include "memalloc.h"
+
+mem_node_descr descr;
+static pthread_key_t memory_node_key;
+
+void init_memory_nodes(void)
+{
+	/* there is no node yet, subsequent nodes will be 
+	 * added using register_memory_node */
+	descr.nnodes = 0;
+
+	pthread_key_create(&memory_node_key, NULL);
+
+	unsigned i;
+	for (i = 0; i < MAXNODES; i++) 
+	{
+		descr.nodes[i] = UNUSED; 
+	}
+
+	init_mem_chunk_lists();
+	init_data_request_lists();
+}
+
+void deinit_memory_nodes(void)
+{
+	deinit_data_request_lists();
+	deinit_mem_chunk_lists();
+
+	pthread_key_delete(memory_node_key);
+}
+
+void set_local_memory_node_key(unsigned *node)
+{
+	pthread_setspecific(memory_node_key, node);
+}
+
+unsigned get_local_memory_node(void)
+{
+	unsigned *memory_node;
+	memory_node = pthread_getspecific(memory_node_key);
+	
+	/* in case this is called by the programmer, we assume the RAM node 
+	   is the appropriate memory node ... so we return 0 XXX */
+	if (STARPU_UNLIKELY(!memory_node))
+		return 0;
+
+	return *memory_node;
+}
+
+inline node_kind get_node_kind(uint32_t node)
+{
+	return descr.nodes[node];
+}
+
+
+unsigned register_memory_node(node_kind kind)
+{
+	unsigned nnodes;
+	/* ATOMIC_ADD returns the new value ... */
+	nnodes = STARPU_ATOMIC_ADD(&descr.nnodes, 1);
+
+	descr.nodes[nnodes-1] = kind;
+	TRACE_NEW_MEM_NODE(nnodes-1);
+
+	/* for now, there is no queue related to that newly created node */
+	descr.queues_count[nnodes-1] = 0;
+
+	return (nnodes-1);
+}
+
+/* TODO move in a more appropriate file  !! */
+/* attach a queue to a memory node (if it's not already attached) */
+void memory_node_attach_queue(struct jobq_s *q, unsigned nodeid)
+{
+	unsigned queue;
+	unsigned nqueues_total, nqueues;
+	
+	take_mutex(&descr.attached_queues_mutex);
+
+	/* we only insert the queue if it's not already in the list */
+	nqueues = descr.queues_count[nodeid];
+	for (queue = 0; queue < nqueues; queue++)
+	{
+		if (descr.attached_queues_per_node[nodeid][queue] == q)
+		{
+			/* the queue is already in the list */
+			release_mutex(&descr.attached_queues_mutex);
+			return;
+		}
+	}
+
+	/* it was not found locally */
+	descr.attached_queues_per_node[nodeid][nqueues] = q;
+	descr.queues_count[nodeid]++;
+
+	/* do we have to add it in the global list as well ? */
+	nqueues_total = descr.total_queues_count; 
+	for (queue = 0; queue < nqueues_total; queue++)
+	{
+		if (descr.attached_queues_all[queue] == q)
+		{
+			/* the queue is already in the global list */
+			release_mutex(&descr.attached_queues_mutex);
+			return;
+		}
+	} 
+
+	/* it was not in the global queue either */
+	descr.attached_queues_all[nqueues_total] = q;
+	descr.total_queues_count++;
+
+	release_mutex(&descr.attached_queues_mutex);
+}
+
+
+
+

+ 60 - 0
src/datawizard/memory_nodes.h

@@ -0,0 +1,60 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
+ *
+ * This program 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.
+ *
+ * This program 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_NODES_H__
+#define __MEMORY_NODES_H__
+
+#include "coherency.h"
+#include "memalloc.h"
+
+#ifdef USE_CUDA
+#include <cublas.h>
+#endif
+
+typedef enum {
+	UNUSED,
+	SPU_LS,
+	RAM,
+	CUDA_RAM
+} node_kind;
+
+typedef struct {
+	unsigned nnodes;
+	node_kind nodes[MAXNODES];
+
+	/* the list of queues that are attached to a given node */
+	// XXX 32 is set randomly !
+	// TODO move this 2 lists outside mem_node_descr
+	struct starpu_mutex_t attached_queues_mutex;
+	struct jobq_s *attached_queues_per_node[MAXNODES][32];
+	struct jobq_s *attached_queues_all[MAXNODES*32];
+	/* the number of queues attached to each node */
+	unsigned total_queues_count;
+	unsigned queues_count[MAXNODES];
+} mem_node_descr;
+
+struct starpu_data_state_t;
+
+void init_memory_nodes(void);
+void deinit_memory_nodes(void);
+void set_local_memory_node_key(unsigned *node);
+unsigned get_local_memory_node(void);
+unsigned register_memory_node(node_kind kind);
+void memory_node_attach_queue(struct jobq_s *q, unsigned nodeid);
+
+node_kind get_node_kind(uint32_t node);
+
+#endif // __MEMORY_NODES_H__