Browse Source

src/datawizard: partly revert 8083 for update children storage in
starpu_data_handle_t.

Having starpu_data_handle_t *children; allows to have a
contiguous memory which is allocated at once.

We still keep a function

int _starpu_data_handle_init(starpu_data_handle_t handle, struct starpu_data_interface_ops *interface_ops);

which initialises an already allocated handle.

Nathalie Furmento 12 years ago
parent
commit
b222c59e81

+ 1 - 1
src/datawizard/coherency.h

@@ -126,7 +126,7 @@ struct _starpu_data_state
 	unsigned sibling_index; /* indicate which child this node is from the father's perpsective (if any) */
 	unsigned depth; /* what's the depth of the tree ? */
 
-	starpu_data_handle_t *children;
+	starpu_data_handle_t children;
 	unsigned nchildren;
 
 	/* describe the state of the data in term of coherency */

+ 14 - 12
src/datawizard/filters.c

@@ -40,7 +40,8 @@ static void map_filter(starpu_data_handle_t root_handle, struct starpu_data_filt
 		unsigned child;
 		for (child = 0; child < root_handle->nchildren; child++)
 		{
-			map_filter(root_handle->children[child], f);
+			starpu_data_handle_t handle_child = starpu_data_get_child(root_handle, child);
+			map_filter(handle_child, f);
 		}
 	}
 }
@@ -74,8 +75,7 @@ int starpu_data_get_nb_children(starpu_data_handle_t handle)
 starpu_data_handle_t starpu_data_get_child(starpu_data_handle_t handle, unsigned i)
 {
 	STARPU_ASSERT(i < handle->nchildren);
-
-	return handle->children[i];
+	return &handle->children[i];
 }
 
 /*
@@ -105,7 +105,7 @@ starpu_data_handle_t starpu_data_vget_sub_data(starpu_data_handle_t root_handle,
 
 		STARPU_ASSERT(next_child < current_handle->nchildren);
 
-		current_handle = current_handle->children[next_child];
+		current_handle = &current_handle->children[next_child];
 	}
 
 	return current_handle;
@@ -278,7 +278,7 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, uint32_t gatherin
 	/* first take all the children lock (in order !) */
 	for (child = 0; child < root_handle->nchildren; child++)
 	{
-		starpu_data_handle_t child_handle = root_handle->children[child];
+		starpu_data_handle_t child_handle = starpu_data_get_child(root_handle, child);
 
 		/* make sure the intermediate children is unpartitionned as well */
 		if (child_handle->nchildren > 0)
@@ -316,7 +316,7 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, uint32_t gatherin
 
 		_starpu_spin_lock(&child_handle->header_lock);
 
-		_starpu_data_free_interfaces(root_handle->children[child]);
+		_starpu_data_free_interfaces(child_handle);
 		_starpu_data_requester_list_delete(child_handle->req_list);
 		_starpu_data_requester_list_delete(child_handle->reduction_req_list);
 	}
