浏览代码

fix confusion between handle allocated size and handle data size

Samuel Thibault 6 年之前
父节点
当前提交
dfea028a3b

+ 2 - 0
examples/cpp/add_vectors_interface.cpp

@@ -281,6 +281,7 @@ static struct starpu_data_interface_ops interface_vector_cpp_ops =
 	.to_pointer = vector_cpp_to_pointer,
 	.pointer_is_inside = vector_cpp_pointer_is_inside,
 	.get_size = vector_cpp_interface_get_size,
+	.get_alloc_size = NULL,
 	.footprint = footprint_vector_cpp_interface_crc32,
 	.alloc_footprint = NULL,
 	.compare = vector_cpp_compare,
@@ -306,6 +307,7 @@ static struct starpu_data_interface_ops interface_vector_cpp_ops =
 	vector_cpp_to_pointer,
 	vector_cpp_pointer_is_inside,
 	vector_cpp_interface_get_size,
+	NULL,
 	footprint_vector_cpp_interface_crc32,
 	NULL,
 	vector_cpp_compare,

+ 13 - 0
include/starpu_data_interfaces.h

@@ -440,6 +440,14 @@ struct starpu_data_interface_ops
 	size_t 		 (*get_size)			(starpu_data_handle_t handle);
 
 	/**
+	   Return an estimation of the size of allocated data, for allocation
+	   management.
+	   If not specified, the starpu_data_interface_ops::get_size method is
+	   used instead.
+	*/
+	size_t 		 (*get_alloc_size)		(starpu_data_handle_t handle);
+
+	/**
 	  Return a 32bit footprint which characterizes the data size and layout (nx, ny, ld, elemsize, etc.), to be used for indexing performance models.
 	*/
 	uint32_t 	 (*footprint)			(starpu_data_handle_t handle);
@@ -622,6 +630,11 @@ int starpu_data_unpack(starpu_data_handle_t handle, void *ptr, size_t count);
 size_t starpu_data_get_size(starpu_data_handle_t handle);
 
 /**
+   Return the size of the allocated data associated with \p handle.
+*/
+size_t starpu_data_get_alloc_size(starpu_data_handle_t handle);
+
+/**
    Return the handle corresponding to the data pointed to by the \p ptr host pointer.
 */
 starpu_data_handle_t starpu_data_lookup(const void *ptr);

+ 8 - 0
src/datawizard/coherency.c

@@ -851,6 +851,14 @@ size_t _starpu_data_get_size(starpu_data_handle_t handle)
 	return handle->ops->get_size(handle);
 }
 
