浏览代码

Make sure users use starpu_conf_init to initialize starpu_conf. Fix some code

Samuel Thibault 13 年之前
父节点
当前提交
1a83af1be4

+ 1 - 1
doc/chapters/basic-api.texi

@@ -38,7 +38,7 @@ indicates that no worker was available (so that StarPU was not initialized).
 
 @deftp {Data Type} {struct starpu_conf}
 This structure is passed to the @code{starpu_init} function in order
-to configure StarPU.
+to configure StarPU. It has to be initialized with @code{starpu_conf_init}.
 When the default value is used, StarPU automatically selects the number of
 processing units and takes the default scheduling policy. The environment
 variables overwrite the equivalent parameters.

+ 0 - 4
doc/chapters/configuration.texi

@@ -210,10 +210,6 @@ is enabled when the required dependencies are found.
 * Misc::                        Miscellaneous and debug
 @end menu
 
-Note: the values given in @code{starpu_conf} structure passed when
-calling @code{starpu_init} will override the values of the environment
-variables.
-
 @node Workers
 @subsection Configuring workers
 

+ 7 - 7
examples/matvecmult/matvecmult.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2011  Université de Bordeaux 1
+ * Copyright (C) 2010, 2011-2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -126,12 +126,12 @@ int main(int argc, char **argv)
 {
 	struct starpu_codelet cl = {};
 
-	struct starpu_conf conf =
-	{
-		.ncpus = 0,
-		.ncuda = 0,
-                .nopencl = 1,
-	};
+	struct starpu_conf conf;
+	
+	starpu_conf_init(&conf);
+	conf.ncpus = 0;
+	conf.ncuda = 0;
+	conf.nopencl = 1;
 
         /* int width=1100; */
         /* int height=244021; */

+ 4 - 15
examples/scheduler/dummy_sched.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2011  Université de Bordeaux 1
+ * Copyright (C) 2010-2012  Université de Bordeaux 1
  * Copyright (C) 2010-2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -89,20 +89,6 @@ static struct starpu_sched_policy dummy_sched_policy =
 	.policy_description = "dummy scheduling strategy"
 };
 
-static struct starpu_conf conf =
-{
-	.sched_policy_name = NULL,
-	.sched_policy = &dummy_sched_policy,
-	.ncpus = -1,
-	.ncuda = -1,
-        .nopencl = -1,
-	.nspus = -1,
-	.use_explicit_workers_bindid = 0,
-	.use_explicit_workers_cuda_gpuid = 0,
-	.use_explicit_workers_opencl_gpuid = 0,
-	.calibrate = 0
-};
-
 static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
 {
 }
@@ -122,7 +108,10 @@ int main(int argc, char **argv)
 {
 	int ntasks = NTASKS;
 	int ret;
+	struct starpu_conf conf;
 
+	starpu_conf_init(&conf);
+	conf.sched_policy = &dummy_sched_policy,
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV)
 		return 77;

+ 4 - 1
include/starpu.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2011  Université de Bordeaux 1
+ * Copyright (C) 2009-2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -80,6 +80,9 @@ struct starpu_driver
 
 struct starpu_conf
 {
+	/* Will be initialized by starpu_conf_init */
+	int magic;
+
 	/* which scheduling policy should be used ? (NULL for default) */
 	const char *sched_policy_name;
 	struct starpu_sched_policy *sched_policy;

+ 5 - 0
src/core/workers.c

@@ -410,6 +410,7 @@ int starpu_conf_init(struct starpu_conf *conf)
 	if (!conf)
 		return -EINVAL;
 
+	conf->magic = 42;
 	conf->sched_policy_name = getenv("STARPU_SCHED");
 	conf->sched_policy = NULL;
 
@@ -546,6 +547,10 @@ int starpu_init(struct starpu_conf *user_conf)
 	}
 	else
 	{
+	     if (user_conf->magic != 42) {
+		fprintf(stderr, "starpu_conf structure needs to be initialized with starpu_conf_init\n");
+		return -EINVAL;
+	     }
 	     config.conf = user_conf;
 	     config.default_conf = 0;
 	}

