Bladeren bron

Rearrange _starpu_data_state fields and initialization

Make some of the fields 1-bit booleans.
Move most (common) initialization to _starpu_data_handle_init.
Samuel Thibault 5 jaren geleden
bovenliggende
commit
c4bf3c6484
3 gewijzigde bestanden met toevoegingen van 135 en 142 verwijderingen
  1. 14 12
      src/datawizard/coherency.h
  2. 5 59
      src/datawizard/filters.c
  3. 116 71
      src/datawizard/interfaces/data_interface.c

+ 14 - 12
src/datawizard/coherency.h

@@ -193,14 +193,24 @@ struct _starpu_data_state
 
 	/** in some case, the application may explicitly tell StarPU that a
  	 * piece of data is not likely to be used soon again */
-	unsigned is_not_important;
+	unsigned is_not_important:1;
 
 	/** Does StarPU have to enforce some implicit data-dependencies ? */
-	unsigned sequential_consistency;
+	unsigned sequential_consistency:1;
 	/** Is the data initialized, or a task is already submitted to initialize it */
-	unsigned initialized;
+	unsigned initialized:1;
 	/** Can the data be pushed to the disk? */
-	unsigned ooc;
+	unsigned ooc:1;
+
+	/** Whether lazy unregistration was requested throught starpu_data_unregister_submit */
+	unsigned lazy_unregister:1;
+
+	/** Whether automatic planned partitioning/unpartitioning should not be done */
+	int partition_automatic_disabled:1;
+
+#ifdef STARPU_OPENMP
+	unsigned removed_from_context_hash:1;
+#endif
 
 	/** This lock should protect any operation to enforce
 	 * sequential_consistency */
@@ -254,12 +264,6 @@ struct _starpu_data_state
 	/** Final request for write invalidation */
 	struct _starpu_data_request *write_invalidation_req;
 
-	unsigned lazy_unregister;
-
-#ifdef STARPU_OPENMP
-	unsigned removed_from_context_hash;
-#endif
-
         /** Used for MPI */
 	void *mpi_data;
 
@@ -279,8 +283,6 @@ struct _starpu_data_state
 	 * took it yet */
 	int last_locality;
 
-	int partition_automatic_disabled;
-
 	/** Application-provided coordinates. The maximum dimension (5) is
 	  * relatively arbitrary. */
 	unsigned dimensions;

+ 5 - 59
src/datawizard/filters.c