+size_t _starpu_data_get_alloc_size(starpu_data_handle_t handle)
+{
+	if (handle->ops->get_alloc_size)
+		return handle->ops->get_alloc_size(handle);
+	else
+		return handle->ops->get_size(handle);
+}
+
 uint32_t _starpu_data_get_footprint(starpu_data_handle_t handle)
 {
 	return handle->footprint;

+ 1 - 0
src/datawizard/coherency.h

@@ -306,6 +306,7 @@ void _starpu_update_data_state(starpu_data_handle_t handle,
 uint32_t _starpu_get_data_refcnt(struct _starpu_data_state *state, unsigned node);
 
 size_t _starpu_data_get_size(starpu_data_handle_t handle);
+size_t _starpu_data_get_alloc_size(starpu_data_handle_t handle);
 
 uint32_t _starpu_data_get_footprint(starpu_data_handle_t handle);
 

+ 2 - 2
src/datawizard/filters.c

@@ -445,7 +445,7 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, unsigned gatherin
 
 		_starpu_spin_lock(&child_handle->header_lock);
 
-		sizes[child] = _starpu_data_get_size(child_handle);
+		sizes[child] = _starpu_data_get_alloc_size(child_handle);
 
 		if (child_handle->unregister_hook)
 		{
@@ -524,7 +524,7 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, unsigned gatherin
 
 		if (!isvalid && local->mc && local->allocated && local->automatically_allocated)
 			/* free the data copy in a lazy fashion */
-			_starpu_request_mem_chunk_removal(root_handle, local, node, _starpu_data_get_size(root_handle));
+			_starpu_request_mem_chunk_removal(root_handle, local, node, _starpu_data_get_alloc_size(root_handle));
 
 		/* if there was no invalid copy, the node still has a valid copy */
 		still_valid[node] = isvalid;

+ 7 - 2
src/datawizard/interfaces/data_interface.c

@@ -900,7 +900,7 @@ retry_busy:
 		goto retry_busy;
 	}
 
-	size_t size = _starpu_data_get_size(handle);
+	size_t size = _starpu_data_get_alloc_size(handle);
 
 	/* Destroy the data now */
 	unsigned node;
@@ -996,7 +996,7 @@ void starpu_data_unregister_submit(starpu_data_handle_t handle)
 static void _starpu_data_invalidate(void *data)
 {
 	starpu_data_handle_t handle = data;
-	size_t size = _starpu_data_get_size(handle);
+	size_t size = _starpu_data_get_alloc_size(handle);
 	_starpu_spin_lock(&handle->header_lock);
 
 	//_STARPU_DEBUG("Really invalidating data %p\n", data);
@@ -1106,6 +1106,11 @@ size_t starpu_data_get_size(starpu_data_handle_t handle)
 	return handle->ops->get_size(handle);
 }
 
+size_t starpu_data_get_alloc_size(starpu_data_handle_t handle)
+{
+	return handle->ops->get_alloc_size(handle);
+}
+
 void starpu_data_set_name(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED, const char *name STARPU_ATTRIBUTE_UNUSED)
 {
 	_STARPU_TRACE_DATA_NAME(handle, name);

+ 14 - 0
src/datawizard/interfaces/matrix_interface.c

@@ -91,6 +91,7 @@ static int matrix_pointer_is_inside(void *data_interface, unsigned node, void *p
 static starpu_ssize_t allocate_matrix_buffer_on_node(void *data_interface_, unsigned dst_node);
 static void free_matrix_buffer_on_node(void *data_interface, unsigned node);
 static size_t matrix_interface_get_size(starpu_data_handle_t handle);
+static size_t matrix_interface_get_alloc_size(starpu_data_handle_t handle);
 static uint32_t footprint_matrix_interface_crc32(starpu_data_handle_t handle);
 static uint32_t alloc_footprint_matrix_interface_crc32(starpu_data_handle_t handle);
 static int matrix_compare(void *data_interface_a, void *data_interface_b);
@@ -109,6 +110,7 @@ struct starpu_data_interface_ops starpu_interface_matrix_ops =
 	.free_data_on_node = free_matrix_buffer_on_node,
 	.copy_methods = &matrix_copy_data_methods_s,
 	.get_size = matrix_interface_get_size,
+	.get_alloc_size = matrix_interface_get_alloc_size,
 	.footprint = footprint_matrix_interface_crc32,
 	.alloc_footprint = alloc_footprint_matrix_interface_crc32,
 	.compare = matrix_compare,
@@ -321,6 +323,18 @@ static size_t matrix_interface_get_size(starpu_data_handle_t handle)
 	STARPU_ASSERT_MSG(matrix_interface->id == STARPU_MATRIX_INTERFACE_ID, "Error. The given data is not a matrix.");
 #endif
 
+	return matrix_interface->nx * matrix_interface->ny * matrix_interface->elemsize;
+}
+
+static size_t matrix_interface_get_alloc_size(starpu_data_handle_t handle)
+{
+	struct starpu_matrix_interface *matrix_interface = (struct starpu_matrix_interface *)
+		starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
+
+#ifdef STARPU_DEBUG
+	STARPU_ASSERT_MSG(matrix_interface->id == STARPU_MATRIX_INTERFACE_ID, "Error. The given data is not a matrix.");
+#endif
+
 	return matrix_interface->allocsize;
 }
 

+ 17 - 0
src/datawizard/interfaces/vector_interface.c

@@ -43,6 +43,7 @@ static void *vector_to_pointer(void *data_interface, unsigned node);
 static int vector_pointer_is_inside(void *data_interface, unsigned node, void *ptr);
 static void free_vector_buffer_on_node(void *data_interface, unsigned node);
 static size_t vector_interface_get_size(starpu_data_handle_t handle);
+static size_t vector_interface_get_alloc_size(starpu_data_handle_t handle);
 static uint32_t footprint_vector_interface_crc32(starpu_data_handle_t handle);
 static uint32_t alloc_footprint_vector_interface_crc32(starpu_data_handle_t handle);
 static int vector_compare(void *data_interface_a, void *data_interface_b);
@@ -61,6 +62,7 @@ struct starpu_data_interface_ops starpu_interface_vector_ops =
 	.free_data_on_node = free_vector_buffer_on_node,
 	.copy_methods = &vector_copy_data_methods_s,
 	.get_size = vector_interface_get_size,
+	.get_alloc_size = vector_interface_get_alloc_size,
 	.footprint = footprint_vector_interface_crc32,
 	.alloc_footprint = alloc_footprint_vector_interface_crc32,
 	.compare = vector_compare,
@@ -247,6 +249,21 @@ static size_t vector_interface_get_size(starpu_data_handle_t handle)
 	STARPU_ASSERT_MSG(vector_interface->id == STARPU_VECTOR_INTERFACE_ID, "Error. The given data is not a vector.");
 #endif
 
+	size = vector_interface->nx * vector_interface->elemsize;
+
+	return size;
+}
+
+static size_t vector_interface_get_alloc_size(starpu_data_handle_t handle)
+{
+	size_t size;
+	struct starpu_vector_interface *vector_interface = (struct starpu_vector_interface *)
+		starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
+
+#ifdef STARPU_DEBUG
+	STARPU_ASSERT_MSG(vector_interface->id == STARPU_VECTOR_INTERFACE_ID, "Error. The given data is not a vector.");
+#endif
+
 	size = vector_interface->allocsize;
 
 	return size;

+ 6 - 6
src/datawizard/memalloc.c

@@ -423,7 +423,7 @@ static size_t do_free_mem_chunk(struct _starpu_mem_chunk *mc, unsigned node)
 	if (handle)
 	{
 		_starpu_spin_checklocked(&handle->header_lock);
-		mc->size = _starpu_data_get_size(handle);
+		mc->size = _starpu_data_get_alloc_size(handle);
 	}
 
 	if (mc->replicate)
@@ -1375,7 +1375,7 @@ static starpu_ssize_t _starpu_allocate_interface(starpu_data_handle_t handle, st
 	unsigned attempts = 0;
 	starpu_ssize_t allocated_memory;
 	int ret;
-	starpu_ssize_t data_size = _starpu_data_get_size(handle);
+	starpu_ssize_t data_size = _starpu_data_get_alloc_size(handle);
 	int told_reclaiming = 0;
 	int reused = 0;
 
@@ -1433,7 +1433,7 @@ static starpu_ssize_t _starpu_allocate_interface(starpu_data_handle_t handle, st
 
 		if (allocated_memory == -ENOMEM)
 		{
-			size_t handle_size = handle->ops->get_size(handle);
+			size_t handle_size = handle->ops->get_alloc_size(handle);
 			size_t reclaim = starpu_memstrategy_data_size_coefficient*handle_size;
 
 			/* First try to flush data explicitly marked for freeing */
@@ -1692,7 +1692,7 @@ get_better_disk_can_accept_size(starpu_data_handle_t handle, unsigned node)
 	{
 		if (starpu_node_get_kind(i) == STARPU_DISK_RAM && i != node &&
 		    (handle->per_node[i].allocated ||
-		     _starpu_memory_manager_test_allocate_size(i, _starpu_data_get_size(handle)) == 1))
+		     _starpu_memory_manager_test_allocate_size(i, _starpu_data_get_alloc_size(handle)) == 1))
 		{
 			/* if we can write on the disk */
 			if (_starpu_get_disk_flag(i) != STARPU_DISK_NO_RECLAIM)
@@ -1702,7 +1702,7 @@ get_better_disk_can_accept_size(starpu_data_handle_t handle, unsigned node)
 				for (numa = 0; numa < nnumas; numa++)
 				{
 					/* TODO : check if starpu_transfer_predict(node, i,...) is the same */
-					double time_tmp = starpu_transfer_predict(node, numa, _starpu_data_get_size(handle)) + starpu_transfer_predict(i, numa, _starpu_data_get_size(handle));
+					double time_tmp = starpu_transfer_predict(node, numa, _starpu_data_get_alloc_size(handle)) + starpu_transfer_predict(i, numa, _starpu_data_get_alloc_size(handle));
 					if (target == -1 || time_disk > time_tmp)
 					{
 						target = i;
@@ -1724,7 +1724,7 @@ static int
 choose_target(starpu_data_handle_t handle, unsigned node)
 {
 	int target = -1;
-	size_t size_handle = _starpu_data_get_size(handle);
+	size_t size_handle = _starpu_data_get_alloc_size(handle);
 	if (handle->home_node != -1)
 		/* try to push on RAM if we can before to push on disk */
 		if(starpu_node_get_kind(handle->home_node) == STARPU_DISK_RAM && (starpu_node_get_kind(node) != STARPU_CPU_RAM))