@@ -343,7 +343,8 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, uint32_t gatherin
 
 		for (child = 0; child < root_handle->nchildren; child++)
 		{
-			struct _starpu_data_replicate *local = &root_handle->children[child]->per_node[node];
+			starpu_data_handle_t child_handle = starpu_data_get_child(root_handle, child);
+			struct _starpu_data_replicate *local = &child_handle->per_node[node];
 
 			if (local->state == STARPU_INVALID)
 			{
@@ -353,7 +354,7 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, uint32_t gatherin
 
 			if (local->allocated && local->automatically_allocated)
 				/* free the child data copy in a lazy fashion */
-				_starpu_request_mem_chunk_removal(root_handle->children[child], node, 1);
+				_starpu_request_mem_chunk_removal(child_handle, node, 1);
 		}
 
 		if (!root_handle->per_node[node].allocated)
@@ -384,7 +385,7 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, uint32_t gatherin
 
 	for (child = 0; child < root_handle->nchildren; child++)
 	{
-		starpu_data_handle_t child_handle = root_handle->children[child];
+		starpu_data_handle_t child_handle = starpu_data_get_child(root_handle, child);
 		_starpu_spin_unlock(&child_handle->header_lock);
 	}
 
@@ -400,7 +401,7 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, uint32_t gatherin
 /* each child may have his own interface type */
 static void starpu_data_create_children(starpu_data_handle_t handle, unsigned nchildren, struct starpu_data_filter *f)
 {
-	handle->children = (struct _starpu_data_state **) calloc(nchildren, sizeof(struct _starpu_data_state *));
+	handle->children = (struct _starpu_data_state *) calloc(nchildren, sizeof(struct _starpu_data_state));
 	STARPU_ASSERT(handle->children);
 
 	unsigned node;
@@ -411,6 +412,7 @@ static void starpu_data_create_children(starpu_data_handle_t handle, unsigned nc
 
 	for (child = 0; child < nchildren; child++)
 	{
+		starpu_data_handle_t handle_child;
 		struct starpu_data_interface_ops *ops;
 
 		/* what's this child's interface ? */
@@ -419,7 +421,8 @@ static void starpu_data_create_children(starpu_data_handle_t handle, unsigned nc
 		else
 		  ops = handle->ops;
 
-		starpu_data_handle_t handle_child = _starpu_data_handle_allocate(ops);
+		handle_child = &handle->children[child];
+		_starpu_data_handle_init(handle_child, ops);
 
 		size_t interfacesize = ops->interface_size;
 
@@ -439,7 +442,6 @@ static void starpu_data_create_children(starpu_data_handle_t handle, unsigned nc
 		}
 
 		handle_child->mf_node = handle->mf_node;
-		handle->children[child] = handle_child;
 	}
 
 	/* this handle now has children */

+ 12 - 8
src/datawizard/interfaces/data_interface.c

@@ -228,18 +228,16 @@ static void _starpu_register_new_data(starpu_data_handle_t handle,
 	}
 }
 
-starpu_data_handle_t _starpu_data_handle_allocate(struct starpu_data_interface_ops *interface_ops)
+int _starpu_data_handle_init(starpu_data_handle_t handle, struct starpu_data_interface_ops *interface_ops)
 {
-	starpu_data_handle_t handle = (starpu_data_handle_t) calloc(1, sizeof(struct _starpu_data_state));
-
-	STARPU_ASSERT(handle);
+	unsigned node;
+	unsigned worker;
 
 	handle->ops = interface_ops;
 
 	size_t interfacesize = interface_ops->interface_size;
 
 	_starpu_memory_stats_init(handle);
-	unsigned node;
 	for (node = 0; node < STARPU_MAXNODES; node++)
 	{
 		_starpu_memory_stats_init_per_node(handle, node);
@@ -254,7 +252,6 @@ starpu_data_handle_t _starpu_data_handle_allocate(struct starpu_data_interface_o
 		STARPU_ASSERT(replicate->data_interface);
 	}
 
-	unsigned worker;
 	unsigned nworkers = starpu_worker_get_count();
 	for (worker = 0; worker < nworkers; worker++)
 	{
@@ -271,6 +268,14 @@ starpu_data_handle_t _starpu_data_handle_allocate(struct starpu_data_interface_o
 	handle->tag = -1;
 	handle->rank = -1;
 
+	return 0;
+}
+
+starpu_data_handle_t _starpu_data_handle_allocate(struct starpu_data_interface_ops *interface_ops)
+{
+	starpu_data_handle_t handle = (starpu_data_handle_t) calloc(1, sizeof(struct _starpu_data_state));
+	STARPU_ASSERT(handle);
+	_starpu_data_handle_init(handle, interface_ops);
 	return handle;
 }
 
@@ -278,8 +283,7 @@ void starpu_data_register(starpu_data_handle_t *handleptr, uint32_t home_node,
 				void *data_interface,
 				struct starpu_data_interface_ops *ops)
 {
-	starpu_data_handle_t handle =
-		_starpu_data_handle_allocate(ops);
+	starpu_data_handle_t handle = _starpu_data_handle_allocate(ops);
 
 	STARPU_ASSERT(handleptr);
 	*handleptr = handle;

+ 1 - 1
src/datawizard/interfaces/data_interface.h

@@ -27,7 +27,7 @@ void _starpu_data_free_interfaces(starpu_data_handle_t handle)
 	STARPU_ATTRIBUTE_INTERNAL;
 
 extern
-starpu_data_handle_t _starpu_data_handle_allocate(struct starpu_data_interface_ops *interface_ops);
+int _starpu_data_handle_init(starpu_data_handle_t handle, struct starpu_data_interface_ops *interface_ops);
 
 extern void _starpu_data_interface_init(void) STARPU_ATTRIBUTE_INTERNAL;
 extern int _starpu_data_check_not_busy(starpu_data_handle_t handle) STARPU_ATTRIBUTE_INTERNAL;

+ 9 - 6
src/datawizard/memalloc.c

@@ -83,7 +83,8 @@ static void lock_all_subtree(starpu_data_handle_t handle)
 		unsigned child;
 		for (child = 0; child < handle->nchildren; child++)
 		{
-			lock_all_subtree(handle->children[child]);
+			starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
+			lock_all_subtree(child_handle);
 		}
 	}
 }
@@ -104,7 +105,8 @@ static void unlock_all_subtree(starpu_data_handle_t handle)
 		for (i =0; i < handle->nchildren; i++)
 		{
 			unsigned child = handle->nchildren - 1 - i;
-			unlock_all_subtree(handle->children[child]);
+			starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
+			unlock_all_subtree(child_handle);
 		}
 	}
 }
@@ -124,7 +126,8 @@ static unsigned may_free_subtree(starpu_data_handle_t handle, unsigned node)
 	for (child = 0; child < handle->nchildren; child++)
 	{
 		unsigned res;
-		res = may_free_subtree(handle->children[child], node);
+		starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
+		res = may_free_subtree(child_handle, node);
 		if (!res) return 0;
 	}
 
@@ -208,8 +211,8 @@ static void transfer_subtree_to_node(starpu_data_handle_t handle, unsigned src_n
 		unsigned child;
 		for (child = 0; child < handle->nchildren; child++)
 		{
-			transfer_subtree_to_node(handle->children[child],
-						 src_node, dst_node);
+			starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
+			transfer_subtree_to_node(child_handle, src_node, dst_node);
 		}
 	}
 }
@@ -842,7 +845,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);
+			_starpu_memory_manager_sub_size(size);
 			break;
 #ifdef STARPU_USE_CUDA
 		case STARPU_CUDA_RAM:

+ 6 - 0
src/datawizard/memory_manager.c

@@ -36,3 +36,9 @@ int _starpu_memory_manager_add_size(size_t size)
      used_size += size;
      return 0;
 }
