Browse Source

Make where field for struct starpu_codelet optional. When unset, its
value will be automatically set based on the availability of the
different XXX_funcs fields of the codelet.

Nathalie Furmento 14 years ago
parent
commit
7fbf4f58da
5 changed files with 52 additions and 43 deletions
  1. 3 0
      ChangeLog
  2. 12 7
      doc/chapters/basic-api.texi
  3. 4 1
      doc/chapters/basic-examples.texi
  4. 6 12
      src/core/task.c
  5. 27 23
      tests/core/deprecated_func.c

+ 3 - 0
ChangeLog

@@ -18,6 +18,9 @@ StarPU 1.0 (svn revision xxxx)
 ==============================================
 The extensions-again release
 
+  * Make where field for struct starpu_codelet optional. When unset, its
+	value will be automatically set based on the availability of the
+	different XXX_funcs fields of the codelet.
   * Add a hook function pre_exec_hook in struct starpu_sched_policy.
         The function is meant to be called in drivers. Schedulers
         can use it to be notified when a task is about being computed.

+ 12 - 7
doc/chapters/basic-api.texi

@@ -1035,11 +1035,13 @@ The codelet structure describes a kernel that is possibly implemented on various
 targets. For compatibility, make sure to initialize the whole structure to zero.
 
 @table @asis
-@item @code{where}
+@item @code{where} (optional)
 Indicates which types of processing units are able to execute the codelet.
 @code{STARPU_CPU|STARPU_CUDA} for instance indicates that the codelet is
 implemented for both CPU cores and CUDA devices while @code{STARPU_GORDON}
-indicates that it is only available on Cell SPUs.
+indicates that it is only available on Cell SPUs. If the field is
+unset, its value will be automatically set based on the availability
+of the @code{XXX_funcs} fields defined below.
 
 @item @code{cpu_func} (optional)
 This field has been made deprecated. One should use instead the
@@ -1052,8 +1054,9 @@ The functions prototype must be: @code{void cpu_func(void *buffers[], void *cl_a
 argument being the array of data managed by the data management library, and
 the second argument is a pointer to the argument passed from the @code{cl_arg}
 field of the @code{starpu_task} structure.
-The @code{cpu_funcs} field is ignored if @code{STARPU_CPU} does not appear in
-the @code{where} field, it must be non-null otherwise.
+If the @code{where} field is set, then the @code{cpu_funcs} field is
+ignored if @code{STARPU_CPU} does not appear in the @code{where}
+field, it must be non-null otherwise.
 
 @item @code{cuda_func} (optional)
 This field has been made deprecated. One should use instead the
@@ -1064,7 +1067,8 @@ Is an array of function pointers to the CUDA implementations of the codelet.
 It must be terminated by a NULL value.
 @emph{The functions must be host-functions written in the CUDA runtime
 API}. Their prototype must
-be: @code{void cuda_func(void *buffers[], void *cl_arg);}. The @code{cuda_funcs}
+be: @code{void cuda_func(void *buffers[], void *cl_arg);}.
+If the @code{where} field is set, then the @code{cuda_funcs}
 field is ignored if @code{STARPU_CUDA} does not appear in the @code{where}
 field, it must be non-null otherwise.
 
@@ -1077,8 +1081,9 @@ Is an array of function pointers to the OpenCL implementations of the codelet.
 It must be terminated by a NULL value.
 The functions prototype must be:
 @code{void opencl_func(void *buffers[], void *cl_arg);}.
-This pointer is ignored if @code{STARPU_OPENCL} does not appear in the
-@code{where} field, it must be non-null otherwise.
+If the @code{where} field is set, then the @code{opencl_funcs} field
+is ignored if @code{STARPU_OPENCL} does not appear in the @code{where}
+field, it must be non-null otherwise.
 
 @item @code{gordon_func} (optional)
 This field has been made deprecated. One should use instead the

+ 4 - 1
doc/chapters/basic-examples.texi

@@ -106,7 +106,10 @@ management library, but just contain trivial parameters.
 We create a codelet which may only be executed on the CPUs. The @code{where}
 field is a bitmask that defines where the codelet may be executed. Here, the
 @code{STARPU_CPU} value means that only CPUs can execute this codelet
-(@pxref{Codelets and Tasks} for more details on this field).
+(@pxref{Codelets and Tasks} for more details on this field). Note that
+the @code{where} field is optional, when unset its value is
+automatically set based on the availability of the different
+@code{XXX_funcs} fields.
 When a CPU core executes a codelet, it calls the @code{cpu_func} function,
 which @emph{must} have the following prototype:
 

+ 6 - 12
src/core/task.c

@@ -226,6 +226,8 @@ void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl)
 	if (!cl)
 		return;
 
+	int is_where_unset = cl->where == 0;
+
 	/* Check deprecated and unset fields (where, <device>_func,
  	 * <device>_funcs) */
 
@@ -244,12 +246,10 @@ void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl)
 	{
 		cl->cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS;
 	}
