浏览代码

Cache the size and the footprint of the data into the handle structure rather
than computing them all the time.

Cédric Augonnet 15 年之前
父节点
当前提交
4e8827c5d3

+ 2 - 1
src/core/jobs.c

@@ -14,6 +14,7 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
 
+#include <starpu.h>
 #include <core/jobs.h>
 #include <core/task.h>
 #include <core/workers.h>
@@ -33,7 +34,7 @@ size_t _starpu_job_get_data_size(starpu_job_t j)
 	for (buffer = 0; buffer < nbuffers; buffer++)
 	{
 		starpu_data_handle handle = task->buffers[buffer].handle;
-		size += handle->ops->get_size(handle);
+		size += _starpu_data_get_size(handle);
 	}
 
 	return size;

+ 1 - 1
src/core/perfmodel/perfmodel.c

@@ -150,7 +150,7 @@ double _starpu_data_expected_penalty(struct starpu_jobq_s *q, struct starpu_task
 
 		if (!_starpu_is_data_present_or_requested(handle, memory_node))
 		{
-			size_t size = handle->ops->get_size(handle);
+			size_t size = _starpu_data_get_size(handle);
 
 			uint32_t src_node = _starpu_select_src_node(handle);
 

+ 10 - 0
src/datawizard/coherency.c

@@ -300,6 +300,16 @@ inline uint32_t _starpu_get_data_refcnt(starpu_data_handle handle, uint32_t node
 	return handle->per_node[node].refcnt;
 }
 
+size_t _starpu_data_get_size(starpu_data_handle handle)
+{
+	return handle->data_size;
+}
+
+uint32_t _starpu_data_get_footprint(starpu_data_handle handle)
+{
+	return handle->footprint;
+}
+
 /* in case the data was accessed on a write mode, do not forget to 
  * make it accessible again once it is possible ! */
 void _starpu_release_data_on_node(starpu_data_handle handle, uint32_t default_wb_mask, uint32_t memory_node)

+ 10 - 0
src/datawizard/coherency.h

@@ -95,6 +95,12 @@ struct starpu_data_state_t {
 
 	struct starpu_data_interface_ops_t *ops;
 
+	/* To avoid recomputing data size all the time, we store it directly. */
+	size_t data_size;
+
+	/* Footprint which identifies data layout */
+	uint32_t footprint;
+
 	/* where is the data home ? -1 if none yet */
 	int home_node;
 
@@ -138,6 +144,10 @@ void _starpu_update_data_state(struct starpu_data_state_t *state, uint32_t reque
 
 uint32_t _starpu_get_data_refcnt(struct starpu_data_state_t *state, uint32_t node);
 
+size_t _starpu_data_get_size(starpu_data_handle handle);
+
+uint32_t _starpu_data_get_footprint(starpu_data_handle handle);
+
 void _starpu_push_task_output(struct starpu_task *task, uint32_t mask);
 
 __attribute__((warn_unused_result))

+ 2 - 2
src/datawizard/copy_driver.c

@@ -217,7 +217,7 @@ int __attribute__((warn_unused_result)) _starpu_driver_copy_data_1_to_1(starpu_d
 		STARPU_ASSERT(handle->ops);
 		//STARPU_ASSERT(handle->ops->copy_data_1_to_1);
 
-		size_t size = handle->ops->get_size(handle);
+		size_t size = _starpu_data_get_size(handle);
 		_starpu_bus_update_profiling_info((int)src_node, (int)dst_node, size);
 		
 #ifdef STARPU_USE_FXT
@@ -234,7 +234,7 @@ int __attribute__((warn_unused_result)) _starpu_driver_copy_data_1_to_1(starpu_d
 #ifdef STARPU_USE_FXT
 		if (ret_copy != EAGAIN)
 		{
-			size_t size = handle->ops->get_size(handle);
+			size_t size = _starpu_data_get_size(handle);
 			STARPU_TRACE_END_DRIVER_COPY(src_node, dst_node, size, com_id);
 		}
 #endif

+ 1 - 1
src/datawizard/data_request.c

@@ -226,7 +226,7 @@ static void starpu_handle_data_request_completion(starpu_data_request_t r)
 	_starpu_update_data_state(handle, dst_node, r->mode);
 
 #ifdef STARPU_USE_FXT
-	size_t size = handle->ops->get_size(handle);
+	size_t size = _starpu_data_get_size(handle);
 	STARPU_TRACE_END_DRIVER_COPY(src_node, dst_node, size, r->com_id);
 #endif
 

+ 6 - 1
src/datawizard/filters.c

@@ -15,6 +15,7 @@
  */
 
 #include <datawizard/filters.h>
+#include <datawizard/footprint.h>
 
 /*
  * This function applies a starpu_filter on all the elements of a partition
@@ -122,10 +123,14 @@ void starpu_data_partition(starpu_data_handle initial_handle, starpu_filter *f)
 		children->depth = initial_handle->depth + 1;
 
 		children->is_not_important = initial_handle->is_not_important;
-
 		children->wb_mask = initial_handle->wb_mask;
 		children->home_node = initial_handle->home_node;
 
+		/* We compute the size and the footprint of the child once and
+		 * store it in the handle */
+		children->data_size = children->ops->get_size(children);
+		children->footprint = _starpu_compute_data_footprint(children);
+
 		/* initialize the chunk lock */
 		children->req_list = starpu_data_requester_list_new();
 		children->refcnt = 0;

+ 1 - 4
src/datawizard/footprint.c

@@ -28,10 +28,7 @@ void _starpu_compute_buffers_footprint(starpu_job_t j)
 	{
 		starpu_data_handle handle = task->buffers[buffer].handle;
 
-		STARPU_ASSERT(handle->ops);
-		STARPU_ASSERT(handle->ops->footprint);
-
-		uint32_t handle_footprint = handle->ops->footprint(handle);
+		uint32_t handle_footprint = _starpu_data_get_footprint(handle);
 
 		footprint = _starpu_crc32_be(handle_footprint, footprint);
 	}

+ 5 - 0
src/datawizard/interfaces/data_interface.c

@@ -55,6 +55,11 @@ static void _starpu_register_new_data(starpu_data_handle handle,
 
 	handle->wb_mask = wb_mask;
 
+	/* Store some values directly in the handle not to recompute them all
+	 * the time. */
+	handle->data_size = handle->ops->get_size(handle);
+	handle->footprint = _starpu_compute_data_footprint(handle);
+
 	handle->home_node = home_node;
 
 	/* that new data is invalid from all nodes perpective except for the

+ 1 - 2
src/datawizard/memalloc.c

@@ -628,8 +628,7 @@ size_t _starpu_allocate_interface(starpu_data_handle handle, void *interface, ui
 		if (!allocated_memory) {
 			/* XXX perhaps we should find the proper granularity 
 			 * not to waste our cache all the time */
-			STARPU_ASSERT(handle->ops->get_size);
-			size_t data_size = handle->ops->get_size(handle);
+			size_t data_size = _starpu_data_get_size(handle);
 
 			STARPU_TRACE_START_MEMRECLAIM(dst_node);
 			reclaim_memory(dst_node, 2*data_size);