Просмотр исходного кода

The data interface allocation method now directly takes a "void *interface"
argument instead of the handle.

Cédric Augonnet лет назад: 15
Родитель
Сommit
2a361c1284

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

@@ -60,7 +60,7 @@ static const struct starpu_copy_data_methods_s 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(starpu_data_handle handle, uint32_t dst_node);
+static size_t allocate_bcsr_buffer_on_node(void *interface, uint32_t dst_node);
 static void liberate_bcsr_buffer_on_node(void *interface, uint32_t node);
 static size_t bcsr_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_bcsr_interface_crc32(starpu_data_handle handle);
@@ -237,15 +237,14 @@ 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(starpu_data_handle handle, uint32_t dst_node)
+static size_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;
 
 	/* we need the 3 arrays to be allocated */
-	starpu_bcsr_interface_t *interface =
-		starpu_data_get_interface_on_node(handle, dst_node);
+	starpu_bcsr_interface_t *interface = interface_;
 
 	uint32_t nnz = interface->nnz;
 	uint32_t nrow = interface->nrow;

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

@@ -65,7 +65,7 @@ static const struct starpu_copy_data_methods_s 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(starpu_data_handle handle, uint32_t dst_node);
+static size_t allocate_block_buffer_on_node(void *interface_, uint32_t dst_node);
 static void liberate_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);
@@ -259,7 +259,7 @@ 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(starpu_data_handle handle, uint32_t dst_node)
+static size_t allocate_block_buffer_on_node(void *interface_, uint32_t dst_node)
 {
 	uintptr_t addr = 0;
 	unsigned fail = 0;
@@ -268,8 +268,7 @@ static size_t allocate_block_buffer_on_node(starpu_data_handle handle, uint32_t
 #ifdef STARPU_USE_CUDA
 	cudaError_t status;
 #endif
-	starpu_block_interface_t *dst_block =
-		starpu_data_get_interface_on_node(handle, dst_node);
+	starpu_block_interface_t *dst_block = interface_;
 
 	uint32_t nx = dst_block->nx;
 	uint32_t ny = dst_block->ny;

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

@@ -56,7 +56,7 @@ static const struct starpu_copy_data_methods_s 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(starpu_data_handle handle, uint32_t dst_node);
+static size_t allocate_csr_buffer_on_node(void *interface_, uint32_t dst_node);
 static void liberate_csr_buffer_on_node(void *interface, uint32_t node);
 static size_t csr_interface_get_size(starpu_data_handle handle);
 static uint32_t footprint_csr_interface_crc32(starpu_data_handle handle);
@@ -211,15 +211,14 @@ 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(starpu_data_handle handle, uint32_t dst_node)
+static size_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;
 
 	/* we need the 3 arrays to be allocated */
-	starpu_csr_interface_t *interface =
-		starpu_data_get_interface_on_node(handle, dst_node);
+	starpu_csr_interface_t *interface = interface_;
 
 	uint32_t nnz = interface->nnz;
 	uint32_t nrow = interface->nrow;

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

@@ -28,7 +28,7 @@
 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)(starpu_data_handle handle, uint32_t node);
+	size_t (*allocate_data_on_node)(void *interface, uint32_t node);
 	void (*liberate_data_on_node)(void *interface, uint32_t node);
 	const struct starpu_copy_data_methods_s *copy_methods;
 	size_t (*get_size)(starpu_data_handle handle);

+ 7 - 8
src/datawizard/interfaces/matrix_interface.c

@@ -68,7 +68,7 @@ static const struct starpu_copy_data_methods_s 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(starpu_data_handle handle, uint32_t dst_node);
+static size_t allocate_matrix_buffer_on_node(void *interface_, uint32_t dst_node);
 static void liberate_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);
@@ -95,7 +95,7 @@ struct starpu_data_interface_ops_t _starpu_interface_matrix_ops = {
 #ifdef STARPU_USE_GORDON
 static int convert_matrix_to_gordon(void *interface, uint64_t *ptr, gordon_strideSize_t *ss) 
 {
-	size_t elemsize = GET_BLAS_ELEMSIZE(interface);
+	size_t elemsize = GET_MATRIX_ELEMSIZE(interface);
 	uint32_t nx = STARPU_GET_MATRIX_NX(interface);
 	uint32_t ny = STARPU_GET_MATRIX_NY(interface);
 	uint32_t ld = STARPU_GET_MATRIX_LD(interface);
@@ -139,7 +139,7 @@ static void register_matrix_handle(starpu_data_handle handle, uint32_t home_node
 	}
 }
 
-/* declare a new data with the BLAS interface */
+/* declare a new data with the matrix interface */
 void starpu_matrix_data_register(starpu_data_handle *handleptr, uint32_t home_node,
 			uintptr_t ptr, uint32_t ld, uint32_t nx,
 			uint32_t ny, size_t elemsize)
@@ -232,10 +232,10 @@ size_t starpu_matrix_get_elemsize(starpu_data_handle handle)
 	return interface->elemsize;
 }
 
-/* memory allocation/deallocation primitives for the BLAS interface */
+/* memory allocation/deallocation primitives for the matrix interface */
 
 /* returns the size of the allocated area */
