StarPU Handbook
|
When GCC plug-in support is available, StarPU builds a plug-in for the GNU Compiler Collection (GCC), which defines extensions to languages of the C family (C, C++, Objective-C) that make it easier to write StarPU code. This feature is only available for GCC 4.5 and later; it is known to work with GCC 4.5, 4.6, and 4.7. You may need to install a specific -dev
package of your distro, such as gcc-4.6-plugin-dev
on Debian and derivatives. In addition, the plug-in's test suite is only run when GNU Guile is found at configure
-time. Building the GCC plug-in can be disabled by configuring with --disable-gcc-extensions.
Those extensions include syntactic sugar for defining tasks and their implementations, invoking a task, and manipulating data buffers. Use of these extensions can be made conditional on the availability of the plug-in, leading to valid C sequential code when the plug-in is not used (Using C Extensions Conditionally).
When StarPU has been installed with its GCC plug-in, programs that use these extensions can be compiled this way:
$ gcc -c -fplugin=`pkg-config starpu-1.1 --variable=gccplugin` foo.c
When the plug-in is not available, the above pkg-config
command returns the empty string.
In addition, the -fplugin-arg-starpu-verbose
flag can be used to obtain feedback from the compiler as it analyzes the C extensions used in source files.
This section describes the C extensions implemented by StarPU's GCC plug-in. It does not require detailed knowledge of the StarPU library.
Note: this is still an area under development and subject to change.
The StarPU GCC plug-in views tasks as ``extended'' C functions:
Tasks and their implementations must be declared. These declarations are annotated with attributes (http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax): the declaration of a task is a regular C function declaration with an additional task
attribute, and task implementations are declared with a task_implementation
attribute.
The following function attributes are provided:
task
Declare the given function as a StarPU task. Its return type must be void
. When a function declared as task
has a user-defined body, that body is interpreted as the implicit definition of the task's CPU implementation (see example below). In all cases, the actual definition of a task's body is automatically generated by the compiler.
Under the hood, declaring a task leads to the declaration of the corresponding codelet
(Codelet and Tasks). If one or more task implementations are declared in the same compilation unit, then the codelet and the function itself are also defined; they inherit the scope of the task.
Scalar arguments to the task are passed by value and copied to the target device if need be—technically, they are passed as the buffer starpu_task::cl_arg (Codelet and Tasks).
Pointer arguments are assumed to be registered data buffers—the handles argument of a task (starpu_task::handles) ; const
-qualified pointer arguments are viewed as read-only buffers (STARPU_R), and non-const
-qualified buffers are assumed to be used read-write (STARPU_RW). In addition, the output
type attribute can be as a type qualifier for output pointer or array parameters (STARPU_W).
task_implementation (target, task)
Declare the given function as an implementation of task
to run on target
. target
must be a string, currently one of "cpu"
, "opencl"
, or "cuda"
.