Ver código fonte

The allocate_data_on_node method of the starpu_data_interface_ops_t structure
now returns a signed size_t. When an allocation fails, it returns -ENOMEM
instead of 0, so that we can implement "dummy" interfaces which does not
allocate any memory.

Cédric Augonnet 14 anos atrás
pai
commit
57ab0708b3

+ 1 - 1
include/starpu_data_interfaces.h

@@ -83,7 +83,7 @@ struct starpu_data_copy_methods {
 struct starpu_data_interface_ops_t {
 	void (*register_data_handle)(starpu_data_handle handle,
 					uint32_t home_node, void *interface);
-	size_t (*allocate_data_on_node)(void *interface, uint32_t node);
+	ssize_t (*allocate_data_on_node)(void *interface, uint32_t node);
 	void (*free_data_on_node)(void *interface, uint32_t node);
 	const struct starpu_data_copy_methods *copy_methods;
 	size_t (*get_size)(starpu_data_handle handle);

+ 4 - 6
src/datawizard/interfaces/bcsr_interface.c

@@ -59,7 +59,7 @@ static const struct starpu_data_copy_methods bcsr_copy_data_methods_s = {
 };
 
 static void register_bcsr_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
-static size_t allocate_bcsr_buffer_on_node(void *interface, uint32_t dst_node);
+static ssize_t allocate_bcsr_buffer_on_node(void *interface, uint32_t dst_node);
 static void free_bcsr_buffer_on_node(void *interface, uint32_t node);
 static size_t bcsr_interface_get_size(starpu_data_handle handle);
 static int bcsr_compare(void *interface_a, void *interface_b);
@@ -252,11 +252,11 @@ static size_t bcsr_interface_get_size(starpu_data_handle handle)
 /* memory allocation/deallocation primitives for the BLAS interface */
 
 /* returns the size of the allocated area */
-static size_t allocate_bcsr_buffer_on_node(void *interface_, uint32_t dst_node)
+static ssize_t allocate_bcsr_buffer_on_node(void *interface_, uint32_t dst_node)
 {
 	uintptr_t addr_nzval;
 	uint32_t *addr_colind, *addr_rowptr;
-	size_t allocated_memory;
+	ssize_t allocated_memory;
 
 	/* we need the 3 arrays to be allocated */
 	starpu_bcsr_interface_t *interface = interface_;
@@ -376,9 +376,7 @@ fail_colind:
 fail_nzval:
 
 	/* allocation failed */
-	allocated_memory = 0;
-
-	return allocated_memory;
+	return -ENOMEM;
 }
 
 static void free_bcsr_buffer_on_node(void *interface, uint32_t node)

+ 4 - 4
src/datawizard/interfaces/block_interface.c

@@ -64,7 +64,7 @@ static const struct starpu_data_copy_methods block_copy_data_methods_s = {
 
 
 static void register_block_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
-static size_t allocate_block_buffer_on_node(void *interface_, uint32_t dst_node);
+static ssize_t allocate_block_buffer_on_node(void *interface_, uint32_t dst_node);
 static void free_block_buffer_on_node(void *interface, uint32_t node);
 static size_t block_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_block_interface_crc32(starpu_data_handle handle);
@@ -272,11 +272,11 @@ size_t starpu_block_get_elemsize(starpu_data_handle handle)
 /* memory allocation/deallocation primitives for the BLOCK interface */
 
 /* returns the size of the allocated area */
-static size_t allocate_block_buffer_on_node(void *interface_, uint32_t dst_node)
+static ssize_t allocate_block_buffer_on_node(void *interface_, uint32_t dst_node)
 {
 	uintptr_t addr = 0;
 	unsigned fail = 0;
-	size_t allocated_memory;
+	ssize_t allocated_memory;
 
 #ifdef STARPU_USE_CUDA
 	cudaError_t status;
@@ -342,7 +342,7 @@ static size_t allocate_block_buffer_on_node(void *interface_, uint32_t dst_node)
 		dst_block->ldz = nx*ny;
 	} else {
 		/* allocation failed */
-		allocated_memory = 0;
+		allocated_memory = -ENOMEM;
 	}
 	
 	return allocated_memory;

+ 4 - 6
src/datawizard/interfaces/csr_interface.c

@@ -55,7 +55,7 @@ static const struct starpu_data_copy_methods csr_copy_data_methods_s = {
 };
 
 static void register_csr_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
-static size_t allocate_csr_buffer_on_node(void *interface_, uint32_t dst_node);
+static ssize_t allocate_csr_buffer_on_node(void *interface_, uint32_t dst_node);
 static void free_csr_buffer_on_node(void *interface, uint32_t node);
 static size_t csr_interface_get_size(starpu_data_handle handle);
 static int csr_compare(void *interface_a, void *interface_b);
@@ -222,11 +222,11 @@ static size_t csr_interface_get_size(starpu_data_handle handle)
 /* memory allocation/deallocation primitives for the BLAS interface */
 
 /* returns the size of the allocated area */
-static size_t allocate_csr_buffer_on_node(void *interface_, uint32_t dst_node)
+static ssize_t allocate_csr_buffer_on_node(void *interface_, uint32_t dst_node)
 {
 	uintptr_t addr_nzval;
 	uint32_t *addr_colind, *addr_rowptr;
-	size_t allocated_memory;
+	ssize_t allocated_memory;
 
 	/* we need the 3 arrays to be allocated */
 	starpu_csr_interface_t *interface = interface_;
@@ -343,9 +343,7 @@ fail_colind:
 fail_nzval:
 
 	/* allocation failed */
-	allocated_memory = 0;
-
-	return allocated_memory;
+	return -ENOMEM;
 }
 
 static void free_csr_buffer_on_node(void *interface, uint32_t node)

+ 4 - 4
src/datawizard/interfaces/matrix_interface.c

@@ -61,7 +61,7 @@ static const struct starpu_data_copy_methods matrix_copy_data_methods_s = {
 };
 
 static void register_matrix_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
-static size_t allocate_matrix_buffer_on_node(void *interface_, uint32_t dst_node);
+static ssize_t allocate_matrix_buffer_on_node(void *interface_, uint32_t dst_node);
 static void free_matrix_buffer_on_node(void *interface, uint32_t node);
 static size_t matrix_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_matrix_interface_crc32(starpu_data_handle handle);
@@ -241,11 +241,11 @@ size_t starpu_matrix_get_elemsize(starpu_data_handle handle)
 /* memory allocation/deallocation primitives for the matrix interface */
 
 /* returns the size of the allocated area */
-static size_t allocate_matrix_buffer_on_node(void *interface_, uint32_t dst_node)
+static ssize_t allocate_matrix_buffer_on_node(void *interface_, uint32_t dst_node)
 {
 	uintptr_t addr = 0;
 	unsigned fail = 0;
-	size_t allocated_memory;
+	ssize_t allocated_memory;
 
 #ifdef STARPU_USE_CUDA
 	cudaError_t status;
@@ -310,7 +310,7 @@ static size_t allocate_matrix_buffer_on_node(void *interface_, uint32_t dst_node
 		interface->ld = ld;
 	} else {
 		/* allocation failed */
-		allocated_memory = 0;
+		allocated_memory = -ENOMEM;
 	}
 	
 	return allocated_memory;

+ 4 - 4
src/datawizard/interfaces/variable_interface.c

@@ -62,7 +62,7 @@ static const struct starpu_data_copy_methods variable_copy_data_methods_s = {
 };
 
 static void register_variable_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
-static size_t allocate_variable_buffer_on_node(void *interface_, uint32_t dst_node);
+static ssize_t allocate_variable_buffer_on_node(void *interface_, uint32_t dst_node);
 static void free_variable_buffer_on_node(void *interface, uint32_t node);
 static size_t variable_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_variable_interface_crc32(starpu_data_handle handle);
@@ -178,13 +178,13 @@ size_t starpu_variable_get_elemsize(starpu_data_handle handle)
 /* memory allocation/deallocation primitives for the variable interface */
 
 /* returns the size of the allocated area */
-static size_t allocate_variable_buffer_on_node(void *interface_, uint32_t dst_node)
+static ssize_t allocate_variable_buffer_on_node(void *interface_, uint32_t dst_node)
 {
 	starpu_variable_interface_t *interface = interface_;
 
 	unsigned fail = 0;
 	uintptr_t addr = 0;
-	size_t allocated_memory;
+	ssize_t allocated_memory;
 
 	size_t elemsize = interface->elemsize;
 
@@ -230,7 +230,7 @@ static size_t allocate_variable_buffer_on_node(void *interface_, uint32_t dst_no
 	}
 
 	if (fail)
-		return 0;
+		return -ENOMEM;
 
 	/* allocation succeeded */
 	allocated_memory = elemsize;

+ 4 - 4
src/datawizard/interfaces/vector_interface.c

@@ -61,7 +61,7 @@ static const struct starpu_data_copy_methods vector_copy_data_methods_s = {
 };
 
 static void register_vector_handle(starpu_data_handle handle, uint32_t home_node, void *interface);
-static size_t allocate_vector_buffer_on_node(void *interface_, uint32_t dst_node);
+static ssize_t allocate_vector_buffer_on_node(void *interface_, uint32_t dst_node);
 static void free_vector_buffer_on_node(void *interface, uint32_t node);
 static size_t vector_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_vector_interface_crc32(starpu_data_handle handle);
@@ -208,13 +208,13 @@ size_t starpu_vector_get_elemsize(starpu_data_handle handle)
 /* memory allocation/deallocation primitives for the vector interface */
 
 /* returns the size of the allocated area */
-static size_t allocate_vector_buffer_on_node(void *interface_, uint32_t dst_node)
+static ssize_t allocate_vector_buffer_on_node(void *interface_, uint32_t dst_node)
 {
 	starpu_vector_interface_t *interface = interface_;
 
 	unsigned fail = 0;
 	uintptr_t addr = 0;
-	size_t allocated_memory;
+	ssize_t allocated_memory;
 
 	uint32_t nx = interface->nx;
 	size_t elemsize = interface->elemsize;
@@ -261,7 +261,7 @@ static size_t allocate_vector_buffer_on_node(void *interface_, uint32_t dst_node
 	}
 
 	if (fail)
-		return 0;
+		return -ENOMEM;
 
 	/* allocation succeeded */
 	allocated_memory = nx*elemsize;

+ 7 - 7
src/datawizard/memalloc.c

@@ -658,10 +658,10 @@ static size_t free_memory_on_node(starpu_mem_chunk_t mc, uint32_t node)
  *
  */
 
-size_t _starpu_allocate_interface(starpu_data_handle handle, void *interface, uint32_t dst_node)
+ssize_t _starpu_allocate_interface(starpu_data_handle handle, void *interface, uint32_t dst_node)
 {
 	unsigned attempts = 0;
-	size_t allocated_memory;
+	ssize_t allocated_memory;
 
 	_starpu_data_allocation_inc_stats(dst_node);
 
@@ -673,7 +673,7 @@ size_t _starpu_allocate_interface(starpu_data_handle handle, void *interface, ui
 	if (try_to_find_reusable_mem_chunk(dst_node, handle, footprint))
 	{
 		_starpu_allocation_cache_hit(dst_node);
-		return 0;
+		return -ENOMEM;
 	}
 	STARPU_TRACE_END_ALLOC_REUSE(dst_node);
 #endif
@@ -686,7 +686,7 @@ size_t _starpu_allocate_interface(starpu_data_handle handle, void *interface, ui
 		allocated_memory = handle->ops->allocate_data_on_node(interface, dst_node);
 		STARPU_TRACE_END_ALLOC(dst_node);
 
-		if (!allocated_memory) {
+		if (allocated_memory == -ENOMEM) {
 			/* XXX perhaps we should find the proper granularity 
 			 * not to waste our cache all the time */
 			size_t data_size = _starpu_data_get_size(handle);
@@ -696,14 +696,14 @@ size_t _starpu_allocate_interface(starpu_data_handle handle, void *interface, ui
 			STARPU_TRACE_END_MEMRECLAIM(dst_node);
 		}
 		
-	} while(!allocated_memory && attempts++ < 2);
+	} while((allocated_memory == -ENOMEM) && attempts++ < 2);
 
 	return allocated_memory;
 }
 
 int _starpu_allocate_memory_on_node(starpu_data_handle handle, uint32_t dst_node, unsigned may_alloc)
 {
-	size_t allocated_memory;
+	ssize_t allocated_memory;
 
 	STARPU_ASSERT(handle);
 
@@ -718,7 +718,7 @@ int _starpu_allocate_memory_on_node(starpu_data_handle handle, uint32_t dst_node
 	allocated_memory = _starpu_allocate_interface(handle, interface, dst_node);
 
 	/* perhaps we could really not handle that capacity misses */
-	if (!allocated_memory)
+	if (allocated_memory == -ENOMEM)
 		return ENOMEM;
 
 	register_mem_chunk(handle, dst_node, allocated_memory, 1);

+ 1 - 1
src/datawizard/memalloc.h

@@ -46,7 +46,7 @@ LIST_TYPE(starpu_mem_chunk,
 void _starpu_init_mem_chunk_lists(void);
 void _starpu_deinit_mem_chunk_lists(void);
 void _starpu_request_mem_chunk_removal(starpu_data_handle handle, unsigned node);
-size_t _starpu_allocate_interface(starpu_data_handle handle, void *interface, uint32_t dst_node);
+ssize_t _starpu_allocate_interface(starpu_data_handle handle, void *interface, uint32_t dst_node);
 int _starpu_allocate_memory_on_node(starpu_data_handle handle, uint32_t dst_node, unsigned may_alloc);
 size_t _starpu_free_all_automatically_allocated_buffers(uint32_t node);