Browse Source

tools/dev : add a coccinelle semantic patch that converts cpu_func to cpu_funcs in codelet initialization.

* Removes cpu_func and adds cpu_funcs
* If both cpu_func and cpu_funcs are defined, removes cpu_func
* Removes "cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS"
Cyril Roelandt 13 years ago
parent
commit
6158fd9e59

+ 64 - 0
tools/dev/experimental/cpu_func_to_cpu_funcs.cocci

@@ -0,0 +1,64 @@
+// $ spatch -sp_file cpu_func_to_cpu_funcs.cocci cpu_func_to_cpu_funcs_test.c
+
+///////////////////////////////////////////////////////////////////////////////
+// There is no need to specify STARPU_MULTIPLE_CPU_IMPLEMENTATIONS any more. //
+// XXX : We must find a way to make sure cpu_funcs is NULL-terminated.       //
+///////////////////////////////////////////////////////////////////////////////
+@@
+identifier cl;
+@@
+struct starpu_codelet cl = {
+-	.cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS,
+	.cpu_funcs = { ... }
+};
+
+
+////////////////////////////////////////////////////
+// Find all the codelets using the cpu_func field //
+////////////////////////////////////////////////////
+@cpu_func@
+expression f;
+identifier cl;
+@@
+struct starpu_codelet cl = {
+	.cpu_func = f
+};
+
+
+
+///////////////////////////////////////////////////////////////////
+// Find all the codelets that define both cpu_func and cpu_funcs //
+///////////////////////////////////////////////////////////////////
+@cpu_funcs depends on cpu_func@
+expression cpu_func.f;
+identifier cpu_func.cl;
+@@
+struct starpu_codelet cl = {
+	.cpu_funcs = { f, NULL }
+};
+
+
+//////////////////////////////////////////////////////////////////////////////
+// For codelets that define cpu_func but not cpu_funcs, remove cpu_func and //
+// add cpu_funcs                                                            //
+//////////////////////////////////////////////////////////////////////////////
+@depends on !cpu_funcs@
+identifier cpu_func.cl;
+expression cpu_func.f;
+@@
+struct starpu_codelet cl = {
+-	.cpu_func = f
++	.cpu_funcs = { f, NULL }
+};
+
+
+/////////////////////////////////////////////////////////////////
+// If both cpu_func and cpu_funcs are defined, remove cpu_func //
+/////////////////////////////////////////////////////////////////
+@depends on cpu_funcs@
+identifier cpu_func.cl;
+expression cpu_func.f;
+@@
+struct starpu_codelet cl = {
+-	.cpu_func = f
+};

+ 43 - 0
tools/dev/experimental/cpu_func_to_cpu_funcs_test.c

@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <sdtdlib.h>
+#include "lol.h"
+
+/*
+ * Old format
+ */
+struct starpu_codelet cl1 = {
+	.where = STARPU_CPU,
+	.cpu_func = foo
+};
+
+/*
+ * New format : it must not be changed !
+ */
+struct starpu_codelet cl2 = {
+	.cpu_funcs = {foo, NULL}
+};
+
+/*
+ * Maybe we added the cpu_funcs fields, but forgot to remove the cpu_func one.
+ */
+struct starpu_codelet cl3 = {
+	.cpu_func = foo,
+	.cpu_funcs = { foo, NULL }
+};
+
+/*
+ * Old multiimplementations format, but not terminated by NULL
+ * XXX : NULL is not added.
+ */
+struct starpu_codelet cl4 = {
+	.cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS,
+	.cpu_funcs = { foo, bar }
+};
+
+/*
+ * Old multiimplementations format, terminated by NULL
+ */
+struct starpu_codelet cl5 = {
+	.cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS,
+	.cpu_funcs = { foo, bar, NULL }
+};