-#if 0
-	if (cl->cpu_funcs[0])
+	if (cl->cpu_funcs[0] && is_where_unset)
 	{
 		cl->where |= STARPU_CPU;
 	}
-#endif
 
 	/* CUDA */
 	if (cl->cuda_func && cl->cuda_func != STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS && cl->cuda_funcs[0])
@@ -266,12 +266,10 @@ void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl)
 	{
 		cl->cuda_func = STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS;
 	}
-#if 0
-	if (cl->cuda_funcs[0])
+	if (cl->cuda_funcs[0] && is_where_unset)
 	{
 		cl->where |= STARPU_CUDA;
 	}
-#endif
 
 	/* OpenCL */
 	if (cl->opencl_func && cl->opencl_func != STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS && cl->opencl_funcs[0])
@@ -288,12 +286,10 @@ void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl)
 	{
 		cl->opencl_func = STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS;
 	}
-#if 0
-	if (cl->opencl_funcs[0])
+	if (cl->opencl_funcs[0] && is_where_unset)
 	{
 		cl->where |= STARPU_OPENCL;
 	}
-#endif
 
 	/* Gordon */
 	if (cl->gordon_func && cl->gordon_func != STARPU_MULTIPLE_GORDON_IMPLEMENTATIONS)
@@ -305,12 +301,10 @@ void _starpu_codelet_check_deprecated_fields(struct starpu_codelet *cl)
 	{
 		cl->gordon_func = STARPU_MULTIPLE_GORDON_IMPLEMENTATIONS;
 	}
-#if 0
-	if (cl->gordon_funcs[0])
+	if (cl->gordon_funcs[0] && is_where_unset)
 	{
 		cl->where = STARPU_GORDON;
 	}
-#endif
 }
 
 void _starpu_task_check_deprecated_fields(struct starpu_task *task)

+ 27 - 23
tests/core/deprecated_func.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * 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
@@ -67,7 +67,7 @@ struct starpu_codelet cl_cpu_func_funcs =
 	.name = "cpu_func_funcs",
 };
 
-int submit_codelet(struct starpu_codelet *cl)
+int submit_codelet(struct starpu_codelet *cl, int where)
 {
 	int x=42, y=14;
 	starpu_data_handle_t handles[2];
@@ -76,6 +76,7 @@ int submit_codelet(struct starpu_codelet *cl)
 	starpu_variable_data_register(&handles[0], 0, (uintptr_t)&x, sizeof(x));
 	starpu_variable_data_register(&handles[1], 0, (uintptr_t)&y, sizeof(y));
 
+	cl->where = where;
 	ret = starpu_insert_task(cl,
 				 STARPU_R, handles[0],
 				 STARPU_W, handles[1],
@@ -94,41 +95,44 @@ int submit_codelet(struct starpu_codelet *cl)
 
 	if (x != y)
 	{
-		FPRINTF(stderr, "error when executing codelet <%s>\n", cl->name);
+		FPRINTF(stderr, "error when executing codelet <%s> with where=%d\n", cl->name, where);
 	}
 	else
 	{
-		FPRINTF(stderr, "success when executing codelet <%s>\n", cl->name);
+		FPRINTF(stderr, "success when executing codelet <%s> with where=%d\n", cl->name, where);
 	}
 	return (x != y);
 }
 
 int main(int argc, char **argv)
 {
-	int ret;
+	int ret, where;
 
 	ret = starpu_init(NULL);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
-	ret = submit_codelet(&cl_cpu_func);
-	if (ret == -ENODEV)
-	{
-		starpu_shutdown();
-		fprintf(stderr, "WARNING: No one can execute this task\n");
-		return STARPU_TEST_SKIPPED;
-	}
-
-	if (!ret)
-	{
-		ret = submit_codelet(&cl_cpu_funcs);
-	}
-	if (!ret)
-	{
-		ret = submit_codelet(&cl_cpu_multiple);
-	}
-	if (!ret)
+	for(where=0 ; where<=STARPU_CPU ; where+=STARPU_CPU)
 	{
-		ret = submit_codelet(&cl_cpu_func_funcs);
+		ret = submit_codelet(&cl_cpu_func, where);
+		if (ret == -ENODEV)
+		{
+			starpu_shutdown();
+			fprintf(stderr, "WARNING: No one can execute this task\n");
+			return STARPU_TEST_SKIPPED;
+		}
+
+		if (!ret)
+		{
+			ret = submit_codelet(&cl_cpu_funcs, where);
+		}
+		if (!ret)
+		{
+			ret = submit_codelet(&cl_cpu_multiple, where);
+		}
+		if (!ret)
+		{
+			ret = submit_codelet(&cl_cpu_func_funcs, where);
+		}
 	}
 
 	starpu_shutdown();