Преглед изворни кода

separate stdio and general disk functions + reduce warnings

Corentin Salingue пре 12 година
родитељ
комит
4ae966b5a4
6 измењених фајлова са 280 додато и 252 уклоњено
  1. 1 1
      include/starpu_disk.h
  2. 1 0
      src/Makefile.am
  3. 9 248
      src/core/disk.c
  4. 2 0
      src/core/disk.h
  5. 264 0
      src/core/diskOps/disk_stdio.c
  6. 3 3
      src/datawizard/coherency.c

+ 1 - 1
include/starpu_disk.h

@@ -32,7 +32,7 @@ struct disk_ops {
 	 void *  (*plug)   (void *parameter);
 	 void    (*unplug) (void *base);
 	  int    (*copy)   (void *base_src, void* obj_src, off_t offset_src,  void *base_dst, void* obj_dst, off_t offset_dst, size_t size);
-	 void    (*bandwidth) (void *base, unsigned node);
+	 void    (*bandwidth) (unsigned node);
 };
 
 

+ 1 - 0
src/Makefile.am

@@ -158,6 +158,7 @@ libstarpu_@STARPU_EFFECTIVE_VERSION@_la_SOURCES = 						\
 	core/dependencies/tags.c				\
 	core/dependencies/task_deps.c				\
 	core/dependencies/data_concurrency.c			\
+	core/diskOps/disk_stdio.c				\
 	core/perfmodel/perfmodel_history.c			\
 	core/perfmodel/perfmodel_bus.c				\
 	core/perfmodel/perfmodel.c				\

+ 9 - 248
src/core/disk.c

@@ -14,18 +14,20 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
 
-#include <stdlib.h>
-#include <stdio.h>
+#include <fcntl.h>
 #include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <time.h>
+
+#include <datawizard/memory_manager.h>
 #include <common/config.h>
-#include <core/workers.h>
 #include <core/debug.h>
+#include <core/disk.h>
+#include <core/workers.h>
 #include <core/perfmodel/perfmodel.h>
-#include <datawizard/memory_manager.h>
 
 #include <core/topology.h>
 #include <drivers/cuda/driver_cuda.h>
@@ -33,10 +35,6 @@
 #include <profiling/profiling.h>
 #include <common/uthash.h>
 
-#define SIZE	(1024*1024)
-#define NITER	64
-
-
 struct disk_register {
 	unsigned node;
 	void * base;
@@ -55,7 +53,7 @@ unsigned
 starpu_disk_register(struct disk_ops * func, void *parameter, size_t size)
 {
 
-	STARPU_ASSERT_MSG(size >= SIZE,"Minimum disk size is %u Bytes ! (Here %u)", (int) SIZE, (int) size);
+	STARPU_ASSERT_MSG(size >= SIZE_DISK_MIN,"Minimum disk size is %u Bytes ! (Here %u)", (int) SIZE_DISK_MIN, (int) size);
 	/* register disk */
 	unsigned memory_node = _starpu_memory_node_register(STARPU_DISK_RAM, 0);
 
@@ -68,7 +66,7 @@ starpu_disk_register(struct disk_ops * func, void *parameter, size_t size)
 	/* remember it */
 	add_disk_in_list(memory_node,func,base);
 
-	func->bandwidth(base,memory_node);
+	func->bandwidth(memory_node);
 	_starpu_memory_manager_set_global_memory_size(memory_node, size);
 	return memory_node;
 }
@@ -223,240 +221,3 @@ _starpu_is_same_kind_disk(unsigned node1, unsigned node2)
 	return 0;
 }
 