@@ -232,19 +232,9 @@ static void _starpu_data_partition(starpu_data_handle_t initial_handle, starpu_d
 		memset(child, 0, sizeof(*child));
 		_starpu_data_handle_init(child, ops, initial_handle->mf_node);
 
-		//child->nchildren = 0;
-		//child->nplans = 0;
-		//child->switch_cl = NULL;
-		//child->partitioned = 0;
-		//child->part_readonly = 0;
-		child->active = inherit_state;
-		//child->active_ro = 0;
-                //child->mpi_data = NULL;
 		child->root_handle = initial_handle->root_handle;
 		child->father_handle = initial_handle;
-		//child->active_children = NULL;
-		//child->active_readonly_children = NULL;
-		//child->nactive_readonly_children = 0;
+
 		child->nsiblings = nparts;
 		if (inherit_state)
 		{
@@ -255,59 +245,22 @@ static void _starpu_data_partition(starpu_data_handle_t initial_handle, starpu_d
 		child->sibling_index = i;
 		child->depth = initial_handle->depth + 1;
 
-		child->is_not_important = initial_handle->is_not_important;
-		child->wt_mask = initial_handle->wt_mask;
+		child->active = inherit_state;
+
 		child->home_node = initial_handle->home_node;
+		child->wt_mask = initial_handle->wt_mask;
 
-		/* initialize the chunk lock */
-		_starpu_data_requester_prio_list_init(&child->req_list);
-		_starpu_data_requester_prio_list_init(&child->reduction_req_list);
-		//child->reduction_tmp_handles = NULL;
-		//child->write_invalidation_req = NULL;
-		//child->refcnt = 0;
-		//child->unlocking_reqs = 0;
-		//child->busy_count = 0;
-		//child->busy_waiting = 0;
-		STARPU_PTHREAD_MUTEX_INIT0(&child->busy_mutex, NULL);
-		STARPU_PTHREAD_COND_INIT0(&child->busy_cond, NULL);
-		//child->reduction_refcnt = 0;
-		_starpu_spin_init(&child->header_lock);
+		child->is_not_important = initial_handle->is_not_important;
 
 		child->sequential_consistency = initial_handle->sequential_consistency;
 		child->initialized = initial_handle->initialized;
 		child->ooc = initial_handle->ooc;
 
-		STARPU_PTHREAD_MUTEX_INIT0(&child->sequential_consistency_mutex, NULL);
-		child->last_submitted_mode = STARPU_R;
-		//child->last_sync_task = NULL;
-		//child->last_submitted_accessors.task = NULL;
-		child->last_submitted_accessors.next = &child->last_submitted_accessors;
-		child->last_submitted_accessors.prev = &child->last_submitted_accessors;
-		//child->post_sync_tasks = NULL;
-		/* Tell helgrind that the race in _starpu_unlock_post_sync_tasks is fine */
-		STARPU_HG_DISABLE_CHECKING(child->post_sync_tasks_cnt);
-		//child->post_sync_tasks_cnt = 0;
-
 		/* The methods used for reduction are propagated to the
 		 * children. */
 		child->redux_cl = initial_handle->redux_cl;
 		child->init_cl = initial_handle->init_cl;
 
-#ifdef STARPU_USE_FXT
-		//child->last_submitted_ghost_sync_id_is_valid = 0;
-		//child->last_submitted_ghost_sync_id = 0;
-		//child->last_submitted_ghost_accessors_id = NULL;
-#endif
-
-		if (_starpu_global_arbiter)
-			/* Just for testing purpose */
-			starpu_data_assign_arbiter(child, _starpu_global_arbiter);
-		else
-		{
-			//child->arbiter = NULL;
-		}
-		_starpu_data_requester_prio_list_init0(&child->arbitered_req_list);
-
 		for (node = 0; node < STARPU_MAXNODES; node++)
 		{
 			struct _starpu_data_replicate *initial_replicate;
@@ -346,13 +299,6 @@ static void _starpu_data_partition(starpu_data_handle_t initial_handle, starpu_d
 			f->filter_func(initial_interface, child_interface, f, i, nparts);
 		}
 
-		//child->per_worker = NULL;
-		//child->user_data = NULL;
-
-		/* We compute the size and the footprint of the child once and
-		 * store it in the handle */
-		child->footprint = _starpu_compute_data_footprint(child);
-
 		for (node = 0; node < STARPU_MAXNODES; node++)
 		{
 			if (starpu_node_get_kind(node) != STARPU_CPU_RAM)

+ 116 - 71
src/datawizard/interfaces/data_interface.c

@@ -259,37 +259,21 @@ static void _starpu_register_new_data(starpu_data_handle_t handle,
 
 	STARPU_ASSERT(handle);
 
-	/* initialize the new lock */
-	_starpu_data_requester_prio_list_init0(&handle->req_list);
-	//handle->refcnt = 0;
-	//handle->unlocking_reqs = 0;
-	//handle->busy_count = 0;
-	//handle->busy_waiting = 0;
-	STARPU_PTHREAD_MUTEX_INIT0(&handle->busy_mutex, NULL);
-	STARPU_PTHREAD_COND_INIT0(&handle->busy_cond, NULL);
-	_starpu_spin_init(&handle->header_lock);
-
 	/* first take care to properly lock the data */
 	_starpu_spin_lock(&handle->header_lock);
 
-	/* there is no hierarchy yet */
-	//handle->nchildren = 0;
-	//handle->nplans = 0;
-	//handle->switch_cl = NULL;
-	//handle->partitioned = 0;
-	//handle->part_readonly = 0;
-	handle->active = 1;
-	//handle->active_ro = 0;
 	handle->root_handle = handle;
 	//handle->father_handle = NULL;
-	//handle->active_children = NULL;
-	//handle->active_readonly_children = NULL;
-	//handle->nactive_readonly_children = 0;
 	//handle->nsiblings = 0;
 	//handle->siblings = NULL;
 	//handle->sibling_index = 0; /* could be anything for the root */
 	handle->depth = 1; /* the tree is just a node yet */
-        //handle->mpi_data = NULL; /* invalid until set */
+
+	handle->active = 1;
+
+	handle->home_node = home_node;
+
+	handle->wt_mask = wt_mask;
 
 	//handle->is_not_important = 0;
 
@@ -298,51 +282,10 @@ static void _starpu_register_new_data(starpu_data_handle_t handle,
 	handle->initialized = home_node != -1;
 	handle->ooc = 1;
 
-	STARPU_PTHREAD_MUTEX_INIT0(&handle->sequential_consistency_mutex, NULL);
-	handle->last_submitted_mode = STARPU_R;
-	//handle->last_sync_task = NULL;
-	//handle->last_submitted_accessors.task = NULL;
-	handle->last_submitted_accessors.next = &handle->last_submitted_accessors;
-	handle->last_submitted_accessors.prev = &handle->last_submitted_accessors;
-	//handle->post_sync_tasks = NULL;
-
-	/* Tell helgrind that the race in _starpu_unlock_post_sync_tasks is fine */
-	STARPU_HG_DISABLE_CHECKING(handle->post_sync_tasks_cnt);
-	//handle->post_sync_tasks_cnt = 0;
-
 	/* By default, there are no methods available to perform a reduction */
 	//handle->redux_cl = NULL;
 	//handle->init_cl = NULL;
 
-	//handle->reduction_refcnt = 0;
-	_starpu_data_requester_prio_list_init0(&handle->reduction_req_list);
-	//handle->reduction_tmp_handles = NULL;
-	//handle->write_invalidation_req = NULL;
-
-#ifdef STARPU_USE_FXT
-	//handle->last_submitted_ghost_sync_id_is_valid = 0;
-	//handle->last_submitted_ghost_sync_id = 0;
-	//handle->last_submitted_ghost_accessors_id = NULL;
-#endif
-
-	handle->wt_mask = wt_mask;
-
-	/* Store some values directly in the handle not to recompute them all
-	 * the time. */
-	handle->footprint = _starpu_compute_data_footprint(handle);
-
-	handle->home_node = home_node;
-
-	if (_starpu_global_arbiter)
-		/* Just for testing purpose */
-		starpu_data_assign_arbiter(handle, _starpu_global_arbiter);
-	else
-	{
-		//handle->arbiter = NULL;
-	}
-	_starpu_data_requester_prio_list_init0(&handle->arbitered_req_list);
-	handle->last_locality = -1;
-
 	/* that new data is invalid from all nodes perpective except for the
 	 * home node */
 	unsigned node;
@@ -372,9 +315,6 @@ static void _starpu_register_new_data(starpu_data_handle_t handle,
 		}
 	}
 
-	//handle->per_worker = NULL;
-	//handle->user_data = NULL;
-
 	/* now the data is available ! */
 	_starpu_spin_unlock(&handle->header_lock);
 
@@ -449,14 +389,47 @@ int _starpu_data_handle_init(starpu_data_handle_t handle, struct starpu_data_int
 	STARPU_HG_DISABLE_CHECKING(handle->busy_count);
 
 	handle->magic = 42;
-	handle->ops = interface_ops;
-	handle->mf_node = mf_node;
-	//handle->mpi_data = NULL;
-	//handle->partition_automatic_disabled = 0;
 
+	/* When not specified, the fields are initialized in _starpu_register_new_data and _starpu_data_partition */
+
+	_starpu_data_requester_prio_list_init0(&handle->req_list);
+	//handle->refcnt = 0;
+	//handle->unlocking_reqs = 0;
+	//handle->current_mode = STARPU_NONE;
+	_starpu_spin_init(&handle->header_lock);
+
+	//handle->busy_count = 0;
+	//handle->busy_waiting = 0;
+	STARPU_PTHREAD_MUTEX_INIT0(&handle->busy_mutex, NULL);
+	STARPU_PTHREAD_COND_INIT0(&handle->busy_cond, NULL);
+
+	//handle->root_handle
+	//handle->father_handle
+	//handle->active_children = NULL;
+	//handle->active_readonly_children = NULL;
+	//handle->nactive_readonly_children = 0;
+	//handle->nsiblings
+	//handle->siblings
+	//handle->sibling_index
+	//handle->depth
+
+	/* there is no hierarchy yet */
+	//handle->children = NULL;
+	//handle->nchildren = 0;
+	//handle->nplans = 0;
+	//handle->switch_cl = NULL;
+	//handle->switch_cl_nparts = 0;
+	//handle->partitioned = 0;
+	//handle->part_readonly = 0;
+
+	//handle->active
+	//handle->active_ro = 0;
+
+	//handle->per_node below
+
+	handle->ops = interface_ops;
 	size_t interfacesize = interface_ops->interface_size;
 
-	_starpu_memory_stats_init(handle);
 	for (node = 0; node < STARPU_MAXNODES; node++)
 	{
 		_starpu_memory_stats_init_per_node(handle, node);
@@ -471,6 +444,78 @@ int _starpu_data_handle_init(starpu_data_handle_t handle, struct starpu_data_int
 		if (handle->ops->init) handle->ops->init(replicate->data_interface);
 	}
 
+	//handle->per_worker = NULL;
+	//handle->ops above
+
+	/* Store some values directly in the handle not to recompute them all
+	 * the time. */
+	handle->footprint = _starpu_compute_data_footprint(handle);
+
+	//handle->home_node
+	//handle->wt_mask
+	//handle->is_not_important
+	//handle->sequential_consistency
+	//handle->initialized
+	//handle->ooc
+	//handle->lazy_unregister = 0;
+	//handle->partition_automatic_disabled = 0;
+	//handle->removed_from_context_hash = 0;
+
+	STARPU_PTHREAD_MUTEX_INIT0(&handle->sequential_consistency_mutex, NULL);
+
+	handle->last_submitted_mode = STARPU_R;
+	//handle->last_sync_task = NULL;
+	//handle->last_submitted_accessors.task = NULL;
+	handle->last_submitted_accessors.next = &handle->last_submitted_accessors;
+	handle->last_submitted_accessors.prev = &handle->last_submitted_accessors;
+
+#ifdef STARPU_USE_FXT
+	//handle->last_submitted_ghost_sync_id_is_valid = 0;
+	//handle->last_submitted_ghost_sync_id = 0;
+	//handle->last_submitted_ghost_accessors_id = NULL;
+#endif
+
+	//handle->post_sync_tasks = NULL;
+	/* Tell helgrind that the race in _starpu_unlock_post_sync_tasks is fine */
+	STARPU_HG_DISABLE_CHECKING(handle->post_sync_tasks_cnt);
+	//handle->post_sync_tasks_cnt = 0;
+
+	//handle->redux_cl
+	//handle->init_cl
+
+	//handle->reduction_refcnt = 0;
+
+	_starpu_data_requester_prio_list_init0(&handle->reduction_req_list);
+
+	//handle->reduction_tmp_handles = NULL;
+
+	//handle->write_invalidation_req = NULL;
+
+        //handle->mpi_data = NULL; /* invalid until set */
+
+	_starpu_memory_stats_init(handle);
+
+	handle->mf_node = mf_node;
+
+        //handle->unregister_hook = NULL;
+
+	if (_starpu_global_arbiter)
+		/* Just for testing purpose */
+		starpu_data_assign_arbiter(handle, _starpu_global_arbiter);
+	else
+	{
+		//handle->arbiter = NULL;
+	}
+	_starpu_data_requester_prio_list_init0(&handle->arbitered_req_list);
+
+	handle->last_locality = -1;
+
+	//handle->dimensions = 0;
+	//handle->coordinates = {};
+
+	//handle->user_data = NULL;
+
+
 	return 0;
 }