Browse Source

Mark struct starpu_codelet's fields XXX_func as deprecated. Fields
xxx_funcs should be used instead.

The new function

void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl);

is called within StarPU to check if the deprecated fields are set and
to set instead the xxx_funcs fields.

The new functions

starpu_cpu_func_t _starpu_task_get_cpu_nth_implementation(struct starpu_codelet *cl, unsigned nimpl);
starpu_cuda_func_t _starpu_task_get_cuda_nth_implementation(struct starpu_codelet *cl, unsigned nimpl);
starpu_opencl_func_t _starpu_task_get_opencl_nth_implementation(struct starpu_codelet *cl, unsigned nimpl);
starpu_gordon_func_t _starpu_task_get_gordon_nth_implementation(struct starpu_codelet *cl, unsigned nimpl);

should be used to retrieve the n-th func of a codelet, instead of
accessing the xxx_func(s) field directly.

Nathalie Furmento 13 years ago
parent
commit
9faadcf561

+ 4 - 4
include/starpu_task.h

@@ -84,10 +84,10 @@ struct starpu_codelet
 	int max_parallelism;
 
 	/* the different implementations of the codelet */
-	void (*cuda_func)(void **, void *);
-	void (*cpu_func)(void **, void *);
-	void (*opencl_func)(void **, void *);
-	uint8_t gordon_func;
+	void (*cuda_func)(void **, void *) STARPU_DEPRECATED;
+	void (*cpu_func)(void **, void *) STARPU_DEPRECATED;
+	void (*opencl_func)(void **, void *) STARPU_DEPRECATED;
+	uint8_t gordon_func STARPU_DEPRECATED;
 
 	starpu_cpu_func_t cpu_funcs[STARPU_MAXIMPLEMENTATIONS];
 	starpu_cuda_func_t cuda_funcs[STARPU_MAXIMPLEMENTATIONS];

+ 1 - 1
src/core/jobs.h

@@ -45,7 +45,7 @@
 struct _starpu_worker;
 
 /* codelet function */
-typedef void (*_starpu_cl_func)(void **, void *);
+typedef void (*_starpu_cl_func_t)(void **, void *);
 
 #define _STARPU_CPU_MAY_PERFORM(j)	((j)->task->cl->where & STARPU_CPU)
 #define _STARPU_CUDA_MAY_PERFORM(j)      ((j)->task->cl->where & STARPU_CUDA)

+ 51 - 0
src/core/task.c

@@ -221,6 +221,27 @@ int _starpu_submit_job(struct _starpu_job *j)
         return ret;
 }
 
