Sfoglia il codice sorgente

fix bugs detected by coverity

Nathalie Furmento 9 anni fa
parent
commit
d476c09ccf

+ 1 - 1
examples/basic_examples/multiformat_conversion_codelets_opencl.c

@@ -31,7 +31,7 @@ void cpu_to_opencl_opencl_func(void *buffers[], void *args)
 	cl_mem src = (cl_mem) STARPU_MULTIFORMAT_GET_CPU_PTR(buffers[0]);
 	cl_mem dst = (cl_mem) STARPU_MULTIFORMAT_GET_OPENCL_PTR(buffers[0]);
 
-	id = starpu_worker_get_id();
+	id = starpu_worker_get_id_check();
 	devid = starpu_worker_get_devid(id);
 
 	err = starpu_opencl_load_kernel(&kernel,

+ 1 - 1
examples/incrementer/incrementer_kernels_opencl.c

@@ -27,7 +27,7 @@ void opencl_codelet(void *descr[], void *_args)
 	cl_command_queue queue;
 	int id, devid, err;
 
-        id = starpu_worker_get_id();
+        id = starpu_worker_get_id_check();
         devid = starpu_worker_get_devid(id);
 
 	err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_program, "incrementer", devid);

+ 5 - 2
examples/mandelbrot/mandelbrot.c

@@ -257,11 +257,13 @@ static void compute_block_opencl(void *descr[], void *cl_arg)
 	cl_kernel kernel;
 	cl_command_queue queue;
 	cl_event event;
+	cl_int err;
 
 	int id = starpu_worker_get_id_check();
 	int devid = starpu_worker_get_devid(id);
 
-	starpu_opencl_load_kernel(&kernel, &queue, &opencl_programs, "mandelbrot_kernel", devid);
+	err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_programs, "mandelbrot_kernel", devid);
+	if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
 
 	clSetKernelArg(kernel, 0, sizeof(data), &data);
 	clSetKernelArg(kernel, 1, sizeof(leftX), &leftX);
@@ -276,7 +278,8 @@ static void compute_block_opencl(void *descr[], void *cl_arg)
 	unsigned dim = 16;
 	size_t local[2] = {dim, 1};
 	size_t global[2] = {width, block_size};
-	clEnqueueNDRangeKernel(queue, kernel, 2, NULL, global, local, 0, NULL, NULL);
+	err = clEnqueueNDRangeKernel(queue, kernel, 2, NULL, global, local, 0, NULL, NULL);
+	if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
 	starpu_opencl_release_kernel(kernel);
 }
 #endif

+ 10 - 10
examples/sched_ctx/dummy_sched_with_ctx.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2015  Université de Bordeaux
- * Copyright (C) 2010-2013  CNRS
+ * Copyright (C) 2010-2013, 2016  CNRS
  *
  * 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
@@ -37,7 +37,7 @@ static void init_dummy_sched(unsigned sched_ctx_id)
 
 	starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)data);
 
-	starpu_pthread_mutex_init(&data->policy_mutex, NULL);
+	STARPU_PTHREAD_MUTEX_INIT(&data->policy_mutex, NULL);
 	FPRINTF(stderr, "Initialising Dummy scheduler\n");
 }
 
@@ -47,7 +47,7 @@ static void deinit_dummy_sched(unsigned sched_ctx_id)
 
 	STARPU_ASSERT(starpu_task_list_empty(&data->sched_list));
 
-	starpu_pthread_mutex_destroy(&data->policy_mutex);
+	STARPU_PTHREAD_MUTEX_DESTROY(&data->policy_mutex);
 
 	free(data);
 
@@ -65,12 +65,12 @@ static int push_task_dummy(struct starpu_task *task)
 
 	/* lock all workers when pushing tasks on a list where all
 	   of them would pop for tasks */
-        starpu_pthread_mutex_lock(&data->policy_mutex);
+        STARPU_PTHREAD_MUTEX_LOCK(&data->policy_mutex);
 
 	starpu_task_list_push_front(&data->sched_list, task);
 
 	starpu_push_task_end(task);
-	starpu_pthread_mutex_unlock(&data->policy_mutex);
+	STARPU_PTHREAD_MUTEX_UNLOCK(&data->policy_mutex);
 
 
         /*if there are no tasks block */
@@ -87,9 +87,9 @@ static int push_task_dummy(struct starpu_task *task)
 		starpu_pthread_mutex_t *sched_mutex;
                 starpu_pthread_cond_t *sched_cond;
                 starpu_worker_get_sched_condition(worker, &sched_mutex, &sched_cond);
-		starpu_pthread_mutex_lock(sched_mutex);
-                starpu_pthread_cond_signal(sched_cond);
-                starpu_pthread_mutex_unlock(sched_mutex);
+		STARPU_PTHREAD_MUTEX_LOCK(sched_mutex);
+                STARPU_PTHREAD_COND_SIGNAL(sched_cond);
+                STARPU_PTHREAD_MUTEX_UNLOCK(sched_mutex);
         }
 
 	return 0;