+ 5 - 6
tests/datawizard/interfaces/bcsr/bcsr_interface.c

@@ -171,12 +171,11 @@ int
 main(void)
 {
 	data_interface_test_summary *summary;
-	struct starpu_conf conf =
-	{
-		.ncpus   = -1,
-		.ncuda   = 2,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+
+	conf.ncuda = 2;
+	conf.nopencl = 1;
 
 	if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
 		return STARPU_TEST_SKIPPED;

+ 4 - 6
tests/datawizard/interfaces/block/block_interface.c

@@ -133,12 +133,10 @@ int
 main(void)
 {
 	data_interface_test_summary *summary;
-	struct starpu_conf conf =
-	{
-		.ncpus   = -1,
-		.ncuda   = 2,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+	conf.ncuda = 2;
+	conf.nopencl = 1;
 
 	if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
 		goto enodev;

+ 5 - 6
tests/datawizard/interfaces/csr/csr_interface.c

@@ -141,12 +141,11 @@ int
 main(void)
 {
 	data_interface_test_summary *summary;
-	struct starpu_conf conf =
-	{
-		.ncpus   = -1,
-		.ncuda   = 2,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+
+	conf.ncuda = 2;
+	conf.nopencl = 1;
 
 	if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
 		goto enodev;

+ 4 - 6
tests/datawizard/interfaces/matrix/matrix_interface.c

@@ -116,12 +116,10 @@ int
 main(void)
 {
 	data_interface_test_summary *summary;
-	struct starpu_conf conf =
-	{
-		.ncpus   = -1,
-		.ncuda   = 2,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+	conf.ncuda = 2;
+	conf.nopencl = 1;
 
 	if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
 		goto enodev;

+ 5 - 6
tests/datawizard/interfaces/multiformat/advanced/multiformat_cuda_opencl.c

@@ -105,12 +105,11 @@ main(void)
 {
 #if defined(STARPU_USE_CUDA) && defined(STARPU_USE_OPENCL)
 	int ret;
-	struct starpu_conf conf =
-	{
-		.ncpus   = -1,
-		.ncuda   = 1,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+
+	conf.ncuda = 1;
+	conf.nopencl = 1;
 
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV)

+ 5 - 6
tests/datawizard/interfaces/multiformat/advanced/multiformat_data_release.c

@@ -123,12 +123,11 @@ main(void)
 {
 #ifdef STARPU_USE_CPU
 	int ret;
-	struct starpu_conf conf =
-	{
-		.ncpus = -1,
-		.ncuda = 1,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+
+	conf.ncuda = 1;
+	conf.nopencl = 1;
 	memset(&global_stats, 0, sizeof(global_stats));
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0) return STARPU_TEST_SKIPPED;

+ 5 - 6
tests/datawizard/interfaces/multiformat/advanced/multiformat_handle_conversion.c

@@ -203,12 +203,11 @@ main(void)
 {
 #ifdef STARPU_USE_CPU
 	int ret;
-	struct starpu_conf conf =
-	{
-		.ncpus   = -1,
-		.ncuda   = 2,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+
+	conf.ncuda = 2;
+	conf.nopencl = 1;
 
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;

+ 4 - 6
tests/datawizard/interfaces/multiformat/multiformat_interface.c

@@ -136,12 +136,10 @@ main(void)
 #ifdef STARPU_USE_CPU
 	int ret;
 	data_interface_test_summary *summary;
-	struct starpu_conf conf =
-	{
-		.ncpus   = -1,
-		.ncuda   = 2,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+	conf.ncuda = 2;
+	conf.nopencl = 1;
 
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0)

+ 5 - 6
tests/datawizard/interfaces/variable/variable_interface.c

@@ -93,12 +93,11 @@ main(void)
 	int ret;
 	data_interface_test_summary *summary;
 
-	struct starpu_conf conf =
-	{
-		.ncpus = -1,
-		.ncuda = 2,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+
+	conf.ncuda = 2;
+	conf.nopencl = 1;
 
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0)

+ 4 - 6
tests/datawizard/interfaces/vector/test_vector_interface.c

@@ -103,12 +103,10 @@ int
 main(void)
 {
 	data_interface_test_summary *summary;
-	struct starpu_conf conf =
-	{
-		.ncpus   = -1,
-		.ncuda   = 2,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+	conf.ncuda = 2;
+	conf.nopencl = 1;
 
 	if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
 		goto enodev;

+ 4 - 6
tests/datawizard/interfaces/void/void_interface.c

@@ -59,12 +59,10 @@ int
 main(void)
 {
 	data_interface_test_summary *summary;
-	struct starpu_conf conf =
-	{
-		.ncpus   = -1,
-		.ncuda   = 2,
-		.nopencl = 1
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+	conf.ncuda = 2;
+	conf.nopencl = 1;
 
 	if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
 		goto enodev;

+ 1 - 1
tests/errorcheck/invalid_tasks.c

@@ -48,7 +48,7 @@ int main(int argc, char **argv)
 	unsetenv("STARPU_NOPENCL");
 	unsetenv("STARPU_NCPUS");
 	struct starpu_conf conf;
-	memset(&conf, 0, sizeof(conf));
+	starpu_conf_init(&conf);
 	conf.ncpus = 1;
 
 	ret = starpu_init(&conf);

+ 7 - 13
tests/errorcheck/starpu_init_noworker.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009, 2010, 2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -43,18 +43,12 @@ int main(int argc, char **argv)
 	unset_env_variables();
 
 	/* We try to initialize StarPU without any worker */
-	struct starpu_conf conf =
-	{
-		.sched_policy_name = NULL, /* default */
-		.ncpus = 0,
-		.ncuda = 0,
-                .nopencl = 0,
-		.nspus = 0,
-		.use_explicit_workers_bindid = 0,
-		.use_explicit_workers_cuda_gpuid = 0,
-		.use_explicit_workers_opencl_gpuid = 0,
-		.calibrate = 0
-	};
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+	conf.ncpus = 0;
+	conf.ncuda = 0;
+	conf.nopencl = 0;
+	conf.nspus = 0;
 
 	/* starpu_init should return -ENODEV */
 	ret = starpu_init(&conf);

+ 7 - 17
tests/main/starpu_task_wait_for_all.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2011  Université de Bordeaux 1
+ * Copyright (C) 2010-2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -69,26 +69,13 @@ static int inject_one_task(void)
 	return ret;
 }
 
-static struct starpu_conf conf =
-{
-	.sched_policy_name = NULL,
-	.ncpus = -1,
-	.ncuda = -1,
-        .nopencl = -1,
-	.nspus = -1,
-	.use_explicit_workers_bindid = 0,
-	.use_explicit_workers_cuda_gpuid = 0,
-	.use_explicit_workers_opencl_gpuid = 0,
-	.calibrate = 0
-};
-
 static void usage(char **argv)
 {
 	FPRINTF(stderr, "%s [-i ntasks] [-p sched_policy] [-h]\n", argv[0]);
 	exit(-1);
 }
 
-static void parse_args(int argc, char **argv)
+static void parse_args(int argc, char **argv, struct starpu_conf *conf)
 {
 	int c;
 	while ((c = getopt(argc, argv, "i:p:h")) != -1)
@@ -98,7 +85,7 @@ static void parse_args(int argc, char **argv)
 			ntasks = atoi(optarg);
 			break;
 		case 'p':
-			conf.sched_policy_name = optarg;
+			conf->sched_policy_name = optarg;
 			break;
 		case 'h':
 			usage(argv);
@@ -113,8 +100,11 @@ int main(int argc, char **argv)
 	struct timeval start;
 	struct timeval end;
 	int ret;
+	struct starpu_conf conf;
+
+	starpu_conf_init(&conf);
 
-	parse_args(argc, argv);
+	parse_args(argc, argv, &conf);
 
 #ifdef STARPU_SLOW_MACHINE
 	ntasks /= 10;

+ 6 - 16
tests/microbenchs/async_tasks_overhead.c

@@ -76,26 +76,13 @@ static void init_gordon_kernel(void)
 //	STARPU_ASSERT(!ret);
 //}
 
-static struct starpu_conf conf =
-{
-	.sched_policy_name = NULL,
-	.ncpus = -1,
-	.ncuda = -1,
-        .nopencl = -1,
-	.nspus = -1,
-	.use_explicit_workers_bindid = 0,
-	.use_explicit_workers_cuda_gpuid = 0,
-	.use_explicit_workers_opencl_gpuid = 0,
-	.calibrate = 0
-};
-
 static void usage(char **argv)
 {
 	fprintf(stderr, "%s [-i ntasks] [-p sched_policy] [-h]\n", argv[0]);
 	exit(-1);
 }
 
-static void parse_args(int argc, char **argv)
+static void parse_args(int argc, char **argv, struct starpu_conf *conf)
 {
 	int c;
 	while ((c = getopt(argc, argv, "i:p:h")) != -1)
@@ -105,7 +92,7 @@ static void parse_args(int argc, char **argv)
 			ntasks = atoi(optarg);
 			break;
 		case 'p':
-			conf.sched_policy_name = optarg;
+			conf->sched_policy_name = optarg;
 			break;
 		case 'h':
 			usage(argv);
@@ -121,7 +108,10 @@ int main(int argc, char **argv)
 	struct timeval start;
 	struct timeval end;
 
-	parse_args(argc, argv);
+	struct starpu_conf conf;
+	starpu_conf_init(&conf);
+
+	parse_args(argc, argv, &conf);
 
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;

+ 5 - 13
tests/parallel_tasks/explicit_combined_worker.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010  Université de Bordeaux 1
+ * Copyright (C) 2010, 2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -57,18 +57,10 @@ int main(int argc, char **argv)
 	unsigned *v;
 	int ret;
 
-//      struct starpu_conf conf =
-//	{
-//                .sched_policy_name = "pheft",
-//                .ncpus = -1,
-//                .ncuda = -1,
-//                .nopencl = -1,
-//                .nspus = -1,
-//                .use_explicit_workers_bindid = 0,
-//                .use_explicit_workers_cuda_gpuid = 0,
-//                .use_explicit_workers_opencl_gpuid = 0,
-//                .calibrate = -1
-//        };
+//      struct starpu_conf conf;
+//      starpu_conf_init(&conf);
+//      conf.sched_policy_name = "pheft";
+//      conf.calibrate = 1;
 
 	ret = starpu_init(NULL);
 	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;

+ 4 - 12
tests/parallel_tasks/parallel_kernels.c

@@ -64,18 +64,10 @@ int main(int argc, char **argv)
 	starpu_data_handle_t v_handle;
 	unsigned *v;
 
-        struct starpu_conf conf =
-	{
-                .sched_policy_name = "pheft",
-                .ncpus = -1,
-                .ncuda = -1,
-                .nopencl = -1,
-                .nspus = -1,
-                .use_explicit_workers_bindid = 0,
-                .use_explicit_workers_cuda_gpuid = 0,
-                .use_explicit_workers_opencl_gpuid = 0,
-                .calibrate = 1
-        };
+        struct starpu_conf conf;
+	starpu_conf_init(&conf);
+	conf.sched_policy_name = "pheft";
+	conf.calibrate = 1;
 
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;

+ 4 - 12
tests/parallel_tasks/parallel_kernels_spmd.c

@@ -66,18 +66,10 @@ int main(int argc, char **argv)
 	starpu_data_handle_t v_handle;
 	unsigned *v;
 
-        struct starpu_conf conf =
-	{
-                .sched_policy_name = "pheft",
-                .ncpus = -1,
-                .ncuda = -1,
-                .nopencl = -1,
-                .nspus = -1,
-                .use_explicit_workers_bindid = 0,
-                .use_explicit_workers_cuda_gpuid = 0,
-                .use_explicit_workers_opencl_gpuid = 0,
-                .calibrate = 1
-        };
+        struct starpu_conf conf;
+	starpu_conf_init(&conf);
+	conf.sched_policy_name = "pheft";
+	conf.calibrate = 1;
 
 	ret = starpu_init(&conf);
 	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;