-static size_t allocate_matrix_buffer_on_node(starpu_data_handle handle, uint32_t dst_node)
+static size_t allocate_matrix_buffer_on_node(void *interface_, uint32_t dst_node)
 {
 	uintptr_t addr = 0;
 	unsigned fail = 0;
@@ -246,8 +246,7 @@ static size_t allocate_matrix_buffer_on_node(starpu_data_handle handle, uint32_t
 	size_t pitch;
 #endif
 
-	starpu_matrix_interface_t *interface =
-		starpu_data_get_interface_on_node(handle, dst_node);
+	starpu_matrix_interface_t *interface = interface_;
 
 	uint32_t nx = interface->nx;
 	uint32_t ny = interface->ny;
@@ -542,7 +541,7 @@ static int copy_opencl_to_ram(starpu_data_handle handle, uint32_t src_node, uint
 
 #endif
 
-/* as not all platform easily have a BLAS lib installed ... */
+/* as not all platform easily have a  lib installed ... */
 static int dummy_copy_ram_to_ram(starpu_data_handle handle, uint32_t src_node, uint32_t dst_node)
 {
 	starpu_matrix_interface_t *src_matrix;

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

@@ -68,7 +68,7 @@ static const struct starpu_copy_data_methods_s 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(starpu_data_handle handle, uint32_t dst_node);
+static size_t allocate_variable_buffer_on_node(void *interface_, uint32_t dst_node);
 static void liberate_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);
@@ -173,10 +173,9 @@ size_t starpu_get_variable_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(starpu_data_handle handle, uint32_t dst_node)
+static size_t allocate_variable_buffer_on_node(void *interface_, uint32_t dst_node)
 {
-	starpu_variable_interface_t *interface =
-		starpu_data_get_interface_on_node(handle, dst_node);
+	starpu_variable_interface_t *interface = interface_;
 
 	unsigned fail = 0;
 	uintptr_t addr = 0;

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

@@ -67,7 +67,7 @@ static const struct starpu_copy_data_methods_s 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(starpu_data_handle handle, uint32_t dst_node);
+static size_t allocate_vector_buffer_on_node(void *interface_, uint32_t dst_node);
 static void liberate_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);
@@ -202,10 +202,9 @@ 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(starpu_data_handle handle, uint32_t dst_node)
+static size_t allocate_vector_buffer_on_node(void *interface_, uint32_t dst_node)
 {
-	starpu_vector_interface_t *interface =
-		starpu_data_get_interface_on_node(handle, dst_node);
+	starpu_vector_interface_t *interface = interface_;
 
 	unsigned fail = 0;
 	uintptr_t addr = 0;

+ 27 - 17
src/datawizard/memalloc.c

@@ -587,20 +587,12 @@ static size_t liberate_memory_on_node(starpu_mem_chunk_t mc, uint32_t node)
  *	not referenced (or part of those).
  *
  */
-int _starpu_allocate_memory_on_node(starpu_data_handle handle, uint32_t dst_node, unsigned may_alloc)
+
+static size_t _starpu_allocate_interface(starpu_data_handle handle, void *interface, uint32_t dst_node)
 {
 	unsigned attempts = 0;
 	size_t allocated_memory;
 
-	STARPU_ASSERT(handle);
-
-	/* A buffer is already allocated on the node */
-	if (handle->per_node[dst_node].allocated)
-		return 0;
-
-	if (!may_alloc)
-		return ENOMEM;
-
 	_starpu_data_allocation_inc_stats(dst_node);
 
 #ifdef STARPU_USE_ALLOCATION_CACHE
@@ -621,7 +613,7 @@ int _starpu_allocate_memory_on_node(starpu_data_handle handle, uint32_t dst_node
 		STARPU_ASSERT(handle->ops->allocate_data_on_node);
 
 		STARPU_TRACE_START_ALLOC(dst_node);
-		allocated_memory = handle->ops->allocate_data_on_node(handle, dst_node);
+		allocated_memory = handle->ops->allocate_data_on_node(interface, dst_node);
 		STARPU_TRACE_END_ALLOC(dst_node);
 
 		if (!allocated_memory) {
@@ -638,18 +630,36 @@ int _starpu_allocate_memory_on_node(starpu_data_handle handle, uint32_t dst_node
 	} while(!allocated_memory && attempts++ < 2);
 
 	/* perhaps we could really not handle that capacity misses */
-	if (!allocated_memory)
-		goto nomem;
+	if (allocated_memory)
+		register_mem_chunk(handle, dst_node, allocated_memory, 1);
 
-	register_mem_chunk(handle, dst_node, allocated_memory, 1);
+	return allocated_memory;
+}
+
+int _starpu_allocate_memory_on_node(starpu_data_handle handle, uint32_t dst_node, unsigned may_alloc)
+{
+	size_t allocated_memory;
+
+	STARPU_ASSERT(handle);
+
+	/* A buffer is already allocated on the node */
+	if (handle->per_node[dst_node].allocated)
+		return 0;
+
+	if (!may_alloc)
+		return ENOMEM;
+
+	void *interface = starpu_data_get_interface_on_node(handle, dst_node);
+	allocated_memory = _starpu_allocate_interface(handle, interface, dst_node);
+
+	/* perhaps we could really not handle that capacity misses */
+	if (!allocated_memory)
+		return ENOMEM;
 
 	handle->per_node[dst_node].allocated = 1;
 	handle->per_node[dst_node].automatically_allocated = 1;
 
 	return 0;
-nomem:
-	STARPU_ASSERT(!allocated_memory);
-	return -ENOMEM;
 }
 
 unsigned starpu_data_test_if_allocated_on_node(starpu_data_handle handle, uint32_t memory_node)