-/* ------------------- use STDIO to write on disk -------------------  */
-
-struct starpu_stdio_obj {
-	int descriptor;
-	FILE * file;
-	char * path;
-	double size;
-};
-
-
-/* allocation memory on disk */
-static void * 
-starpu_stdio_alloc (void *base, size_t size STARPU_ATTRIBUTE_UNUSED)
-{
-	
-	struct starpu_stdio_obj * obj = malloc(sizeof(struct starpu_stdio_obj));
-	STARPU_ASSERT(obj != NULL);
-	int id = -1;
-
-	/* create template for mkstemp */
-	unsigned int sizeBase = 16;
-	while(sizeBase < (strlen(base)+7))
-		sizeBase *= 2;
-
-	char * baseCpy = malloc(sizeBase*sizeof(char));
-	STARPU_ASSERT(baseCpy != NULL);
-	char * tmp = "XXXXXX";
-
-	strcpy(baseCpy, (char *) base);
-	strcat(baseCpy,tmp);
-
-	id = mkstemp(baseCpy);
-	STARPU_ASSERT_MSG(id >= 0, "Stdio allocation failed");
-
-	FILE * f = fdopen(id, "rb+");
-	STARPU_ASSERT_MSG(f != NULL, "Stdio allocation failed");
-
-	int val = ftruncate(id,size);
-	STARPU_ASSERT_MSG(val >= 0, "Stdio allocation failed");
-
-	obj->descriptor = id;
-	obj->file = f;
-	obj->path = baseCpy;
-	obj->size = size;
-
-	return (void *) obj;
-}
-
-
-/* free memory on disk */
-static void
-starpu_stdio_free (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, size_t size STARPU_ATTRIBUTE_UNUSED)
-{
-	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) obj;
-
-	unlink(tmp->path);
-	fclose(tmp->file);
-	close(tmp->descriptor);
-
-	free(tmp->path);
-	free(tmp);
-}
-
-
-/* open an existing memory on disk */
-static void * 
-starpu_stdio_open (void *base, void *pos, size_t size)
-{
-	struct starpu_stdio_obj * obj = malloc(sizeof(struct starpu_stdio_obj));
-	STARPU_ASSERT(obj != NULL);
-
-	/* create template */
-	unsigned int sizeBase = 16;
-	while(sizeBase < (strlen(base)+strlen(pos)+1))
-		sizeBase *= 2;
-	
-	char * baseCpy = malloc(sizeBase*sizeof(char));
-	STARPU_ASSERT(baseCpy != NULL);
-	strcpy(baseCpy,(char *) base);
-	strcat(baseCpy,(char *) pos);
-
-	int id = open(baseCpy, O_RDONLY);
-	STARPU_ASSERT_MSG(id >= 0, "Unistd open failed");
-
-	FILE * f = fdopen(id,"rb+");
-	STARPU_ASSERT_MSG(f != NULL, "Unistd open failed");
-
-	obj->descriptor = id;
-	obj->file = f;
-	obj->path = baseCpy;
-	obj->size = size;
-
-	return (void *) obj;
-	
-}
-
-
-/* free memory without delete it */
-static void 
-starpu_stdio_close (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, size_t size STARPU_ATTRIBUTE_UNUSED)
-{
-	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) obj;
-
-	fclose(tmp->file);
-	close(tmp->descriptor);
-	free(tmp->path);
-	free(tmp);	
-}
-
-
-/* read the memory disk */
-static ssize_t 
-starpu_stdio_read (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, void *buf, off_t offset, size_t size)
-{
-	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) obj;
-	
-	int res = fseek(tmp->file, offset, SEEK_SET); 
-	STARPU_ASSERT_MSG(res == 0, "Stdio read failed");
-
-	ssize_t nb = fread (buf, 1, size, tmp->file);
-	return nb;
-}
-
-
-/* write on the memory disk */
-static ssize_t 
-starpu_stdio_write (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, const void *buf, off_t offset, size_t size)
-{
-	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) obj;
-
-	int res = fseek(tmp->file, offset, SEEK_SET); 
-	STARPU_ASSERT_MSG(res == 0, "Stdio write failed");
-
-	ssize_t nb = fwrite (buf, 1, size, tmp->file);
-
-	return nb;
-}
-
-
-/* create a new copy of parameter == base */
-static void * 
-starpu_stdio_plug (void *parameter)
-{
-	char * tmp = malloc(sizeof(char)*(strlen(parameter)+1));
-	STARPU_ASSERT(tmp != NULL);
-	strcpy(tmp,(char *) parameter);
-	return (void *) tmp;	
-}
-
-
-/* free memory allocated for the base */
-static void
-starpu_stdio_unplug (void *base)
-{
-	free(base);
-}
-
-
-static void
-get_stdio_bandwidth_between_disk_and_main_ram(void * base, unsigned node)
-{
-
-	unsigned iter;
-	double timing_slowness, timing_latency;
-	struct timeval start;
-	struct timeval end;
-	
-	srand (time (NULL)); 
-	int pos = get_location_with_node(node);
-	char * buf = malloc(SIZE*sizeof(char));
-	STARPU_ASSERT(buf != NULL);
-	
-	/* allocate memory */
-	void * mem = disk_register_list[pos]->functions->alloc(base, SIZE);
-	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) mem;
-
-	/* Measure upload slowness */
-	gettimeofday(&start, NULL);
-	for (iter = 0; iter < NITER; ++iter)
-	{
-		disk_register_list[pos]->functions->write(base, mem, buf, 0, SIZE);
-		/* clean cache memory */
-		int res = fflush (tmp->file);
-		STARPU_ASSERT_MSG(res == 0, "Slowness computation failed");
-
-		res = fsync(tmp->descriptor);
-		STARPU_ASSERT_MSG(res == 0, "Slowness computation failed");
-	}
-	gettimeofday(&end, NULL);
-	timing_slowness = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
-
-
-	/* free memory */
-	disk_register_list[pos]->functions->free(base, mem, SIZE);
-	free(buf);
-
-	mem = disk_register_list[pos]->functions->alloc(base, 2*SIZE);
-	tmp = (struct starpu_stdio_obj *) mem;
-	buf = malloc(sizeof(char));
-	STARPU_ASSERT(buf != NULL);
-
-	/* Measure latency */
-	gettimeofday(&start, NULL);
-	for (iter = 0; iter < NITER; ++iter)
-	{
-		disk_register_list[pos]->functions->write(base, mem, buf, rand() % ((2*SIZE)-1) +1 , 1);
-
-		int res = fflush (tmp->file);
-		STARPU_ASSERT_MSG(res == 0, "Latency computation failed");
-
-		res = fsync(tmp->descriptor);
-		STARPU_ASSERT_MSG(res == 0, "Latency computation failed");
-	}
-	gettimeofday(&end, NULL);
-	timing_latency = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
-
-	disk_register_list[pos]->functions->free(base, mem, SIZE);
-	free(buf);
-
-	_starpu_save_bandwidth_and_latency_disk((NITER/timing_slowness)*1000000, (NITER/timing_slowness)*1000000,
-					       timing_latency/NITER, timing_latency/NITER, node);
-}
-
-
-
-struct disk_ops write_on_file = {
-	.alloc = starpu_stdio_alloc,
-	.free = starpu_stdio_free,
-	.open = starpu_stdio_open,
-	.close = starpu_stdio_close,
-	.read = starpu_stdio_read,
-	.write = starpu_stdio_write,
-	.plug = starpu_stdio_plug,
-	.unplug = starpu_stdio_unplug,
-	.copy = NULL,
-	.bandwidth = get_stdio_bandwidth_between_disk_and_main_ram
-};

