瀏覽代碼

fix bugs detected by coverity

Nathalie Furmento 9 年之前
父節點
當前提交
94d626f9e1

+ 3 - 1
src/core/perfmodel/perfmodel.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2016  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016  CNRS
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -51,6 +51,8 @@ unsigned _starpu_get_calibrate_flag(void)
 
 struct starpu_perfmodel_arch* starpu_worker_get_perf_archtype(int workerid, unsigned sched_ctx_id)
 {
+	STARPU_ASSERT(workerid>=0);
+
 	if(sched_ctx_id != STARPU_NMAX_SCHED_CTXS)
 	{
 		unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);

+ 20 - 26
src/core/perfmodel/perfmodel_history.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2016  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016  CNRS
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -658,6 +658,7 @@ void _starpu_perfmodel_realloc(struct starpu_perfmodel *model, int nb)
 	int i;
 
 	STARPU_ASSERT(nb > model->state->ncombs_set);
+	STARPU_ASSERT((size_t) nb < SSIZE_MAX / sizeof(struct starpu_perfmodel_per_arch*));
 	model->state->per_arch = (struct starpu_perfmodel_per_arch**) realloc(model->state->per_arch, nb*sizeof(struct starpu_perfmodel_per_arch*));
 	model->state->per_arch_is_set = (int**) realloc(model->state->per_arch_is_set, nb*sizeof(int*));
 	model->state->nimpls = (int *)realloc(model->state->nimpls, nb*sizeof(int));
@@ -949,41 +950,34 @@ void _starpu_load_history_based_model(struct starpu_perfmodel *model, unsigned s
 
 		unsigned calibrate_flag = _starpu_get_calibrate_flag();
 		model->benchmarking = calibrate_flag;
+		model->is_loaded = 1;
 
-		/* try to open an existing file and load it */
-		int res;
-		res = access(path, F_OK);
-		if (res == 0)
+		if (calibrate_flag == 2)
 		{
-			if (calibrate_flag == 2)
-			{
-				/* The user specified that the performance model should
-				 * be overwritten, so we don't load the existing file !
-				 * */
-				_STARPU_DEBUG("Overwrite existing file\n");
-			}
-			else
+			/* The user specified that the performance model should
+			 * be overwritten, so we don't load the existing file !
+			 * */
+			_STARPU_DEBUG("Overwrite existing file\n");
+		}
+		else
+		{
+			/* We try to load the file */
+			FILE *f;
+			f = fopen(path, "r");
+			if (f)
 			{
-				/* We load the available file */
-				_STARPU_DEBUG("File exists\n");
-				FILE *f;
-				f = fopen(path, "r");
-				STARPU_ASSERT(f);
-
 				_starpu_frdlock(f);
 				parse_model_file(f, model, scan_history);
 				_starpu_frdunlock(f);
-
 				fclose(f);
+				_STARPU_DEBUG("Performance model file %s for model %s is loaded\n", path, model->symbol);
+			}
+			else
+			{
+				_STARPU_DEBUG("Performance model file %s does not exist or is not readable\n", path);
 			}
-			_STARPU_DEBUG("Performance model file %s for model %s is loaded\n", path, model->symbol);
-		}
-		else
-		{
-			_STARPU_DEBUG("Performance model file %s does not exist\n", path);
 		}
 
-		model->is_loaded = 1;
 	}
 	STARPU_PTHREAD_RWLOCK_UNLOCK(&model->state->model_rwlock);
 

+ 2 - 1
src/core/topology.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2009-2016  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015 CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 CNRS
  * Copyright (C) 2011  INRIA
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -948,6 +948,7 @@ _starpu_init_machine_config(struct _starpu_machine_config *config, int no_mp_con
 	int nworker_per_cuda = starpu_get_env_number_default("STARPU_NWORKER_PER_CUDA", 1);
 
 	STARPU_ASSERT_MSG(nworker_per_cuda > 0, "STARPU_NWORKER_PER_CUDA has to be > 0");
+	STARPU_ASSERT_MSG(nworker_per_cuda < STARPU_NMAXWORKERS, "STARPU_NWORKER_PER_CUDA (%d) cannot be higher than STARPU_NMAXWORKERS (%d)\n", nworker_per_cuda, STARPU_NMAXWORKERS);
 
 #ifndef STARPU_NON_BLOCKING_DRIVERS
 	if (nworker_per_cuda > 1)

+ 4 - 4
src/core/workers.h

@@ -105,17 +105,17 @@ LIST_TYPE(_starpu_worker,
 
 	unsigned has_prev_init; /* had already been inited in another ctx */
 
-	unsigned removed_from_ctx[STARPU_NMAX_SCHED_CTXS];
+	unsigned removed_from_ctx[STARPU_NMAX_SCHED_CTXS+1];
 
 	unsigned spinning_backoff ; /* number of cycles to pause when spinning  */
 
 
 	/* indicate whether the workers shares tasks lists with other workers*/
 	/* in this case when removing him from a context it disapears instantly */
-	unsigned shares_tasks_lists[STARPU_NMAX_SCHED_CTXS];
+	unsigned shares_tasks_lists[STARPU_NMAX_SCHED_CTXS+1];
 
         /* boolean to chose the next ctx a worker will pop into */
-	unsigned poped_in_ctx[STARPU_NMAX_SCHED_CTXS];	  
+	unsigned poped_in_ctx[STARPU_NMAX_SCHED_CTXS+1];
 
        /* boolean indicating at which moment we checked all ctxs and change phase for the booleab poped_in_ctx*/
        /* one for each of the 2 priorities*/
@@ -348,7 +348,7 @@ struct _starpu_machine_config
 	int pause_depth;
 
 	/* all the sched ctx of the current instance of starpu */
-	struct _starpu_sched_ctx sched_ctxs[STARPU_NMAX_SCHED_CTXS];
+	struct _starpu_sched_ctx sched_ctxs[STARPU_NMAX_SCHED_CTXS+1];
 
 	/* this flag is set until the application is finished submitting tasks */
 	unsigned submitting;

+ 2 - 1
src/datawizard/coherency.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures. *
  * Copyright (C) 2009-2016  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016  CNRS
  * Copyright (C) 2014  INRIA
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -345,6 +345,7 @@ static int determine_request_path(starpu_data_handle_t handle,
 		/* We need an intermediate hop to implement data staging
 		 * through main memory. */
 		STARPU_ASSERT(max_len >= 2);
+		STARPU_ASSERT(src_node >= 0);
 
 		/* GPU -> RAM */
 		src_nodes[0] = src_node;

+ 4 - 5
src/util/starpu_clusters_create.c

@@ -572,23 +572,22 @@ int _starpu_cluster_topology(hwloc_obj_type_t cluster_level,
 void _starpu_cluster_group(hwloc_obj_type_t cluster_level,
 			   struct starpu_cluster_machine *machine)
 {
-	unsigned nb_objects;
-	unsigned i;
+	int nb_objects;
+	int i;
 	struct _starpu_cluster_group *group = NULL;
 
 	if (machine->groups == NULL)
 		machine->groups = _starpu_cluster_group_list_new();
 
 	nb_objects = hwloc_get_nbobjs_by_type(machine->topology, cluster_level);
-	if (nb_objects == 0)
+	if (nb_objects <= 0)
 		return;
 	/* XXX: handle nb_objects == -1 */
 
 	group = _starpu_cluster_group_list_begin(machine->groups);
 	for (i = 0 ; i < nb_objects ; i++)
 	{
-		hwloc_obj_t cluster_obj = hwloc_get_obj_by_type(machine->topology,
-								cluster_level, i);
+		hwloc_obj_t cluster_obj = hwloc_get_obj_by_type(machine->topology, cluster_level, i);
 
 		if (group == NULL)
 		{