+void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl)
+{
+	/* Check deprecated fields */
+	if (cl && cl->cpu_func && cl->cpu_func != STARPU_MULTIPLE_CPU_IMPLEMENTATIONS) {
+		cl->cpu_funcs[0] = cl->cpu_func;
+		cl->cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS;
+	}
+	if (cl && cl->cuda_func && cl->cuda_func != STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS) {
+		cl->cuda_funcs[0] = cl->cuda_func;
+		cl->cuda_func = STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS;
+	}
+	if (cl && cl->opencl_func && cl->opencl_func != STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS) {
+		cl->opencl_funcs[0] = cl->opencl_func;
+		cl->opencl_func = STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS;
+	}
+	if (cl && cl->gordon_func && cl->gordon_func != STARPU_MULTIPLE_GORDON_IMPLEMENTATIONS) {
+		cl->gordon_funcs[0] = cl->gordon_func;
+		cl->gordon_func = STARPU_MULTIPLE_GORDON_IMPLEMENTATIONS;
+	}
+}
+
 /* application should submit new tasks to StarPU through this function */
 int starpu_task_submit(struct starpu_task *task)
 {
@@ -248,11 +269,17 @@ int starpu_task_submit(struct starpu_task *task)
 	{
 		uint32_t where = task->cl->where;
 		unsigned i;
+
+		_starpu_codelet_check_deprecated_fields(task->cl);
+
+		/* Check the type of worker(s) required by the task exist */
 		if (!_starpu_worker_exists(where))
 		{
                         _STARPU_LOG_OUT_TAG("ENODEV");
 			return -ENODEV;
                 }
+
+		/* Check buffers */
 		assert(task->cl->nbuffers <= STARPU_NMAXBUFS);
 		for (i = 0; i < task->cl->nbuffers; i++)
 		{
@@ -505,3 +532,27 @@ _starpu_handle_needs_conversion_task(starpu_data_handle_t handle,
 			STARPU_ASSERT(0);
 	}
 }
+
+starpu_cpu_func_t _starpu_task_get_cpu_nth_implementation(struct starpu_codelet *cl, unsigned nimpl)
+{
+	STARPU_ASSERT(cl->cpu_func == STARPU_MULTIPLE_CPU_IMPLEMENTATIONS);
+	return cl->cpu_funcs[nimpl];
+}
+
+starpu_cuda_func_t _starpu_task_get_cuda_nth_implementation(struct starpu_codelet *cl, unsigned nimpl)
+{
+	STARPU_ASSERT(cl->cuda_func == STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS);
+	return cl->cuda_funcs[nimpl];
+}
+
+starpu_opencl_func_t _starpu_task_get_opencl_nth_implementation(struct starpu_codelet *cl, unsigned nimpl)
+{
+	STARPU_ASSERT(cl->opencl_func == STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS);
+	return cl->opencl_funcs[nimpl];
+}
+
+starpu_gordon_func_t _starpu_task_get_gordon_nth_implementation(struct starpu_codelet *cl, unsigned nimpl)
+{
+	STARPU_ASSERT(cl->gordon_func == STARPU_MULTIPLE_GORDON_IMPLEMENTATIONS);
+	return cl->gordon_funcs[nimpl];
+}

+ 6 - 0
src/core/task.h

@@ -51,4 +51,10 @@ int _starpu_handle_needs_conversion_task(starpu_data_handle_t handle,
 
 int _starpu_task_uses_multiformat_handles(struct starpu_task *task);
 
+void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl);
+starpu_cpu_func_t _starpu_task_get_cpu_nth_implementation(struct starpu_codelet *cl, unsigned nimpl);
+starpu_cuda_func_t _starpu_task_get_cuda_nth_implementation(struct starpu_codelet *cl, unsigned nimpl);
+starpu_opencl_func_t _starpu_task_get_opencl_nth_implementation(struct starpu_codelet *cl, unsigned nimpl);
+starpu_gordon_func_t _starpu_task_get_gordon_nth_implementation(struct starpu_codelet *cl, unsigned nimpl);
+
 #endif // __CORE_TASK_H__

+ 16 - 12
src/core/workers.c

@@ -74,21 +74,25 @@ static int _starpu_can_use_nth_implementation(enum starpu_archtype arch, struct
 	switch(arch)
 	{
 	case STARPU_CPU_WORKER:
-		if (cl->cpu_func == STARPU_MULTIPLE_CPU_IMPLEMENTATIONS)
-			return cl->cpu_funcs[nimpl] != NULL;
-		return nimpl == 0;
+	{
+		starpu_cpu_func_t func = _starpu_task_get_cpu_nth_implementation(cl, nimpl);
+		return func != NULL;
+	}
 	case STARPU_CUDA_WORKER:
-		if (cl->cuda_func == STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS)
-			return cl->cuda_funcs[nimpl] != NULL;
-		return nimpl == 0;
+	{
+		starpu_cuda_func_t func = _starpu_task_get_cuda_nth_implementation(cl, nimpl);
+		return func != NULL;
+	}
 	case STARPU_OPENCL_WORKER:
-		if (cl->opencl_func == STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS)
-			return cl->opencl_funcs[nimpl] != NULL;
-		return nimpl == 0;
+	{
+		starpu_opencl_func_t func = _starpu_task_get_opencl_nth_implementation(cl, nimpl);
+		return func != NULL;
+	}
 	case STARPU_GORDON_WORKER:
-		if (cl->gordon_func == STARPU_MULTIPLE_GORDON_IMPLEMENTATIONS)
-			return cl->gordon_funcs[nimpl] != 0;
-		return nimpl == 0;
+	{
+		starpu_gordon_func_t func = _starpu_task_get_gordon_nth_implementation(cl, nimpl);
+		return func != NULL;
+	}
 	default:
 		STARPU_ASSERT(!"Unknown arch type");
 	}

+ 4 - 1
src/datawizard/interfaces/data_interface.c

@@ -481,7 +481,10 @@ static void _starpu_data_unregister(starpu_data_handle_t handle, unsigned cohere
 					STARPU_ASSERT(0);
 			}
 			buffers[0] = format_interface;
-			cl->cpu_func(buffers, NULL);
+
+			_starpu_cl_func_t func = _starpu_task_get_cpu_nth_implementation(cl, 0);
+			STARPU_ASSERT(func);
+			func(buffers, NULL);
 		}
 	}
 	else

+ 9 - 0
src/datawizard/interfaces/multiformat_interface.c

@@ -166,6 +166,15 @@ void starpu_multiformat_data_register(starpu_data_handle_t *handleptr,
 				      uint32_t nobjects,
 				      struct starpu_multiformat_data_interface_ops *format_ops)
 {
+#ifdef STARPU_USE_OPENCL
+	_starpu_codelet_check_deprecated_fields(format_ops->cpu_to_opencl_cl);
+	_starpu_codelet_check_deprecated_fields(format_ops->opencl_to_cpu_cl);
+#endif
+#ifdef STARPU_USE_CUDA
+	_starpu_codelet_check_deprecated_fields(format_ops->cpu_to_cuda_cl);
+	_starpu_codelet_check_deprecated_fields(format_ops->cuda_to_cpu_cl);
+#endif
+
 	struct starpu_multiformat_interface multiformat =
 	{
 		.cpu_ptr    = ptr,

+ 9 - 6
src/datawizard/reduction.c

@@ -21,11 +21,14 @@
 #include <datawizard/datawizard.h>
 
 void starpu_data_set_reduction_methods(starpu_data_handle_t handle,
-					struct starpu_codelet *redux_cl,
-					struct starpu_codelet *init_cl)
+				       struct starpu_codelet *redux_cl,
+				       struct starpu_codelet *init_cl)
 {
 	_starpu_spin_lock(&handle->header_lock);
 
+	_starpu_codelet_check_deprecated_fields(redux_cl);
+	_starpu_codelet_check_deprecated_fields(init_cl);
+
 	unsigned child;
 	for (child = 0; child < handle->nchildren; child++)
 	{
@@ -49,20 +52,20 @@ void _starpu_redux_init_data_replicate(starpu_data_handle_t handle, struct _star
 	struct starpu_codelet *init_cl = handle->init_cl;
 	STARPU_ASSERT(init_cl);
 
-	_starpu_cl_func init_func = NULL;
+	_starpu_cl_func_t init_func = NULL;
 
 	/* TODO Check that worker may execute the codelet */
 
 	switch (starpu_worker_get_type(workerid))
 	{
 		case STARPU_CPU_WORKER:
-			init_func = init_cl->cpu_func;
+			init_func = _starpu_task_get_cpu_nth_implementation(init_cl, 0);
 			break;
 		case STARPU_CUDA_WORKER:
-			init_func = init_cl->cuda_func;
+			init_func = _starpu_task_get_cuda_nth_implementation(init_cl, 0);
 			break;
 		case STARPU_OPENCL_WORKER:
-			init_func = init_cl->opencl_func;
+			init_func = _starpu_task_get_opencl_nth_implementation(init_cl, 0);
 			break;
 		default:
 			STARPU_ABORT();

+ 3 - 14
src/drivers/cpu/driver_cpu.c

@@ -34,7 +34,6 @@ static int execute_job_on_cpu(struct _starpu_job *j, struct _starpu_worker *cpu_
 	struct starpu_codelet *cl = task->cl;
 
 	STARPU_ASSERT(cl);
-	STARPU_ASSERT(cl->cpu_func);
 
 	if (rank == 0)
 	{
@@ -56,19 +55,9 @@ static int execute_job_on_cpu(struct _starpu_job *j, struct _starpu_worker *cpu_
 	 * execute the kernel at all. */
 	if ((rank == 0) || (cl->type != STARPU_FORKJOIN))
 	{
-		if (cl->cpu_func != STARPU_MULTIPLE_CPU_IMPLEMENTATIONS)
-		{
-			_starpu_cl_func func = cl->cpu_func;
-			STARPU_ASSERT(func);
-			func(task->interfaces, task->cl_arg);
-		}
-		else
-		{
-			/* _STARPU_DEBUG("CPU driver : running kernel (%d)\n", j->nimpl); */
-			_starpu_cl_func func = cl->cpu_funcs[j->nimpl];
-			STARPU_ASSERT(func);
-			func(task->interfaces, task->cl_arg);
-		}
+		_starpu_cl_func_t func = _starpu_task_get_cpu_nth_implementation(cl, j->nimpl);
+		STARPU_ASSERT(func);
+		func(task->interfaces, task->cl_arg);
 	}
 
 	_starpu_driver_end_job(cpu_args, j, &codelet_end, rank);

+ 3 - 13
src/drivers/cuda/driver_cuda.c

@@ -217,19 +217,9 @@ static int execute_job_on_cuda(struct _starpu_job *j, struct _starpu_worker *arg
 		STARPU_CUDA_REPORT_ERROR(cures);
 #endif
 
-	if (cl->cuda_func != STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS)
-	{
-		_starpu_cl_func func = cl->cuda_func;
-		STARPU_ASSERT(func);
-		func(task->interfaces, task->cl_arg);
-	}
-	else
-	{
-		/* _STARPU_DEBUG("Cuda driver : running kernel * (%d)\n", j->nimpl); */
-		_starpu_cl_func func = cl->cuda_funcs[j->nimpl];
-		STARPU_ASSERT(func);
-		func(task->interfaces, task->cl_arg);
-	}
+	starpu_cuda_func_t func = _starpu_task_get_cuda_nth_implementation(cl, j->nimpl);
+	STARPU_ASSERT(func);
+	func(task->interfaces, task->cl_arg);
 
 	_starpu_driver_end_job(args, j, &codelet_end, 0);
 

+ 2 - 5
src/drivers/gordon/driver_gordon.c

@@ -167,10 +167,7 @@ static struct gordon_task_wrapper_s *starpu_to_gordon_job(struct _starpu_job *j)
 	task_wrapper->j = j;
 	task_wrapper->terminated = 0;
 
-	if (j->task->clgordon_func != STARPU_MULTIPLE_GORDON_IMPLEMENTATIONS)
-		gordon_job->index = j->task->cl->gordon_func;
-	else
-		gordon_job->index = j->task->cl->gordon_funcs[j->nimpl];
+	gordon_job->index = _starpu_task_get_gordon_nth_implementation(j->task->cl, j->nimpl);
 
 	/* we should not hardcore the memory node ... XXX */
 	unsigned memory_node = 0;
@@ -321,7 +318,7 @@ int inject_task_list(struct _starpu_job_list *list, struct _starpu_worker *worke
 		ret = _starpu_fetch_task_input(task, 0);
 		STARPU_ASSERT(!ret);
 
-		gordon_jobs[index].index = task->cl->gordon_func;
+		gordon_jobs[index].index = _starpu_task_get_gordon_nth_implementation(task->cl, j->nimpl);
 
 		struct starpu_perfmodel *model = j->task->cl->model;
 		if (model && model->benchmarking)

+ 3 - 13
src/drivers/opencl/driver_opencl.c

@@ -593,19 +593,9 @@ static int _starpu_opencl_execute_job(struct _starpu_job *j, struct _starpu_work
 
 	_starpu_driver_start_job(args, j, &codelet_start, 0);
 
-	if (cl->opencl_func != STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS)
-	{
-		_starpu_cl_func func = cl->opencl_func;
-		STARPU_ASSERT(func);
-		func(task->interfaces, task->cl_arg);
-	}
-	else
-	{
-		/* _STARPU_DEBUG("OpenCL driver : running kernel (%d)\n", j->nimpl); */
-		_starpu_cl_func func = cl->opencl_funcs[j->nimpl];
-		STARPU_ASSERT(func);
-		func(task->interfaces, task->cl_arg);
-	}
+	starpu_opencl_func_t func = _starpu_task_get_opencl_nth_implementation(cl, j->nimpl);
+	STARPU_ASSERT(func);
+	func(task->interfaces, task->cl_arg);
 
 	_starpu_driver_end_job(args, j, &codelet_end, 0);
 

+ 6 - 3
src/util/execute_on_all.c

@@ -44,9 +44,12 @@ void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t whe
 	struct starpu_codelet wrapper_cl =
 	{
 		.where = where,
-		.cuda_func = wrapper_func,
-		.cpu_func = wrapper_func,
-		.opencl_func = wrapper_func,
+		.cuda_func = STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS,
+		.cuda_funcs = {wrapper_func, NULL},
+		.cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS,
+		.cpu_funcs = {wrapper_func, NULL},
+		.opencl_func = STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS,
+		.opencl_funcs = {wrapper_func, NULL},
 		/* XXX we do not handle Cell .. */
 		.nbuffers = 0
 	};

+ 8 - 4
src/util/malloc.c

@@ -61,9 +61,11 @@ static struct starpu_perfmodel malloc_pinned_model =
 
 static struct starpu_codelet malloc_pinned_cl =
 {
-	.cuda_func = malloc_pinned_cuda_codelet,
+	.cuda_func = STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS,
+	.cuda_funcs = {malloc_pinned_cuda_codelet, NULL},
 //#ifdef STARPU_USE_OPENCL
-//	.opencl_func = malloc_pinned_opencl_codelet,
+//	.opencl_func = STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS,
+//	.opencl_funcs = {malloc_pinned_opencl_codelet, NULL},
 //#endif
 	.nbuffers = 0,
 	.model = &malloc_pinned_model
@@ -165,9 +167,11 @@ static struct starpu_perfmodel free_pinned_model =
 
 static struct starpu_codelet free_pinned_cl =
 {
-	.cuda_func = free_pinned_cuda_codelet,
+	.cuda_func = STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS,
+	.cuda_funcs = {free_pinned_cuda_codelet, NULL},
 //#ifdef STARPU_USE_OPENCL
-//	.opencl_func = free_pinned_opencl_codelet,
+//	.opencl_func = STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS,
+//	.opencl_funcs = {free_pinned_opencl_codelet, NULL},
 //#endif
 	.nbuffers = 0,
 	.model = &free_pinned_model

+ 6 - 3
src/util/starpu_data_cpy.c

@@ -59,9 +59,12 @@ struct starpu_perfmodel copy_model =
 static struct starpu_codelet copy_cl =
 {
 	.where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
-	.cpu_func = data_cpy_func,
-	.cuda_func = data_cpy_func,
-	.opencl_func = data_cpy_func,
+	.cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS,
+	.cpu_funcs = {data_cpy_func, NULL},
+	.cuda_func = STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS,
+	.cuda_funcs = {data_cpy_func, NULL},
+	.opencl_func = STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS,
+	.opencl_funcs = {data_cpy_func, NULL},
 	.nbuffers = 2,
 	.model = &copy_model
 };