+
+int _starpu_memory_manager_sub_size(size_t size)
+{
+     used_size -= size;
+     return 0;
+}

+ 1 - 0
src/datawizard/memory_manager.h

@@ -22,5 +22,6 @@
 
 int _starpu_memory_manager_init();
 int _starpu_memory_manager_add_size(size_t size);
+int _starpu_memory_manager_sub_size(size_t size);
 
 #endif /* __MEMORY_MANAGER_H__ */

+ 1 - 1
src/datawizard/reduction.c

@@ -34,7 +34,7 @@ void starpu_data_set_reduction_methods(starpu_data_handle_t handle,
 	for (child = 0; child < handle->nchildren; child++)
 	{
 		/* make sure that the flags are applied to the children as well */
-		starpu_data_handle_t child_handle = handle->children[child];
+		starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
 		if (child_handle->nchildren > 0)
 			starpu_data_set_reduction_methods(child_handle, redux_cl, init_cl);
 	}

+ 2 - 2
src/datawizard/user_interactions.c

@@ -431,7 +431,7 @@ void starpu_data_advise_as_important(starpu_data_handle_t handle, unsigned is_im
 	for (child = 0; child < handle->nchildren; child++)
 	{
 		/* make sure the intermediate children is advised as well */
-		starpu_data_handle_t child_handle = handle->children[child];
+		starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
 		if (child_handle->nchildren > 0)
 			starpu_data_advise_as_important(child_handle, is_important);
 	}
@@ -451,7 +451,7 @@ void starpu_data_set_sequential_consistency_flag(starpu_data_handle_t handle, un
 	for (child = 0; child < handle->nchildren; child++)
 	{
 		/* make sure that the flags are applied to the children as well */
-		starpu_data_handle_t child_handle = handle->children[child];
+		starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
 		if (child_handle->nchildren > 0)
 			starpu_data_set_sequential_consistency_flag(child_handle, flag);
 	}

+ 4 - 1
src/datawizard/write_back.c

@@ -78,6 +78,9 @@ void starpu_data_set_wt_mask(starpu_data_handle_t handle, uint32_t wt_mask)
 	{
 		unsigned child;
 		for (child = 0; child < handle->nchildren; child++)
-			starpu_data_set_wt_mask(handle->children[child], wt_mask);
+		{
+			starpu_data_handle_t handle_child = starpu_data_get_child(handle, child);
+			starpu_data_set_wt_mask(handle_child, wt_mask);
+		}
 	}
 }