+ 2 - 0
src/core/disk.h

@@ -18,6 +18,8 @@
 #ifndef __DISK_H__
 #define __DISK_H__
 
+#define SIZE_DISK_MIN (1024*1024)
+
 /* interface to manipulate memory disk */
 void * _starpu_disk_alloc (unsigned node, size_t size);
 

+ 264 - 0
src/core/diskOps/disk_stdio.c

@@ -0,0 +1,264 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2013 Corentin Salingue
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+#include <starpu.h>
+#include <core/disk.h>
+#include <core/perfmodel/perfmodel.h>
+
+#define NITER	64
+
+/* ------------------- use STDIO to write on disk -------------------  */
+
+struct starpu_stdio_obj {
+	int descriptor;
+	FILE * file;
+	char * path;
+	double size;
+};
+
+
+/* allocation memory on disk */
+static void * 
+starpu_stdio_alloc (void *base, size_t size STARPU_ATTRIBUTE_UNUSED)
+{
+	
+	struct starpu_stdio_obj * obj = malloc(sizeof(struct starpu_stdio_obj));
+	STARPU_ASSERT(obj != NULL);
+	int id = -1;
+
+	/* create template for mkstemp */
+	unsigned int sizeBase = 16;
+	while(sizeBase < (strlen(base)+7))
+		sizeBase *= 2;
+
+	char * baseCpy = malloc(sizeBase*sizeof(char));
+	STARPU_ASSERT(baseCpy != NULL);
+	char * tmp = "XXXXXX";
+
+	strcpy(baseCpy, (char *) base);
+	strcat(baseCpy,tmp);
+
+	id = mkstemp(baseCpy);
+	STARPU_ASSERT_MSG(id >= 0, "Stdio allocation failed");
+
+	FILE * f = fdopen(id, "rb+");
+	STARPU_ASSERT_MSG(f != NULL, "Stdio allocation failed");
+
+	int val = ftruncate(id,size);
+	STARPU_ASSERT_MSG(val >= 0, "Stdio allocation failed");
+
+	obj->descriptor = id;
+	obj->file = f;
+	obj->path = baseCpy;
+	obj->size = size;
+
+	return (void *) obj;
+}
+
+
+/* free memory on disk */
+static void
+starpu_stdio_free (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, size_t size STARPU_ATTRIBUTE_UNUSED)
+{
+	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) obj;
+
+	unlink(tmp->path);
+	fclose(tmp->file);
+	close(tmp->descriptor);
+
+	free(tmp->path);
+	free(tmp);
+}
+
+
+/* open an existing memory on disk */
+static void * 
+starpu_stdio_open (void *base, void *pos, size_t size)
+{
+	struct starpu_stdio_obj * obj = malloc(sizeof(struct starpu_stdio_obj));
+	STARPU_ASSERT(obj != NULL);
+
+	/* create template */
+	unsigned int sizeBase = 16;
+	while(sizeBase < (strlen(base)+strlen(pos)+1))
+		sizeBase *= 2;
+	
+	char * baseCpy = malloc(sizeBase*sizeof(char));
+	STARPU_ASSERT(baseCpy != NULL);
+	strcpy(baseCpy,(char *) base);
+	strcat(baseCpy,(char *) pos);
+
+	int id = open(baseCpy, O_RDONLY);
+	STARPU_ASSERT_MSG(id >= 0, "Unistd open failed");
+
+	FILE * f = fdopen(id,"rb+");
+	STARPU_ASSERT_MSG(f != NULL, "Unistd open failed");
+
+	obj->descriptor = id;
+	obj->file = f;
+	obj->path = baseCpy;
+	obj->size = size;
+
+	return (void *) obj;
+	
+}
+
+
+/* free memory without delete it */
+static void 
+starpu_stdio_close (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, size_t size STARPU_ATTRIBUTE_UNUSED)
+{
+	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) obj;
+
+	fclose(tmp->file);
+	close(tmp->descriptor);
+	free(tmp->path);
+	free(tmp);	
+}
+
+
+/* read the memory disk */
+static ssize_t 
+starpu_stdio_read (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, void *buf, off_t offset, size_t size)
+{
+	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) obj;
+	
+	int res = fseek(tmp->file, offset, SEEK_SET); 
+	STARPU_ASSERT_MSG(res == 0, "Stdio read failed");
+
+	ssize_t nb = fread (buf, 1, size, tmp->file);
+	return nb;
+}
+
+
+/* write on the memory disk */
+static ssize_t 
+starpu_stdio_write (void *base STARPU_ATTRIBUTE_UNUSED, void *obj, const void *buf, off_t offset, size_t size)
+{
+	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) obj;
+
+	int res = fseek(tmp->file, offset, SEEK_SET); 
+	STARPU_ASSERT_MSG(res == 0, "Stdio write failed");
+
+	ssize_t nb = fwrite (buf, 1, size, tmp->file);
+
+	return nb;
+}
+
+
+/* create a new copy of parameter == base */
+static void * 
+starpu_stdio_plug (void *parameter)
+{
+	char * tmp = malloc(sizeof(char)*(strlen(parameter)+1));
+	STARPU_ASSERT(tmp != NULL);
+	strcpy(tmp,(char *) parameter);
+	return (void *) tmp;	
+}
+
+
+/* free memory allocated for the base */
+static void
+starpu_stdio_unplug (void *base)
+{
+	free(base);
+}
+
+
+static void
+get_stdio_bandwidth_between_disk_and_main_ram(unsigned node)
+{
+
+	unsigned iter;
+	double timing_slowness, timing_latency;
+	struct timeval start;
+	struct timeval end;
+	
+	srand (time (NULL)); 
+	char * buf = malloc(SIZE_DISK_MIN*sizeof(char));
+	STARPU_ASSERT(buf != NULL);
+	
+	/* allocate memory */
+	void * mem = _starpu_disk_alloc(node, SIZE_DISK_MIN);
+	struct starpu_stdio_obj * tmp = (struct starpu_stdio_obj *) mem;
+
+	/* Measure upload slowness */
+	gettimeofday(&start, NULL);
+	for (iter = 0; iter < NITER; ++iter)
+	{
+		_starpu_disk_write(node, mem, buf, 0, SIZE_DISK_MIN);
+		/* clean cache memory */
+		int res = fflush (tmp->file);
+		STARPU_ASSERT_MSG(res == 0, "Slowness computation failed");
+
+		res = fsync(tmp->descriptor);
+		STARPU_ASSERT_MSG(res == 0, "Slowness computation failed");
+	}
+	gettimeofday(&end, NULL);
+	timing_slowness = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
+
+
+	/* free memory */
+	_starpu_disk_free(node, mem, SIZE_DISK_MIN);
+	free(buf);
+
+	mem = _starpu_disk_alloc(node, SIZE_DISK_MIN);
+	tmp = (struct starpu_stdio_obj *) mem;
+	buf = malloc(sizeof(char));
+	STARPU_ASSERT(buf != NULL);
+
+	/* Measure latency */
+	gettimeofday(&start, NULL);
+	for (iter = 0; iter < NITER; ++iter)
+	{
+		_starpu_disk_write(node, mem, buf, rand() % (SIZE_DISK_MIN -1) , 1);
+
+		int res = fflush (tmp->file);
+		STARPU_ASSERT_MSG(res == 0, "Latency computation failed");
+
+		res = fsync(tmp->descriptor);
+		STARPU_ASSERT_MSG(res == 0, "Latency computation failed");
+	}
+	gettimeofday(&end, NULL);
+	timing_latency = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
+
+	_starpu_disk_free(node, mem, SIZE_DISK_MIN);
+	free(buf);
+
+	_starpu_save_bandwidth_and_latency_disk((NITER/timing_slowness)*1000000, (NITER/timing_slowness)*1000000,
+					       timing_latency/NITER, timing_latency/NITER, node);
+}
+
+
+
+struct disk_ops write_on_file = {
+	.alloc = starpu_stdio_alloc,
+	.free = starpu_stdio_free,
+	.open = starpu_stdio_open,
+	.close = starpu_stdio_close,
+	.read = starpu_stdio_read,
+	.write = starpu_stdio_write,
+	.plug = starpu_stdio_plug,
+	.unplug = starpu_stdio_unplug,
+	.copy = NULL,
+	.bandwidth = get_stdio_bandwidth_between_disk_and_main_ram
+};

+ 3 - 3
src/datawizard/coherency.c

@@ -87,9 +87,9 @@ unsigned _starpu_select_src_node(starpu_data_handle_t handle, unsigned destinati
 		/* Could estimate through cost, return that */
 		return src_node;
 	
-	unsigned i_ram = -1;
-	unsigned i_gpu = -1;
-	unsigned i_disk = -1;
+	int i_ram = -1;
+	int i_gpu = -1;
+	int i_disk = -1;
 	
 	/* Revert to dumb strategy: take RAM unless only a GPU has it */
 	for (i = 0; i < nnodes; i++)