@@ -104,9 +104,9 @@ static struct starpu_task *pop_task_dummy(unsigned sched_ctx_id)
 	 * the calling worker. So we just take the head of the list and give it
 	 * to the worker. */
 	struct dummy_sched_data *data = (struct dummy_sched_data*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
-	starpu_pthread_mutex_lock(&data->policy_mutex);
+	STARPU_PTHREAD_MUTEX_LOCK(&data->policy_mutex);
 	struct starpu_task *task = starpu_task_list_pop_back(&data->sched_list);
-	starpu_pthread_mutex_unlock(&data->policy_mutex);
+	STARPU_PTHREAD_MUTEX_UNLOCK(&data->policy_mutex);
 	return task;
 }
 

+ 1 - 3
examples/sched_ctx/nested_sched_ctxs.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2015  Université de Bordeaux
- * Copyright (C) 2010-2014  CNRS
+ * Copyright (C) 2010-2014, 2016  CNRS
  *
  * 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
@@ -25,7 +25,6 @@
 #endif
 
 int tasks_executed[2];
-starpu_pthread_mutex_t mut;
 
 int parallel_code(int sched_ctx)
 {
@@ -79,7 +78,6 @@ int main(int argc, char **argv)
 		return 77;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
-	starpu_pthread_mutex_init(&mut, NULL);
 	int nprocs1 = 1;
 	int nprocs2 = 1;
 	int *procs1, *procs2;

+ 1 - 1
examples/sched_ctx/sched_ctx.c

@@ -71,7 +71,7 @@ int main(int argc, char **argv)
 		return 77;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
-	starpu_pthread_mutex_init(&mut, NULL);
+	STARPU_PTHREAD_MUTEX_INIT(&mut, NULL);
 
 #ifdef STARPU_USE_CPU
 	nprocs1 = starpu_cpu_worker_get_count();

+ 1 - 3
examples/sched_ctx/sched_ctx_without_sched_policy.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2014  Université de Bordeaux
- * Copyright (C) 2010-2014  CNRS
+ * Copyright (C) 2010-2014, 2016  CNRS
  *
  * 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
@@ -25,7 +25,6 @@
 #endif
 
 int tasks_executed[2];
-starpu_pthread_mutex_t mut;
 
 int parallel_code(int sched_ctx)
 {
@@ -78,7 +77,6 @@ int main(int argc, char **argv)
 		return 77;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
-	starpu_pthread_mutex_init(&mut, NULL);
 	int nprocs1 = 1;
 	int nprocs2 = 1;
 	int ncuda = 0;

+ 1 - 4
examples/sched_ctx/sched_ctx_without_sched_policy_awake.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2014  Université de Bordeaux
- * Copyright (C) 2010-2014  CNRS
+ * Copyright (C) 2010-2014, 2016  CNRS
  *
  * 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
@@ -25,8 +25,6 @@
 #endif
 
 
-starpu_pthread_mutex_t mut;
-
 int tasks_executed[2][STARPU_NMAXWORKERS];
 int parallel_code(int sched_ctx)
 {
@@ -74,7 +72,6 @@ int main(int argc, char **argv)
 		return 77;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
-	starpu_pthread_mutex_init(&mut, NULL);
 	int nprocs1 = 1;
 	int nprocs2 = 1;
 	int *procs1, *procs2;

+ 8 - 3
examples/stencil/life_opencl.c

@@ -79,7 +79,8 @@ opencl_life_init(void)
 
 void opencl_life_free(void)
 {
-  starpu_opencl_unload_opencl(&program);
+  int ret = starpu_opencl_unload_opencl(&program);
+  STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
 }
 
 void
@@ -92,12 +93,15 @@ opencl_life_update_host(int bz, const TYPE *old, TYPE *newp, int nx, int ny, int
 #endif
 
   int devid,id;
+  cl_int err;
+
   id = starpu_worker_get_id_check();
   devid = starpu_worker_get_devid(id);
 
   cl_kernel kernel;
   cl_command_queue cq;
-  starpu_opencl_load_kernel(&kernel, &cq, &program, "life_update", devid);
+  err = starpu_opencl_load_kernel(&kernel, &cq, &program, "life_update", devid);
+  if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
 
   clSetKernelArg(kernel, 0, sizeof(bz), &bz);
   clSetKernelArg(kernel, 1, sizeof(old), &old);
@@ -110,5 +114,6 @@ opencl_life_update_host(int bz, const TYPE *old, TYPE *newp, int nx, int ny, int
   clSetKernelArg(kernel, 8, sizeof(iter), &iter);
 
   cl_event ev;
-  clEnqueueNDRangeKernel(cq, kernel, 3, NULL, dim, NULL, 0, NULL, NULL);
+  err = clEnqueueNDRangeKernel(cq, kernel, 3, NULL, dim, NULL, 0, NULL, NULL);
+  if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
 }

+ 9 - 7
examples/stencil/shadow_opencl.c

@@ -17,7 +17,7 @@
 
 #include "stencil.h"
 
-/* Perform replication of data on X and Y edges, to fold the domain on 
+/* Perform replication of data on X and Y edges, to fold the domain on
    itself through mere replication of the source state. */
 
 #define str(x) #x
@@ -76,7 +76,8 @@ opencl_shadow_init(void)
 
 void opencl_shadow_free(void)
 {
-  starpu_opencl_unload_opencl(&program);
+  int ret = starpu_opencl_unload_opencl(&program);
+  STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
 }
 
 void
@@ -94,7 +95,10 @@ opencl_shadow_host(int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz,
 
         cl_kernel kernel;
         cl_command_queue cq;
-        starpu_opencl_load_kernel(&kernel, &cq, &program, "shadow", devid);
+	cl_int err;
+
+        err = starpu_opencl_load_kernel(&kernel, &cq, &program, "shadow", devid);
+	if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
 
         clSetKernelArg(kernel, 0, sizeof(bz), &bz);
         clSetKernelArg(kernel, 1, sizeof(ptr), &ptr);
@@ -106,8 +110,6 @@ opencl_shadow_host(int bz, TYPE *ptr, int nx, int ny, int nz, int ldy, int ldz,
         clSetKernelArg(kernel, 7, sizeof(i), &i);
 
         cl_event ev;
-        cl_int err = clEnqueueNDRangeKernel(cq, kernel, 3, NULL, dim, NULL, 0, NULL, NULL);
-        if (err != CL_SUCCESS)
-                STARPU_OPENCL_REPORT_ERROR(err);
+        err = clEnqueueNDRangeKernel(cq, kernel, 3, NULL, dim, NULL, 0, NULL, NULL);
+        if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
 }
-

+ 4 - 4
examples/stencil/stencil.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2011, 2012, 2013  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2016  CNRS
  * Copyright (C) 2010-2012, 2014  Université de Bordeaux
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -229,12 +229,12 @@ int main(int argc, char **argv)
 	}
 
 	ret = starpu_init(NULL);
-	if (ret == -ENODEV)
-		return 77;
+	if (ret == -ENODEV) return 77;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
 #if defined(STARPU_USE_MPI) && !defined(STARPU_SIMGRID)
-	starpu_mpi_init(NULL, NULL, 0);
+	ret = starpu_mpi_init(NULL, NULL, 0);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 #endif
 
 #ifdef STARPU_USE_OPENCL

+ 3 - 1
examples/top/hello_world_top.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2016  CNRS
  *
  * 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
@@ -86,6 +86,7 @@ void callback_name_changed(struct starpu_top_param* param)
 	char* message = (char *) malloc(256);
 	sprintf(message, "Name have been changed to %s", names[name_selected]);
 	starpu_top_debug_log(message);
+	free(message);
 }
 
 void callback_number_addition_changed(struct starpu_top_param* param)
@@ -94,6 +95,7 @@ void callback_number_addition_changed(struct starpu_top_param* param)
 	sprintf(message, "Number of addition is now %d", number_of_addition);
 
 	starpu_top_debug_log(message);
+	free(message);
 }
 
 struct starpu_codelet cl =

+ 5 - 5
socl/src/init.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2012 University of Bordeaux
- * Copyright (C) 2012,2014 CNRS
+ * Copyright (C) 2012,2014,2016 CNRS
  * Copyright (C) 2012 Vincent Danjean <Vincent.Danjean@ens-lyon.org>
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -27,7 +27,7 @@ static starpu_pthread_mutex_t _socl_mutex = STARPU_PTHREAD_MUTEX_INITIALIZER;
 static struct starpu_conf conf;
 
 void socl_init_starpu(void) {
-  starpu_pthread_mutex_lock(&_socl_mutex);
+  STARPU_PTHREAD_MUTEX_LOCK(&_socl_mutex);
   if( ! _starpu_init ){
     starpu_conf_init(&conf);
     conf.ncuda = 0;
@@ -51,7 +51,7 @@ void socl_init_starpu(void) {
     starpu_data_set_default_sequential_consistency_flag(0);
     _starpu_init = 1;
   }
-  starpu_pthread_mutex_unlock(&_socl_mutex);
+  STARPU_PTHREAD_MUTEX_UNLOCK(&_socl_mutex);
 
 }
 /**
@@ -72,7 +72,7 @@ void soclShutdown() {
    if (!shutdown) {
       shutdown = 1;
 
-      starpu_pthread_mutex_lock(&_socl_mutex);
+      STARPU_PTHREAD_MUTEX_LOCK(&_socl_mutex);
       if( _starpu_init )
          starpu_task_wait_for_all();
 
@@ -90,7 +90,7 @@ void soclShutdown() {
 
       if( _starpu_init && _starpu_init_failed != -ENODEV)
          starpu_shutdown();
-      starpu_pthread_mutex_unlock(&_socl_mutex);
+      STARPU_PTHREAD_MUTEX_UNLOCK(&_socl_mutex);
 
       if (socl_devices != NULL) {
          free(socl_devices);