123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163 |
- \input texinfo @c -*-texinfo-*-
- @c %**start of header
- @setfilename starpu.info
- @settitle StarPU
- @c %**end of header
- @setchapternewpage odd
- @titlepage
- @title StarPU
- @page
- @vskip 0pt plus 1filll
- @comment For the @value{version-GCC} Version*
- @end titlepage
- @summarycontents
- @contents
- @page
- @node Top
- @top Preface
- @cindex Preface
- This manual documents the usage of StarPU.
- @comment
- @comment When you add a new menu item, please keep the right hand
- @comment aligned to the same column. Do not use tabs. This provides
- @comment better formatting.
- @comment
- @menu
- * Introduction:: A basic introduction to using StarPU
- * Installing StarPU:: How to configure, build and install StarPU
- * Using StarPU:: How to run StarPU application
- * Configuring StarPU:: How to configure StarPU
- * StarPU API:: The API to use StarPU
- * Basic Examples:: Basic examples of the use of StarPU
- * Full source code for the 'Scaling a Vector' example::
- @end menu
- @c ---------------------------------------------------------------------
- @c Introduction to StarPU
- @c ---------------------------------------------------------------------
- @node Introduction
- @chapter Introduction to StarPU
- @menu
- * Motivation:: Why StarPU ?
- * StarPU in a Nutshell:: The Fundamentals of StarPU
- @end menu
- @node Motivation
- @section Motivation
- @c complex machines with heterogeneous cores/devices
- The use of specialized hardware such as accelerators or coprocessors offers an
- interesting approach to overcome the physical limits encountered by processor
- architects. As a result, many machines are now equipped with one or several
- accelerators (e.g. a GPU), in addition to the usual processor(s). While a lot of
- efforts have been devoted to offload computation onto such accelerators, very
- little attention as been paid to portability concerns on the one hand, and to the
- possibility of having heterogeneous accelerators and processors to interact on the other hand.
- StarPU is a runtime system that offers support for heterogeneous multicore
- architectures, it not only offers a unified view of the computational resources
- (i.e. CPUs and accelerators at the same time), but it also takes care of
- efficiently mapping and executing tasks onto an heterogeneous machine while
- transparently handling low-level issues in a portable fashion.
- @c this leads to a complicated distributed memory design
- @c which is not (easily) manageable by hand
- @c added value/benefits of StarPU
- @c - portability
- @c - scheduling, perf. portability
- @node StarPU in a Nutshell
- @section StarPU in a Nutshell
- @menu
- * Codelet and Tasks::
- * StarPU Data Management Library::
- @end menu
- From a programming point of view, StarPU is not a new language but a library
- that executes tasks explicitly submitted by the application. The data that a
- task manipulates are automatically transferred onto the accelerator so that the
- programmer does not have to take care of complex data movements. StarPU also
- takes particular care of scheduling those tasks efficiently and allows
- scheduling experts to implement custom scheduling policies in a portable
- fashion.
- @c explain the notion of codelet and task (i.e. g(A, B)
- @node Codelet and Tasks
- @subsection Codelet and Tasks
- One of StarPU primary data structure is the @b{codelet}. A codelet describes a
- computational kernel that can possibly be implemented on multiple architectures
- such as a CPU, a CUDA device or a Cell's SPU.
- @c TODO insert illustration f : f_spu, f_cpu, ...
- Another important data structure is the @b{task}. Executing a StarPU task
- consists in applying a codelet on a data set, on one of the architectures on
- which the codelet is implemented. In addition to the codelet that a task
- implements, it also describes which data are accessed, and how they are
- accessed during the computation (read and/or write).
- StarPU tasks are asynchronous: submitting a task to StarPU is a non-blocking
- operation. The task structure can also specify a @b{callback} function that is
- called once StarPU has properly executed the task. It also contains optional
- fields that the application may use to give hints to the scheduler (such as
- priority levels).
- A task may be identified by a unique 64-bit number which we refer as a @b{tag}.
- Task dependencies can be enforced either by the means of callback functions, or
- by expressing dependencies between tags.
- @c TODO insert illustration f(Ar, Brw, Cr) + ..
- @c DSM
- @node StarPU Data Management Library
- @subsection StarPU Data Management Library
- Because StarPU schedules tasks at runtime, data transfers have to be
- done automatically and ``just-in-time'' between processing units,
- relieving the application programmer from explicit data transfers.
- Moreover, to avoid unnecessary transfers, StarPU keeps data
- where it was last needed, even if was modified there, and it
- allows multiple copies of the same data to reside at the same time on
- several processing units as long as it is not modified.
- @c ---------------------------------------------------------------------
- @c Installing StarPU
- @c ---------------------------------------------------------------------
- @node Installing StarPU
- @chapter Installing StarPU
- @menu
- * Configuration of StarPU::
- * Building and Installing StarPU::
- @end menu
- StarPU can be built and installed by the standard means of the GNU
- autotools. The following chapter is intended to briefly remind how these tools
- can be used to install StarPU.
- @node Configuration of StarPU
- @section Configuration of StarPU
- @menu
- * Generating Makefiles and configuration scripts::
- * Running the configuration::
- @end menu
- @node Generating Makefiles and configuration scripts
- @subsection Generating Makefiles and configuration scripts
- This step is not necessary when using the tarball releases of StarPU. If you
- are using the source code from the svn repository, you first need to generate
- the configure scripts and the Makefiles.
- @example
- % autoreconf -vfi
- @end example
- @node Running the configuration
- @subsection Running the configuration
- @example
- % ./configure
- @end example
- Details about options that are useful to give to @code{./configure} are given in
- @ref{Compilation configuration}.
- @node Building and Installing StarPU
- @section Building and Installing StarPU
- @menu
- * Building::
- * Sanity Checks::
- * Installing::
- @end menu
- @node Building
- @subsection Building
- @example
- % make
- @end example
- @node Sanity Checks
- @subsection Sanity Checks
- In order to make sure that StarPU is working properly on the system, it is also
- possible to run a test suite.
- @example
- % make check
- @end example
- @node Installing
- @subsection Installing
- In order to install StarPU at the location that was specified during
- configuration:
- @example
- % make install
- @end example
- @c ---------------------------------------------------------------------
- @c Using StarPU
- @c ---------------------------------------------------------------------
- @node Using StarPU
- @chapter Using StarPU
- @menu
- * Setting flags for compiling and linking applications::
- * Running a basic StarPU application::
- @end menu
- @node Setting flags for compiling and linking applications
- @section Setting flags for compiling and linking applications
- Compiling and linking an application against StarPU may require to use
- specific flags or libraries (for instance @code{CUDA} or @code{libspe2}).
- To this end, it is possible to use the @code{pkg-config} tool.
- If StarPU was not installed at some standard location, the path of StarPU's
- library must be specified in the @code{PKG_CONFIG_PATH} environment variable so
- that @code{pkg-config} can find it. For example if StarPU was installed in
- @code{$prefix_dir}:
- @example
- % PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$prefix_dir/lib/pkgconfig
- @end example
- The flags required to compile or link against StarPU are then
- accessible with the following commands:
- @example
- % pkg-config --cflags libstarpu # options for the compiler
- % pkg-config --libs libstarpu # options for the linker
- @end example
- @node Running a basic StarPU application
- @section Running a basic StarPU application
- Basic examples using StarPU have been built in the directory
- @code{$prefix_dir/lib/starpu/examples/}. You can for example run the
- example @code{vector_scal}.
- @example
- % $prefix_dir/lib/starpu/examples/vector_scal
- BEFORE : First element was 1.000000
- AFTER First element is 3.140000
- %
- @end example
- @c ---------------------------------------------------------------------
- @c Configuration options
- @c ---------------------------------------------------------------------
- @node Configuring StarPU
- @chapter Configuring StarPU
- @menu
- * Compilation configuration::
- * Execution configuration through environment variables::
- @end menu
- @node Compilation configuration
- @section Compilation configuration
- The following arguments can be given to the @code{configure} script.
- @menu
- * Common configuration::
- * Configuring workers::
- * Advanced configuration::
- @end menu
- @node Common configuration
- @subsection Common configuration
- @menu
- * --enable-debug::
- * --enable-fast::
- * --enable-verbose::
- * --enable-coverage::
- @end menu
- @node --enable-debug
- @subsubsection @code{--enable-debug}
- @table @asis
- @item @emph{Description}:
- Enable debugging messages.
- @end table
- @node --enable-fast
- @subsubsection @code{--enable-fast}
- @table @asis
- @item @emph{Description}:
- Do not enforce assertions, saves a lot of time spent to compute them otherwise.
- @end table
- @node --enable-verbose
- @subsubsection @code{--enable-verbose}
- @table @asis
- @item @emph{Description}:
- Augment the verbosity of the debugging messages.
- @end table
- @node --enable-coverage
- @subsubsection @code{--enable-coverage}
- @table @asis
- @item @emph{Description}:
- Enable flags for the coverage tool.
- @end table
- @node Configuring workers
- @subsection Configuring workers
- @menu
- * --disable-cpu::
- * --enable-maxcudadev::
- * --disable-cuda::
- * --with-cuda-dir::
- * --enable-maxopencldev::
- * --disable-opencl::
- * --with-opencl-dir::
- * --enable-gordon::
- * --with-gordon-dir::
- @end menu
- @node --disable-cpu
- @subsubsection @code{--disable-cpu}
- @table @asis
- @item @emph{Description}:
- Disable the use of CPUs of the machine. Only GPUs etc. will be used.
- @end table
- @node --enable-maxcudadev
- @subsubsection @code{--enable-maxcudadev=<number>}
- @table @asis
- @item @emph{Description}:
- Defines the maximum number of CUDA devices that StarPU will support, then
- available as the @code{STARPU_MAXCUDADEVS} macro.
- @end table
- @node --disable-cuda
- @subsubsection @code{--disable-cuda}
- @table @asis
- @item @emph{Description}:
- Disable the use of CUDA, even if the SDK is detected.
- @end table
- @node --with-cuda-dir
- @subsubsection @code{--with-cuda-dir=<path>}
- @table @asis
- @item @emph{Description}:
- Specify the location of the CUDA SDK resides. This directory should notably contain
- @code{include/cuda.h}.
- @end table
- @node --enable-maxopencldev
- @subsubsection @code{--enable-maxopencldev=<number>}
- @table @asis
- @item @emph{Description}:
- Defines the maximum number of OpenCL devices that StarPU will support, then
- available as the @code{STARPU_MAXOPENCLDEVS} macro.
- @end table
- @node --disable-opencl
- @subsubsection @code{--disable-opencl}
- @table @asis
- @item @emph{Description}:
- Disable the use of OpenCL, even if the SDK is detected.
- @end table
- @node --with-opencl-dir
- @subsubsection @code{--with-opencl-dir=<path>}
- @table @asis
- @item @emph{Description}:
- Specify the location of the OpenCL SDK. This directory should notably contain
- @code{include/CL/cl.h}.
- @end table
- @node --enable-gordon
- @subsubsection @code{--enable-gordon}
- @table @asis
- @item @emph{Description}:
- Enable the use of the Gordon runtime for Cell SPUs.
- @c TODO: rather default to enabled when detected
- @end table
- @node --with-gordon-dir
- @subsubsection @code{--with-gordon-dir=<path>}
- @table @asis
- @item @emph{Description}:
- Specify the location of the Gordon SDK.
- @end table
- @node Advanced configuration
- @subsection Advanced configuration
- @menu
- * --enable-perf-debug::
- * --enable-model-debug::
- * --enable-stats::
- * --enable-maxbuffers::
- * --enable-allocation-cache::
- * --enable-opengl-render::
- * --enable-blas-lib::
- * --with-magma::
- * --with-fxt::
- * --with-perf-model-dir::
- * --with-mpicc::
- * --with-mpi::
- * --with-goto-dir::
- * --with-atlas-dir::
- @end menu
- @node --enable-perf-debug
- @subsubsection @code{--enable-perf-debug}
- @table @asis
- @item @emph{Description}:
- Enable performance debugging.
- @end table
- @node --enable-model-debug
- @subsubsection @code{--enable-model-debug}
- @table @asis
- @item @emph{Description}:
- Enable performance model debugging.
- @end table
- @node --enable-stats
- @subsubsection @code{--enable-stats}
- @table @asis
- @item @emph{Description}:
- Enable statistics.
- @end table
- @node --enable-maxbuffers
- @subsubsection @code{--enable-maxbuffers=<nbuffers>}
- @table @asis
- @item @emph{Description}:
- Define the maximum number of buffers that tasks will be able to take
- as parameters, then available as the @code{STARPU_NMAXBUFS} macro.
- @end table
- @node --enable-allocation-cache
- @subsubsection @code{--enable-allocation-cache}
- @table @asis
- @item @emph{Description}:
- Enable the use of a data allocation cache to avoid the cost of it with
- CUDA. Still experimental.
- @end table
- @node --enable-opengl-render
- @subsubsection @code{--enable-opengl-render}
- @table @asis
- @item @emph{Description}:
- Enable the use of OpenGL for the rendering of some examples.
- @c TODO: rather default to enabled when detected
- @end table
- @node --enable-blas-lib
- @subsubsection @code{--enable-blas-lib=<name>}
- @table @asis
- @item @emph{Description}:
- Specify the blas library to be used by some of the examples. The
- library has to be 'atlas' or 'goto'.
- @end table
- @node --with-magma
- @subsubsection @code{--with-magma=<path>}
- @table @asis
- @item @emph{Description}:
- Specify where magma is installed.
- @end table
- @node --with-fxt
- @subsubsection @code{--with-fxt=<path>}
- @table @asis
- @item @emph{Description}:
- Specify the location of FxT (for generating traces and rendering them
- using ViTE). This directory should notably contain
- @code{include/fxt/fxt.h}.
- @end table
- @node --with-perf-model-dir
- @subsubsection @code{--with-perf-model-dir=<dir>}
- @table @asis
- @item @emph{Description}:
- Specify where performance models should be stored (instead of defaulting to the
- current user's home).
- @end table
- @node --with-mpicc
- @subsubsection @code{--with-mpicc=<path to mpicc>}
- @table @asis
- @item @emph{Description}:
- Specify the location of the @code{mpicc} compiler to be used for starpumpi.
- @c TODO: also just use AC_PROG
- @end table
- @node --with-mpi
- @subsubsection @code{--with-mpi}
- @table @asis
- @item @emph{Description}:
- Enable building libstarpumpi.
- @c TODO: rather just use the availability of mpicc instead of a second option
- @end table
- @node --with-goto-dir
- @subsubsection @code{--with-goto-dir=<dir>}
- @table @asis
- @item @emph{Description}:
- Specify the location of GotoBLAS.
- @end table
- @node --with-atlas-dir
- @subsubsection @code{--with-atlas-dir=<dir>}
- @table @asis
- @item @emph{Description}:
- Specify the location of ATLAS. This directory should notably contain
- @code{include/cblas.h}.
- @end table
- @c ---------------------------------------------------------------------
- @c Environment variables
- @c ---------------------------------------------------------------------
- @node Execution configuration through environment variables
- @section Execution configuration through environment variables
- @menu
- * Workers:: Configuring workers
- * Scheduling:: Configuring the Scheduling engine
- * Misc:: Miscellaneous and debug
- @end menu
- Note: the values given in @code{starpu_conf} structure passed when
- calling @code{starpu_init} will override the values of the environment
- variables.
- @node Workers
- @subsection Configuring workers
- @menu
- * STARPU_NCPUS:: Number of CPU workers
- * STARPU_NCUDA:: Number of CUDA workers
- * STARPU_NOPENCL:: Number of OpenCL workers
- * STARPU_NGORDON:: Number of SPU workers (Cell)
- * STARPU_WORKERS_CPUID:: Bind workers to specific CPUs
- * STARPU_WORKERS_CUDAID:: Select specific CUDA devices
- * STARPU_WORKERS_OPENCLID:: Select specific OpenCL devices
- @end menu
- @node STARPU_NCPUS
- @subsubsection @code{STARPU_NCPUS} -- Number of CPU workers
- @table @asis
- @item @emph{Description}:
- Specify the maximum number of CPU workers. Note that StarPU will not allocate
- more CPUs than there are physical CPUs, and that some CPUs are used to control
- the accelerators.
- @end table
- @node STARPU_NCUDA
- @subsubsection @code{STARPU_NCUDA} -- Number of CUDA workers
- @table @asis
- @item @emph{Description}:
- Specify the maximum number of CUDA devices that StarPU can use. If
- @code{STARPU_NCUDA} is lower than the number of physical devices, it is
- possible to select which CUDA devices should be used by the means of the
- @code{STARPU_WORKERS_CUDAID} environment variable.
- @end table
- @node STARPU_NOPENCL
- @subsubsection @code{STARPU_NOPENCL} -- Number of OpenCL workers
- @table @asis
- @item @emph{Description}:
- OpenCL equivalent of the @code{STARPU_NCUDA} environment variable.
- @end table
- @node STARPU_NGORDON
- @subsubsection @code{STARPU_NGORDON} -- Number of SPU workers (Cell)
- @table @asis
- @item @emph{Description}:
- Specify the maximum number of SPUs that StarPU can use.
- @end table
- @node STARPU_WORKERS_CPUID
- @subsubsection @code{STARPU_WORKERS_CPUID} -- Bind workers to specific CPUs
- @table @asis
- @item @emph{Description}:
- Passing an array of integers (starting from 0) in @code{STARPU_WORKERS_CPUID}
- specifies on which logical CPU the different workers should be
- bound. For instance, if @code{STARPU_WORKERS_CPUID = "1 3 0 2"}, the first
- worker will be bound to logical CPU #1, the second CPU worker will be bound to
- logical CPU #3 and so on. Note that the logical ordering of the CPUs is either
- determined by the OS, or provided by the @code{hwloc} library in case it is
- available.
- Note that the first workers correspond to the CUDA workers, then come the
- OpenCL and the SPU, and finally the CPU workers. For example if
- we have @code{STARPU_NCUDA=1}, @code{STARPU_NOPENCL=1}, @code{STARPU_NCPUS=2}
- and @code{STARPU_WORKERS_CPUID = "0 2 1 3"}, the CUDA device will be controlled
- by logical CPU #0, the OpenCL device will be controlled by logical CPU #2, and
- the logical CPUs #1 and #3 will be used by the CPU workers.
- If the number of workers is larger than the array given in
- @code{STARPU_WORKERS_CPUID}, the workers are bound to the logical CPUs in a
- round-robin fashion: if @code{STARPU_WORKERS_CPUID = "0 1"}, the first and the
- third (resp. second and fourth) workers will be put on CPU #0 (resp. CPU #1).
- @end table
- @node STARPU_WORKERS_CUDAID
- @subsubsection @code{STARPU_WORKERS_CUDAID} -- Select specific CUDA devices
- @table @asis
- @item @emph{Description}:
- Similarly to the @code{STARPU_WORKERS_CPUID} environment variable, it is
- possible to select which CUDA devices should be used by StarPU. On a machine
- equipped with 4 GPUs, setting @code{STARPU_WORKERS_CUDAID = "1 3"} and
- @code{STARPU_NCUDA=2} specifies that 2 CUDA workers should be created, and that
- they should use CUDA devices #1 and #3 (the logical ordering of the devices is
- the one reported by CUDA).
- @end table
- @node STARPU_WORKERS_OPENCLID
- @subsubsection @code{STARPU_WORKERS_OPENCLID} -- Select specific OpenCL devices
- @table @asis
- @item @emph{Description}:
- OpenCL equivalent of the @code{STARPU_WORKERS_CUDAID} environment variable.
- @end table
- @node Scheduling
- @subsection Configuring the Scheduling engine
- @menu
- * STARPU_SCHED:: Scheduling policy
- * STARPU_CALIBRATE:: Calibrate performance models
- * STARPU_PREFETCH:: Use data prefetch
- * STARPU_SCHED_ALPHA:: Computation factor
- * STARPU_SCHED_BETA:: Communication factor
- @end menu
- @node STARPU_SCHED
- @subsubsection @code{STARPU_SCHED} -- Scheduling policy
- @table @asis
- @item @emph{Description}:
- This chooses between the different scheduling policies proposed by StarPU: work
- random, stealing, greedy, with performance models, etc.
- Use @code{STARPU_SCHED=help} to get the list of available schedulers.
- @end table
- @node STARPU_CALIBRATE
- @subsubsection @code{STARPU_CALIBRATE} -- Calibrate performance models
- @table @asis
- @item @emph{Description}:
- If this variable is set to 1, the performance models are calibrated during
- the execution. If it is set to 2, the previous values are dropped to restart
- calibration from scratch.
- Note: this currently only applies to dm and dmda scheduling policies.
- @end table
- @node STARPU_PREFETCH
- @subsubsection @code{STARPU_PREFETCH} -- Use data prefetch
- @table @asis
- @item @emph{Description}:
- If this variable is set, data prefetching will be enabled, that is when a task is
- scheduled to be executed e.g. on a GPU, StarPU will request an asynchronous
- transfer in advance, so that data is already present on the GPU when the task
- starts. As a result, computation and data transfers are overlapped.
- @end table
- @node STARPU_SCHED_ALPHA
- @subsubsection @code{STARPU_SCHED_ALPHA} -- Computation factor
- @table @asis
- @item @emph{Description}:
- To estimate the cost of a task StarPU takes into account the estimated
- computation time (obtained thanks to performance models). The alpha factor is
- the coefficient to be applied to it before adding it to the communication part.
- @end table
- @node STARPU_SCHED_BETA
- @subsubsection @code{STARPU_SCHED_BETA} -- Communication factor
- @table @asis
- @item @emph{Description}:
- To estimate the cost of a task StarPU takes into account the estimated
- data transfer time (obtained thanks to performance models). The beta factor is
- the coefficient to be applied to it before adding it to the computation part.
- @end table
- @node Misc
- @subsection Miscellaneous and debug
- @menu
- * STARPU_LOGFILENAME:: Select debug file name
- @end menu
- @node STARPU_LOGFILENAME
- @subsubsection @code{STARPU_LOGFILENAME} -- Select debug file name
- @table @asis
- @item @emph{Description}:
- This variable specify in which file the debugging output should be saved to.
- @end table
- @c ---------------------------------------------------------------------
- @c StarPU API
- @c ---------------------------------------------------------------------
- @node StarPU API
- @chapter StarPU API
- @menu
- * Initialization and Termination:: Initialization and Termination methods
- * Workers' Properties:: Methods to enumerate workers' properties
- * Data Library:: Methods to manipulate data
- * Codelets and Tasks:: Methods to construct tasks
- * Tags:: Task dependencies
- * CUDA extensions:: CUDA extensions
- * OpenCL extensions:: OpenCL extensions
- * Cell extensions:: Cell extensions
- * Miscellaneous helpers::
- @end menu
- @node Initialization and Termination
- @section Initialization and Termination
- @menu
- * starpu_init:: Initialize StarPU
- * struct starpu_conf:: StarPU runtime configuration
- * starpu_shutdown:: Terminate StarPU
- @end menu
- @node starpu_init
- @subsection @code{starpu_init} -- Initialize StarPU
- @table @asis
- @item @emph{Description}:
- This is StarPU initialization method, which must be called prior to any other
- StarPU call. It is possible to specify StarPU's configuration (e.g. scheduling
- policy, number of cores, ...) by passing a non-null argument. Default
- configuration is used if the passed argument is @code{NULL}.
- @item @emph{Return value}:
- Upon successful completion, this function returns 0. Otherwise, @code{-ENODEV}
- indicates that no worker was available (so that StarPU was not initialized).
- @item @emph{Prototype}:
- @code{int starpu_init(struct starpu_conf *conf);}
- @end table
- @node struct starpu_conf
- @subsection @code{struct starpu_conf} -- StarPU runtime configuration
- @table @asis
- @item @emph{Description}:
- This structure is passed to the @code{starpu_init} function in order
- to configure StarPU.
- When the default value is used, StarPU automatically selects the number
- of processing units and takes the default scheduling policy. This parameter
- overwrites the equivalent environment variables.
- @item @emph{Fields}:
- @table @asis
- @item @code{sched_policy_name} (default = NULL):
- This is the name of the scheduling policy. This can also be specified with the
- @code{STARPU_SCHED} environment variable.
- @item @code{sched_policy} (default = NULL):
- This is the definition of the scheduling policy. This field is ignored
- if @code{sched_policy_name} is set.
- @item @code{ncpus} (default = -1):
- This is the maximum number of CPU cores that StarPU can use. This can also be
- specified with the @code{STARPU_NCPUS} environment variable.
- @item @code{ncuda} (default = -1):
- This is the maximum number of CUDA devices that StarPU can use. This can also be
- specified with the @code{STARPU_NCUDA} environment variable.
- @item @code{nopencl} (default = -1):
- This is the maximum number of OpenCL devices that StarPU can use. This can also be
- specified with the @code{STARPU_NOPENCL} environment variable.
- @item @code{nspus} (default = -1):
- This is the maximum number of Cell SPUs that StarPU can use. This can also be
- specified with the @code{STARPU_NGORDON} environment variable.
- @item @code{use_explicit_workers_bindid} (default = 0)
- @item @code{workers_bindid[STARPU_NMAXWORKERS]}
- @item @code{use_explicit_workers_cuda_gpuid} (default = 0)
- @item @code{workers_cuda_gpuid[STARPU_NMAXWORKERS]}
- @item @code{use_explicit_workers_opencl_gpuid} (default = 0)
- @item @code{workers_opencl_gpuid[STARPU_NMAXWORKERS]}:
- These fields are explained in @ref{STARPU_WORKERS_CPUID}.
- @item @code{calibrate} (default = 0):
- If this flag is set, StarPU will calibrate the performance models when
- executing tasks. This can also be specified with the @code{STARPU_CALIBRATE}
- environment variable.
- @end table
- @end table
- @node starpu_shutdown
- @subsection @code{starpu_shutdown} -- Terminate StarPU
- @table @asis
- @item @emph{Description}:
- This is StarPU termination method. It must be called at the end of the
- application: statistics and other post-mortem debugging information are not
- guaranteed to be available until this method has been called.
- @item @emph{Prototype}:
- @code{void starpu_shutdown(void);}
- @end table
- @node Workers' Properties
- @section Workers' Properties
- @menu
- * starpu_worker_get_count:: Get the number of processing units
- * starpu_cpu_worker_get_count:: Get the number of CPU controlled by StarPU
- * starpu_cuda_worker_get_count:: Get the number of CUDA devices controlled by StarPU
- * starpu_opencl_worker_get_count:: Get the number of OpenCL devices controlled by StarPU
- * starpu_spu_worker_get_count:: Get the number of Cell SPUs controlled by StarPU
- * starpu_worker_get_id:: Get the identifier of the current worker
- * starpu_worker_get_type:: Get the type of processing unit associated to a worker
- * starpu_worker_get_name:: Get the name of a worker
- @end menu
- @node starpu_worker_get_count
- @subsection @code{starpu_worker_get_count} -- Get the number of processing units
- @table @asis
- @item @emph{Description}:
- This function returns the number of workers (i.e. processing units executing
- StarPU tasks). The returned value should be at most @code{STARPU_NMAXWORKERS}.
- @item @emph{Prototype}:
- @code{unsigned starpu_worker_get_count(void);}
- @end table
- @node starpu_cpu_worker_get_count
- @subsection @code{starpu_cpu_worker_get_count} -- Get the number of CPU controlled by StarPU
- @table @asis
- @item @emph{Description}:
- This function returns the number of CPUs controlled by StarPU. The returned
- value should be at most @code{STARPU_NMAXCPUS}.
- @item @emph{Prototype}:
- @code{unsigned starpu_cpu_worker_get_count(void);}
- @end table
- @node starpu_cuda_worker_get_count
- @subsection @code{starpu_cuda_worker_get_count} -- Get the number of CUDA devices controlled by StarPU
- @table @asis
- @item @emph{Description}:
- This function returns the number of CUDA devices controlled by StarPU. The returned
- value should be at most @code{STARPU_MAXCUDADEVS}.
- @item @emph{Prototype}:
- @code{unsigned starpu_cuda_worker_get_count(void);}
- @end table
- @node starpu_opencl_worker_get_count
- @subsection @code{starpu_opencl_worker_get_count} -- Get the number of OpenCL devices controlled by StarPU
- @table @asis
- @item @emph{Description}:
- This function returns the number of OpenCL devices controlled by StarPU. The returned
- value should be at most @code{STARPU_MAXOPENCLDEVS}.
- @item @emph{Prototype}:
- @code{unsigned starpu_opencl_worker_get_count(void);}
- @end table
- @node starpu_spu_worker_get_count
- @subsection @code{starpu_spu_worker_get_count} -- Get the number of Cell SPUs controlled by StarPU
- @table @asis
- @item @emph{Description}:
- This function returns the number of Cell SPUs controlled by StarPU.
- @item @emph{Prototype}:
- @code{unsigned starpu_opencl_worker_get_count(void);}
- @end table
- @node starpu_worker_get_id
- @subsection @code{starpu_worker_get_id} -- Get the identifier of the current worker
- @table @asis
- @item @emph{Description}:
- This function returns the identifier of the worker associated to the calling
- thread. The returned value is either -1 if the current context is not a StarPU
- worker (i.e. when called from the application outside a task or a callback), or
- an integer between 0 and @code{starpu_worker_get_count() - 1}.
- @item @emph{Prototype}:
- @code{int starpu_worker_get_id(void);}
- @end table
- @node starpu_worker_get_type
- @subsection @code{starpu_worker_get_type} -- Get the type of processing unit associated to a worker
- @table @asis
- @item @emph{Description}:
- This function returns the type of worker associated to an identifier (as
- returned by the @code{starpu_worker_get_id} function). The returned value
- indicates the architecture of the worker: @code{STARPU_CPU_WORKER} for a CPU
- core, @code{STARPU_CUDA_WORKER} for a CUDA device,
- @code{STARPU_OPENCL_WORKER} for a OpenCL device, and
- @code{STARPU_GORDON_WORKER} for a Cell SPU. The value returned for an invalid
- identifier is unspecified.
- @item @emph{Prototype}:
- @code{enum starpu_archtype starpu_worker_get_type(int id);}
- @end table
- @node starpu_worker_get_name
- @subsection @code{starpu_worker_get_name} -- Get the name of a worker
- @table @asis
- @item @emph{Description}:
- StarPU associates a unique human readable string to each processing unit. This
- function copies at most the @code{maxlen} first bytes of the unique string
- associated to a worker identified by its identifier @code{id} into the
- @code{dst} buffer. The caller is responsible for ensuring that the @code{dst}
- is a valid pointer to a buffer of @code{maxlen} bytes at least. Calling this
- function on an invalid identifier results in an unspecified behaviour.
- @item @emph{Prototype}:
- @code{void starpu_worker_get_name(int id, char *dst, size_t maxlen);}
- @end table
- @node Data Library
- @section Data Library
- This section describes the data management facilities provided by StarPU.
- TODO: We show how to use existing data interfaces in [ref], but developers can
- design their own data interfaces if required.
- @menu
- * starpu_data_handle:: StarPU opaque data handle
- * void *interface:: StarPU data interface
- * starpu_XXX_data_register::
- * starpu_data_unregister::
- @end menu
- @node starpu_data_handle
- @subsection @code{starpu_data_handle} -- StarPU opaque data handle
- @table @asis
- @item @emph{Description}:
- StarPU uses @code{starpu_data_handle} as an opaque handle to manage a piece of
- data. Once a piece of data has been registered to StarPU, it is associated to a
- @code{starpu_data_handle} which keeps track of the state of the piece of data
- over the entire machine, so that we can maintain data consistency and locate
- data replicates for instance.
- @end table
- @node void *interface
- @subsection @code{void *interface} -- StarPU data interface
- @table @asis
- @item @emph{Description}:
- Data management is done at a high-level in StarPU: rather than accessing a mere
- list of contiguous buffers, the tasks may manipulate data that are described by
- a high-level construct which we call data interface.
- TODO
- @end table
- @node starpu_XXX_data_register
- @subsection @code{starpu_XXX_data_register} -- Register data to StarPU
- @table @asis
- @end table
- @node starpu_data_unregister
- @subsection @code{starpu_data_unregister} -- Unregister data from StarPU
- @table @asis
- @item @emph{Description}:
- @item @emph{Prototype}:
- @code{void starpu_data_unregister(starpu_data_handle handle);}
- @end table
- @c starpu_worker_get_memory_node TODO
- @c
- @c user interaction with the DSM
- @c void starpu_data_sync_with_mem(struct starpu_data_state_t *state);
- @c void starpu_notify_data_modification(struct starpu_data_state_t *state, uint32_t modifying_node);
- @node Codelets and Tasks
- @section Codelets and Tasks
- @menu
- * struct starpu_codelet:: StarPU codelet structure
- * struct starpu_task:: StarPU task structure
- * starpu_task_init:: Initialize a Task
- * starpu_task_create:: Allocate and Initialize a Task
- * starpu_task_deinit:: Release all the resources used by a Task
- * starpu_task_destroy:: Destroy a dynamically allocated Task
- * starpu_task_wait:: Wait for the termination of a Task
- * starpu_task_submit:: Submit a Task
- * starpu_task_wait_for_all:: Wait for the termination of all Tasks
- @end menu
- @node struct starpu_codelet
- @subsection @code{struct starpu_codelet} -- StarPU codelet structure
- @table @asis
- @item @emph{Description}:
- The codelet structure describes a kernel that is possibly implemented on
- various targets.
- @item @emph{Fields}:
- @table @asis
- @item @code{where}:
- 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.
- @item @code{cpu_func} (optional):
- Is a function pointer to the CPU implementation of the codelet. Its prototype
- must be: @code{void cpu_func(void *buffers[], void *cl_arg)}. The first
- 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_func} 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):
- Is a function pointer to the CUDA implementation of the codelet. @emph{This
- must be a host-function written in the CUDA runtime API}. Its prototype must
- be: @code{void cuda_func(void *buffers[], void *cl_arg);}. The @code{cuda_func}
- field is ignored if @code{STARPU_CUDA} does not appear in the @code{where}
- field, it must be non-null otherwise.
- @item @code{opencl_func} (optional):
- Is a function pointer to the OpenCL implementation of the codelet. Its
- prototype must be:
- @code{void opencl_func(starpu_data_interface_t *descr, void *arg);}.
- This pointer 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 is the index of the Cell SPU implementation within the Gordon library.
- TODO
- @item @code{nbuffers}:
- Specifies the number of arguments taken by the codelet. These arguments are
- managed by the DSM and are accessed from the @code{void *buffers[]}
- array. The constant argument passed with the @code{cl_arg} field of the
- @code{starpu_task} structure is not counted in this number. This value should
- not be above @code{STARPU_NMAXBUFS}.
- @item @code{model} (optional):
- This is a pointer to the performance model associated to this codelet. This
- optional field is ignored when set to @code{NULL}. TODO
- @end table
- @end table
- @node struct starpu_task
- @subsection @code{struct starpu_task} -- StarPU task structure
- @table @asis
- @item @emph{Description}:
- The @code{starpu_task} structure describes a task that can be offloaded on the various
- processing units managed by StarPU. It instantiates a codelet. It can either be
- allocated dynamically with the @code{starpu_task_create} method, or declared
- statically. In the latter case, the programmer has to zero the
- @code{starpu_task} structure and to fill the different fields properly. The
- indicated default values correspond to the configuration of a task allocated
- with @code{starpu_task_create}.
- @item @emph{Fields}:
- @table @asis
- @item @code{cl}:
- Is a pointer to the corresponding @code{starpu_codelet} data structure. This
- describes where the kernel should be executed, and supplies the appropriate
- implementations. When set to @code{NULL}, no code is executed during the tasks,
- such empty tasks can be useful for synchronization purposes.
- @item @code{buffers}:
- TODO
- @item @code{cl_arg} (optional) (default = NULL):
- This pointer is passed to the codelet through the second argument
- of the codelet implementation (e.g. @code{cpu_func} or @code{cuda_func}).
- In the specific case of the Cell processor, see the @code{cl_arg_size}
- argument.
- @item @code{cl_arg_size} (optional, Cell specific):
- In the case of the Cell processor, the @code{cl_arg} pointer is not directly
- given to the SPU function. A buffer of size @code{cl_arg_size} is allocated on
- the SPU. This buffer is then filled with the @code{cl_arg_size} bytes starting
- at address @code{cl_arg}. In this case, the argument given to the SPU codelet
- is therefore not the @code{cl_arg} pointer, but the address of the buffer in
- local store (LS) instead. This field is ignored for CPU, CUDA and OpenCL
- codelets.
- @item @code{callback_func} (optional) (default = @code{NULL}):
- This is a function pointer of prototype @code{void (*f)(void *)} which
- specifies a possible callback. If this pointer is non-null, the callback
- function is executed @emph{on the host} after the execution of the task. The
- callback is passed the value contained in the @code{callback_arg} field. No
- callback is executed if the field is set to @code{NULL}.
- @item @code{callback_arg} (optional) (default = @code{NULL}):
- This is the pointer passed to the callback function. This field is ignored if
- the @code{callback_func} is set to @code{NULL}.
- @item @code{use_tag} (optional) (default = 0):
- If set, this flag indicates that the task should be associated with the tag
- contained in the @code{tag_id} field. Tag allow the application to synchronize
- with the task and to express task dependencies easily.
- @item @code{tag_id}:
- This fields contains the tag associated to the task if the @code{use_tag} field
- was set, it is ignored otherwise.
- @item @code{synchronous}:
- If this flag is set, the @code{starpu_task_submit} function is blocking and
- returns only when the task has been executed (or if no worker is able to
- process the task). Otherwise, @code{starpu_task_submit} returns immediately.
- @item @code{priority} (optional) (default = @code{STARPU_DEFAULT_PRIO}):
- This field indicates a level of priority for the task. This is an integer value
- that must be set between @code{STARPU_MIN_PRIO} (for the least important
- tasks) and @code{STARPU_MAX_PRIO} (for the most important tasks) included.
- Default priority is @code{STARPU_DEFAULT_PRIO}. Scheduling strategies that
- take priorities into account can use this parameter to take better scheduling
- decisions, but the scheduling policy may also ignore it.
- @item @code{execute_on_a_specific_worker} (default = 0):
- If this flag is set, StarPU will bypass the scheduler and directly affect this
- task to the worker specified by the @code{workerid} field.
- @item @code{workerid} (optional):
- If the @code{execute_on_a_specific_worker} field is set, this field indicates
- which is the identifier of the worker that should process this task (as
- returned by @code{starpu_worker_get_id}). This field is ignored if
- @code{execute_on_a_specific_worker} field is set to 0.
- @item @code{detach} (optional) (default = 1):
- If this flag is set, it is not possible to synchronize with the task
- by the means of @code{starpu_task_wait} later on. Internal data structures
- are only guaranteed to be freed once @code{starpu_task_wait} is called if the
- flag is not set.
- @item @code{destroy} (optional) (default = 1):
- If this flag is set, the task structure will automatically be freed, either
- after the execution of the callback if the task is detached, or during
- @code{starpu_task_wait} otherwise. If this flag is not set, dynamically
- allocated data structures will not be freed until @code{starpu_task_destroy} is
- called explicitly. Setting this flag for a statically allocated task structure
- will result in undefined behaviour.
- @end table
- @end table
- @node starpu_task_init
- @subsection @code{starpu_task_init} -- Initialize a Task
- @table @asis
- @item @emph{Description}:
- Initialize a task structure with default values. This function is implicitly
- called by @code{starpu_task_create}. By default, tasks initialized with
- @code{starpu_task_init} must be deinitialized explicitly with
- @code{starpu_task_deinit}. Tasks can also be initialized statically, using the
- constant @code{STARPU_TASK_INITIALIZER}.
- @item @emph{Prototype}:
- @code{void starpu_task_init(struct starpu_task *task);}
- @end table
- @node starpu_task_create
- @subsection @code{starpu_task_create} -- Allocate and Initialize a Task
- @table @asis
- @item @emph{Description}:
- Allocate a task structure and initialize it with default values. Tasks
- allocated dynamically with @code{starpu_task_create} are automatically freed when the
- task is terminated. If the destroy flag is explicitly unset, the resources used
- by the task are freed by calling
- @code{starpu_task_destroy}.
- @item @emph{Prototype}:
- @code{struct starpu_task *starpu_task_create(void);}
- @end table
- @node starpu_task_deinit
- @subsection @code{starpu_task_deinit} -- Release all the resources used by a Task
- @table @asis
- @item @emph{Description}:
- Release all the structures automatically allocated to execute the task. This is
- called automatically by @code{starpu_task_destroy}, but the task structure itself is not
- freed. This should be used for statically allocated tasks for instance.
- @item @emph{Prototype}:
- @code{void starpu_task_deinit(struct starpu_task *task);}
- @end table
- @node starpu_task_destroy
- @subsection @code{starpu_task_destroy} -- Destroy a dynamically allocated Task
- @table @asis
- @item @emph{Description}:
- Free the resource allocated during @code{starpu_task_create}. This function can be
- called automatically after the execution of a task by setting the
- @code{destroy} flag of the @code{starpu_task} structure (default behaviour).
- Calling this function on a statically allocated task results in an undefined
- behaviour.
- @item @emph{Prototype}:
- @code{void starpu_task_destroy(struct starpu_task *task);}
- @end table
- @node starpu_task_wait
- @subsection @code{starpu_task_wait} -- Wait for the termination of a Task
- @table @asis
- @item @emph{Description}:
- This function blocks until the task has been executed. It is not possible to
- synchronize with a task more than once. It is not possible to wait for
- synchronous or detached tasks.
- @item @emph{Return value}:
- Upon successful completion, this function returns 0. Otherwise, @code{-EINVAL}
- indicates that the specified task was either synchronous or detached.
- @item @emph{Prototype}:
- @code{int starpu_task_wait(struct starpu_task *task);}
- @end table
- @node starpu_task_submit
- @subsection @code{starpu_task_submit} -- Submit a Task
- @table @asis
- @item @emph{Description}:
- This function submits a task to StarPU. Calling this function does
- not mean that the task will be executed immediately as there can be data or task
- (tag) dependencies that are not fulfilled yet: StarPU will take care of
- scheduling this task with respect to such dependencies.
- This function returns immediately if the @code{synchronous} field of the
- @code{starpu_task} structure was set to 0, and block until the termination of
- the task otherwise. It is also possible to synchronize the application with
- asynchronous tasks by the means of tags, using the @code{starpu_tag_wait}
- function for instance.
- @item @emph{Return value}:
- In case of success, this function returns 0, a return value of @code{-ENODEV}
- means that there is no worker able to process this task (e.g. there is no GPU
- available and this task is only implemented for CUDA devices).
- @item @emph{Prototype}:
- @code{int starpu_task_submit(struct starpu_task *task);}
- @end table
- @node starpu_task_wait_for_all
- @subsection @code{starpu_task_wait_for_all} -- Wait for the termination of all Tasks
- @table @asis
- @item @emph{Description}:
- This function blocks until all the tasks that were submitted are terminated.
- @item @emph{Prototype}:
- @code{void starpu_task_wait_for_all(void);}
- @end table
- @c Callbacks : what can we put in callbacks ?
- @node Tags
- @section Tags
- @menu
- * starpu_tag_t:: Task identifier
- * starpu_tag_declare_deps:: Declare the Dependencies of a Tag
- * starpu_tag_declare_deps_array:: Declare the Dependencies of a Tag
- * starpu_tag_wait:: Block until a Tag is terminated
- * starpu_tag_wait_array:: Block until a set of Tags is terminated
- * starpu_tag_remove:: Destroy a Tag
- * starpu_tag_notify_from_apps:: Feed a tag explicitly
- @end menu
- @node starpu_tag_t
- @subsection @code{starpu_tag_t} -- Task identifier
- @table @asis
- @item @emph{Description}:
- It is possible to associate a task with a unique ``tag'' and to express
- dependencies between tasks by the means of those tags. To do so, fill the
- @code{tag_id} field of the @code{starpu_task} structure with a tag number (can
- be arbitrary) and set the @code{use_tag} field to 1.
- If @code{starpu_tag_declare_deps} is called with this tag number, the task will
- not be started until the tasks which holds the declared dependency tags are
- completed.
- @end table
- @node starpu_tag_declare_deps
- @subsection @code{starpu_tag_declare_deps} -- Declare the Dependencies of a Tag
- @table @asis
- @item @emph{Description}:
- Specify the dependencies of the task identified by tag @code{id}. The first
- argument specifies the tag which is configured, the second argument gives the
- number of tag(s) on which @code{id} depends. The following arguments are the
- tags which have to be terminated to unlock the task.
- This function must be called before the associated task is submitted to StarPU
- with @code{starpu_task_submit}.
- @item @emph{Remark}
- Because of the variable arity of @code{starpu_tag_declare_deps}, note that the
- last arguments @emph{must} be of type @code{starpu_tag_t}: constant values
- typically need to be explicitly casted. Using the
- @code{starpu_tag_declare_deps_array} function avoids this hazard.
- @item @emph{Prototype}:
- @code{void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);}
- @item @emph{Example}:
- @cartouche
- @example
- /* Tag 0x1 depends on tags 0x32 and 0x52 */
- starpu_tag_declare_deps((starpu_tag_t)0x1,
- 2, (starpu_tag_t)0x32, (starpu_tag_t)0x52);
- @end example
- @end cartouche
- @end table
- @node starpu_tag_declare_deps_array
- @subsection @code{starpu_tag_declare_deps_array} -- Declare the Dependencies of a Tag
- @table @asis
- @item @emph{Description}:
- This function is similar to @code{starpu_tag_declare_deps}, except that its
- does not take a variable number of arguments but an array of tags of size
- @code{ndeps}.
- @item @emph{Prototype}:
- @code{void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);}
- @item @emph{Example}:
- @cartouche
- @example
- /* Tag 0x1 depends on tags 0x32 and 0x52 */
- starpu_tag_t tag_array[2] = @{0x32, 0x52@};
- starpu_tag_declare_deps_array((starpu_tag_t)0x1, 2, tag_array);
- @end example
- @end cartouche
- @end table
- @node starpu_tag_wait
- @subsection @code{starpu_tag_wait} -- Block until a Tag is terminated
- @table @asis
- @item @emph{Description}:
- This function blocks until the task associated to tag @code{id} has been
- executed. This is a blocking call which must therefore not be called within
- tasks or callbacks, but only from the application directly. It is possible to
- synchronize with the same tag multiple times, as long as the
- @code{starpu_tag_remove} function is not called. Note that it is still
- possible to synchronize with a tag associated to a task which @code{starpu_task}
- data structure was freed (e.g. if the @code{destroy} flag of the
- @code{starpu_task} was enabled).
- @item @emph{Prototype}:
- @code{void starpu_tag_wait(starpu_tag_t id);}
- @end table
- @node starpu_tag_wait_array
- @subsection @code{starpu_tag_wait_array} -- Block until a set of Tags is terminated
- @table @asis
- @item @emph{Description}:
- This function is similar to @code{starpu_tag_wait} except that it blocks until
- @emph{all} the @code{ntags} tags contained in the @code{id} array are
- terminated.
- @item @emph{Prototype}:
- @code{void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);}
- @end table
- @node starpu_tag_remove
- @subsection @code{starpu_tag_remove} -- Destroy a Tag
- @table @asis
- @item @emph{Description}:
- This function releases the resources associated to tag @code{id}. It can be
- called once the corresponding task has been executed and when there is
- no other tag that depend on this tag anymore.
- @item @emph{Prototype}:
- @code{void starpu_tag_remove(starpu_tag_t id);}
- @end table
- @node starpu_tag_notify_from_apps
- @subsection @code{starpu_tag_notify_from_apps} -- Feed a Tag explicitly
- @table @asis
- @item @emph{Description}:
- This function explicitly unlocks tag @code{id}. It may be useful in the
- case of applications which execute part of their computation outside StarPU
- tasks (e.g. third-party libraries). It is also provided as a
- convenient tool for the programmer, for instance to entirely construct the task
- DAG before actually giving StarPU the opportunity to execute the tasks.
- @item @emph{Prototype}:
- @code{void starpu_tag_notify_from_apps(starpu_tag_t id);}
- @end table
- @node CUDA extensions
- @section CUDA extensions
- @c void starpu_data_malloc_pinned_if_possible(float **A, size_t dim);
- @c starpu_helper_cublas_init TODO
- @c starpu_helper_cublas_shutdown TODO
- @menu
- * starpu_cuda_get_local_stream:: Get current worker's CUDA stream
- * starpu_helper_cublas_init:: Initialize CUBLAS on every CUDA device
- * starpu_helper_cublas_shutdown:: Deinitialize CUBLAS on every CUDA device
- @end menu
- @node starpu_cuda_get_local_stream
- @subsection @code{starpu_cuda_get_local_stream} -- Get current worker's CUDA stream
- @table @asis
- @item @emph{Description}:
- StarPU provides a stream for every CUDA device controlled by StarPU. This
- function is only provided for convenience so that programmers can easily use
- asynchronous operations within codelets without having to create a stream by
- hand. Note that the application is not forced to use the stream provided by
- @code{starpu_cuda_get_local_stream} and may also create its own streams.
- @item @emph{Prototype}:
- @code{cudaStream_t *starpu_cuda_get_local_stream(void);}
- @end table
- @node starpu_helper_cublas_init
- @subsection @code{starpu_helper_cublas_init} -- Initialize CUBLAS on every CUDA device
- @table @asis
- @item @emph{Description}:
- The CUBLAS library must be initialized prior to any CUBLAS call. Calling
- @code{starpu_helper_cublas_init} will initialize CUBLAS on every CUDA device
- controlled by StarPU. This call blocks until CUBLAS has been properly
- initialized on every device.
- @item @emph{Prototype}:
- @code{void starpu_helper_cublas_init(void);}
- @end table
- @node starpu_helper_cublas_shutdown
- @subsection @code{starpu_helper_cublas_shutdown} -- Deinitialize CUBLAS on every CUDA device
- @table @asis
- @item @emph{Description}:
- This function synchronously deinitializes the CUBLAS library on every CUDA device.
- @item @emph{Prototype}:
- @code{void starpu_helper_cublas_shutdown(void);}
- @end table
- @node OpenCL extensions
- @section OpenCL extensions
- @menu
- * Enabling OpenCL:: Enabling OpenCL
- * Compiling OpenCL codelets:: Compiling OpenCL codelets
- @end menu
- @node Enabling OpenCL
- @subsection Enabling OpenCL
- On GPU devices which can run both CUDA and OpenCL, CUDA will be
- enabled by default. To enable OpenCL, you need either to disable CUDA
- when configuring StarPU:
- @example
- % ./configure --disable-cuda
- @end example
- or when running applications:
- @example
- % STARPU_NCUDA=0 ./application
- @end example
- OpenCL will automatically be started on any device not yet used by
- CUDA. So on a machine running 4 GPUS, it is therefore possible to
- enable CUDA on 2 devices, and OpenCL on the 2 other devices by doing
- so:
- @example
- % STARPU_NCUDA=2 ./application
- @end example
- @node Compiling OpenCL codelets
- @subsection Compiling OpenCL codelets
- TODO
- @node Cell extensions
- @section Cell extensions
- nothing yet.
- @node Miscellaneous helpers
- @section Miscellaneous helpers
- @menu
- * starpu_execute_on_each_worker:: Execute a function on a subset of workers
- @end menu
- @node starpu_execute_on_each_worker
- @subsection @code{starpu_execute_on_each_worker} -- Execute a function on a subset of workers
- @table @asis
- @item @emph{Description}:
- When calling this method, the offloaded function specified by the first argument is
- executed by every StarPU worker that may execute the function.
- The second argument is passed to the offloaded function.
- The last argument specifies on which types of processing units the function
- should be executed. Similarly to the @code{where} field of the
- @code{starpu_codelet} structure, it is possible to specify that the function
- should be executed on every CUDA device and every CPU by passing
- @code{STARPU_CPU|STARPU_CUDA}.
- This function blocks until the function has been executed on every appropriate
- processing units, so that it may not be called from a callback function for
- instance.
- @item @emph{Prototype}:
- @code{void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);}
- @end table
- @c ---------------------------------------------------------------------
- @c Basic Examples
- @c ---------------------------------------------------------------------
- @node Basic Examples
- @chapter Basic Examples
- @menu
- * Compiling and linking options::
- * Hello World:: Submitting Tasks
- * Scaling a Vector:: Manipulating Data
- * Vector Scaling on an Hybrid CPU/GPU Machine:: Handling Heterogeneous Architectures
- @end menu
- @node Compiling and linking options
- @section Compiling and linking options
- Let's suppose StarPU has been installed in the directory
- @code{$STARPU_DIR}. As explained in @ref{Setting flags for compiling and linking applications},
- the variable @code{PKG_CONFIG_PATH} needs to be set. It is also
- necessary to set the variable @code{LD_LIBRARY_PATH} to locate dynamic
- libraries at runtime.
- @example
- % PKG_CONFIG_PATH=$STARPU_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
- % LD_LIBRARY_PATH=$STARPU_DIR/lib:$LD_LIBRARY_PATH
- @end example
- The Makefile could for instance contain the following lines to define which
- options must be given to the compiler and to the linker:
- @cartouche
- @example
- CFLAGS += $$(pkg-config --cflags libstarpu)
- LDFLAGS += $$(pkg-config --libs libstarpu)
- @end example
- @end cartouche
- @node Hello World
- @section Hello World
- @menu
- * Required Headers::
- * Defining a Codelet::
- * Submitting a Task::
- * Execution of Hello World::
- @end menu
- In this section, we show how to implement a simple program that submits a task to StarPU.
- @node Required Headers
- @subsection Required Headers
- The @code{starpu.h} header should be included in any code using StarPU.
- @cartouche
- @example
- #include <starpu.h>
- @end example
- @end cartouche
- @node Defining a Codelet
- @subsection Defining a Codelet
- @cartouche
- @example
- void cpu_func(void *buffers[], void *cl_arg)
- @{
- float *array = cl_arg;
- printf("Hello world (array = @{%f, %f@} )\n", array[0], array[1]);
- @}
- starpu_codelet cl =
- @{
- .where = STARPU_CPU,
- .cpu_func = cpu_func,
- .nbuffers = 0
- @};
- @end example
- @end cartouche
- A codelet is a structure that represents a computational kernel. Such a codelet
- may contain an implementation of the same kernel on different architectures
- (e.g. CUDA, Cell's SPU, x86, ...).
- The @code{nbuffers} field specifies the number of data buffers that are
- manipulated by the codelet: here the codelet does not access or modify any data
- that is controlled by our data management library. Note that the argument
- passed to the codelet (the @code{cl_arg} field of the @code{starpu_task}
- structure) does not count as a buffer since it is not managed by our data
- management library.
- @c TODO need a crossref to the proper description of "where" see bla for more ...
- 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).
- When a CPU core executes a codelet, it calls the @code{cpu_func} function,
- which @emph{must} have the following prototype:
- @code{void (*cpu_func)(void *buffers[], void *cl_arg);}
- In this example, we can ignore the first argument of this function which gives a
- description of the input and output buffers (e.g. the size and the location of
- the matrices). The second argument is a pointer to a buffer passed as an
- argument to the codelet by the means of the @code{cl_arg} field of the
- @code{starpu_task} structure.
- @c TODO rewrite so that it is a little clearer ?
- Be aware that this may be a pointer to a
- @emph{copy} of the actual buffer, and not the pointer given by the programmer:
- if the codelet modifies this buffer, there is no guarantee that the initial
- buffer will be modified as well: this for instance implies that the buffer
- cannot be used as a synchronization medium.
- @node Submitting a Task
- @subsection Submitting a Task
- @cartouche
- @example
- void callback_func(void *callback_arg)
- @{
- printf("Callback function (arg %x)\n", callback_arg);
- @}
- int main(int argc, char **argv)
- @{
- /* @b{initialize StarPU} */
- starpu_init(NULL);
- struct starpu_task *task = starpu_task_create();
- task->cl = &cl; /* @b{Pointer to the codelet defined above} */
- float array[2] = @{1.0f, -1.0f@};
- task->cl_arg = &array;
- task->cl_arg_size = 2*sizeof(float);
- task->callback_func = callback_func;
- task->callback_arg = 0x42;
- /* @b{starpu_task_submit will be a blocking call} */
- task->synchronous = 1;
- /* @b{submit the task to StarPU} */
- starpu_task_submit(task);
- /* @b{terminate StarPU} */
- starpu_shutdown();
- return 0;
- @}
- @end example
- @end cartouche
- Before submitting any tasks to StarPU, @code{starpu_init} must be called. The
- @code{NULL} argument specifies that we use default configuration. Tasks cannot
- be submitted after the termination of StarPU by a call to
- @code{starpu_shutdown}.
- In the example above, a task structure is allocated by a call to
- @code{starpu_task_create}. This function only allocates and fills the
- corresponding structure with the default settings (@pxref{starpu_task_create}),
- but it does not submit the task to StarPU.
- @c not really clear ;)
- The @code{cl} field is a pointer to the codelet which the task will
- execute: in other words, the codelet structure describes which computational
- kernel should be offloaded on the different architectures, and the task
- structure is a wrapper containing a codelet and the piece of data on which the
- codelet should operate.
- The optional @code{cl_arg} field is a pointer to a buffer (of size
- @code{cl_arg_size}) with some parameters for the kernel
- described by the codelet. For instance, if a codelet implements a computational
- kernel that multiplies its input vector by a constant, the constant could be
- specified by the means of this buffer.
- Once a task has been executed, an optional callback function can be called.
- While the computational kernel could be offloaded on various architectures, the
- callback function is always executed on a CPU. The @code{callback_arg}
- pointer is passed as an argument of the callback. The prototype of a callback
- function must be:
- @code{void (*callback_function)(void *);}
- If the @code{synchronous} field is non-null, task submission will be
- synchronous: the @code{starpu_task_submit} function will not return until the
- task was executed. Note that the @code{starpu_shutdown} method does not
- guarantee that asynchronous tasks have been executed before it returns.
- @node Execution of Hello World
- @subsection Execution of Hello World
- @example
- % make helloWorld
- cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) helloWorld.c -o helloWorld
- % ./helloWorld
- Hello world (array = @{1.000000, -1.000000@} )
- Callback function (arg 42)
- @end example
- @node Scaling a Vector
- @section Manipulating Data: Scaling a Vector
- The previous example has shown how to submit tasks. In this section,
- we show how StarPU tasks can manipulate data. The full source code for
- this example is given in @ref{Full source code for the 'Scaling a Vector' example}.
- @menu
- * Source code of Vector Scaling::
- * Execution of Vector Scaling::
- @end menu
- @node Source code of Vector Scaling
- @subsection Source code of Vector Scaling
- Programmers can describe the data layout of their application so that StarPU is
- responsible for enforcing data coherency and availability across the machine.
- Instead of handling complex (and non-portable) mechanisms to perform data
- movements, programmers only declare which piece of data is accessed and/or
- modified by a task, and StarPU makes sure that when a computational kernel
- starts somewhere (e.g. on a GPU), its data are available locally.
- Before submitting those tasks, the programmer first needs to declare the
- different pieces of data to StarPU using the @code{starpu_*_data_register}
- functions. To ease the development of applications for StarPU, it is possible
- to describe multiple types of data layout. A type of data layout is called an
- @b{interface}. By default, there are different interfaces available in StarPU:
- here we will consider the @b{vector interface}.
- The following lines show how to declare an array of @code{NX} elements of type
- @code{float} using the vector interface:
- @cartouche
- @example
- float vector[NX];
- starpu_data_handle vector_handle;
- starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX,
- sizeof(float));
- @end example
- @end cartouche
- The first argument, called the @b{data handle}, is an opaque pointer which
- designates the array in StarPU. This is also the structure which is used to
- describe which data is used by a task. The second argument is the node number
- where the data currently resides. Here it is 0 since the @code{vector} array is in
- the main memory. Then comes the pointer @code{vector} where the data can be found,
- the number of elements in the vector and the size of each element.
- It is possible to construct a StarPU task that will manipulate the
- vector and a constant factor.
- @cartouche
- @example
- float factor = 3.0;
- struct starpu_task *task = starpu_task_create();
- task->cl = &cl; /* @b{Pointer to the codelet defined below} */
- task->callback_func = NULL;
- task->buffers[0].handle = vector_handle; /* @b{First parameter of the codelet} */
- task->buffers[0].mode = STARPU_RW;
- task->cl_arg = &factor;
- task->cl_arg_size = sizeof(float);
- task->synchronous = 1;
- starpu_task_submit(task);
- @end example
- @end cartouche
- Since the factor is constant, it does not need a preliminary declaration, and
- can just be passed through the @code{cl_arg} pointer like in the previous
- example. The vector parameter is described by its handle.
- There are two fields in each element of the @code{buffers} array.
- @code{handle} is the handle of the data, and @code{mode} specifies how the
- kernel will access the data (@code{STARPU_R} for read-only, @code{STARPU_W} for
- write-only and @code{STARPU_RW} for read and write access).
- The definition of the codelet can be written as follows:
- @cartouche
- @example
- void scal_func(void *buffers[], void *cl_arg)
- @{
- unsigned i;
- float *factor = cl_arg;
- struct starpu_vector_interface_s *vector = buffers[0];
- /* length of the vector */
- unsigned n = STARPU_GET_VECTOR_NX(vector);
- /* local copy of the vector pointer */
- float *val = (float *)STARPU_GET_VECTOR_PTR(vector);
- for (i = 0; i < n; i++)
- val[i] *= *factor;
- @}
- starpu_codelet cl = @{
- .where = STARPU_CPU,
- .cpu_func = scal_func,
- .nbuffers = 1
- @};
- @end example
- @end cartouche
- The second argument of the @code{scal_func} function contains a pointer to the
- parameters of the codelet (given in @code{task->cl_arg}), so that we read the
- constant factor from this pointer. The first argument is an array that gives
- a description of all the buffers passed in the @code{task->buffers}@ array. The
- size of this array is given by the @code{nbuffers} field of the codelet
- structure. For the sake of generality, this array contains pointers to the
- different interfaces describing each buffer. In the case of the @b{vector
- interface}, the location of the vector (resp. its length) is accessible in the
- @code{ptr} (resp. @code{nx}) of this array. Since the vector is accessed in a
- read-write fashion, any modification will automatically affect future accesses
- to this vector made by other tasks.
- @node Execution of Vector Scaling
- @subsection Execution of Vector Scaling
- @example
- % make vector
- cc $(pkg-config --cflags libstarpu) $(pkg-config --libs libstarpu) vector.c -o vector
- % ./vector
- 0.000000 3.000000 6.000000 9.000000 12.000000
- @end example
- @node Vector Scaling on an Hybrid CPU/GPU Machine
- @section Vector Scaling on an Hybrid CPU/GPU Machine
- Contrary to the previous examples, the task submitted in this example may not
- only be executed by the CPUs, but also by a CUDA device.
- @menu
- * Source code of Hybrid Vector Scaling::
- * Compilation and execution of Hybrid Vector Scaling::
- @end menu
- @node Source code of Hybrid Vector Scaling
- @subsection Source code of Hybrid Vector Scaling
- The CUDA implementation can be written as follows. It needs to be
- compiled with a CUDA compiler such as nvcc, the NVIDIA CUDA compiler
- driver.
- @cartouche
- @example
- #include <starpu.h>
- static __global__ void vector_mult_cuda(float *val, unsigned n,
- float factor)
- @{
- unsigned i;
- for(i = 0 ; i < n ; i++)
- val[i] *= factor;
- @}
- extern "C" void scal_cuda_func(void *buffers[], void *_args)
- @{
- float *factor = (float *)_args;
- struct starpu_vector_interface_s *vector = (struct starpu_vector_interface_s *) buffers[0];
- /* length of the vector */
- unsigned n = STARPU_GET_VECTOR_NX(vector);
- /* local copy of the vector pointer */
- float *val = (float *)STARPU_GET_VECTOR_PTR(vector);
- /* TODO: use more blocks and threads in blocks */
- vector_mult_cuda<<<1,1>>>(val, n, *factor);
- cudaThreadSynchronize();
- @}
- @end example
- @end cartouche
- The CPU implementation is the same as in the previous section.
- Here is the source of the main application. You can notice the value of the
- field @code{where} for the codelet. We specify
- @code{STARPU_CPU|STARPU_CUDA} to indicate to StarPU that the codelet
- can be executed either on a CPU or on a CUDA device.
- @cartouche
- @example
- #include <starpu.h>
- #define NX 5
- extern void scal_cuda_func(void *buffers[], void *_args);
- extern void scal_func(void *buffers[], void *_args);
- /* @b{Definition of the codelet} */
- static starpu_codelet cl = @{
- .where = STARPU_CPU|STARPU_CUDA; /* @b{It can be executed on a CPU} */
- /* @b{or on a CUDA device} */
- .cuda_func = scal_cuda_func;
- .cpu_func = scal_func;
- .nbuffers = 1;
- @}
- int main(int argc, char **argv)
- @{
- float *vector;
- int i, ret;
- float factor=3.0;
- struct starpu_task *task;
- starpu_data_handle vector_handle;
- starpu_init(NULL); /* @b{Initialising StarPU} */
- vector = (float*)malloc(NX*sizeof(float));
- assert(vector);
- for(i=0 ; i<NX ; i++) vector[i] = i;
- @end example
- @end cartouche
- @cartouche
- @example
- /* @b{Registering data within StarPU} */
- starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector,
- NX, sizeof(float));
- /* @b{Definition of the task} */
- task = starpu_task_create();
- task->cl = &cl;
- task->callback_func = NULL;
- task->buffers[0].handle = vector_handle;
- task->buffers[0].mode = STARPU_RW;
- task->cl_arg = &factor;
- task->cl_arg_size = sizeof(float);
- @end example
- @end cartouche
- @cartouche
- @example
- /* @b{Submitting the task} */
- ret = starpu_task_submit(task);
- if (ret == -ENODEV) @{
- fprintf(stderr, "No worker may execute this task\n");
- return 1;
- @}
- /* @b{Waiting for its termination} */
- starpu_task_wait_for_all();
- /* @b{Update the vector in RAM} */
- starpu_data_sync_with_mem(vector_handle, STARPU_R);
- @end example
- @end cartouche
- @cartouche
- @example
- /* @b{Access the data} */
- for(i=0 ; i<NX; i++) @{
- fprintf(stderr, "%f ", vector[i]);
- @}
- fprintf(stderr, "\n");
- /* @b{Release the data and shutdown StarPU} */
- starpu_data_release_from_mem(vector_handle);
- starpu_shutdown();
- return 0;
- @}
- @end example
- @end cartouche
- @node Compilation and execution of Hybrid Vector Scaling
- @subsection Compilation and execution of Hybrid Vector Scaling
- The Makefile given at the beginning of the section must be extended to
- give the rules to compile the CUDA source code.
- @cartouche
- @example
- CFLAGS += $(shell pkg-config --cflags libstarpu)
- LDFLAGS += $(shell pkg-config --libs libstarpu)
- CC = gcc
- vector: vector.o vector_cpu.o vector_cuda.o
- %.o: %.cu
- nvcc $(CFLAGS) $< -c $@
- clean:
- rm -f vector *.o
- @end example
- @end cartouche
- @example
- % make
- @end example
- and to execute it, with the default configuration:
- @example
- % ./vector
- 0.000000 3.000000 6.000000 9.000000 12.000000
- @end example
- or for example, by disabling CPU devices:
- @example
- % STARPU_NCPUS=0 ./vector
- 0.000000 3.000000 6.000000 9.000000 12.000000
- @end example
- or by disabling CUDA devices:
- @example
- % STARPU_NCUDA=0 ./vector
- 0.000000 3.000000 6.000000 9.000000 12.000000
- @end example
- @c TODO: Add performance model example (and update basic_examples)
- @c ---------------------------------------------------------------------
- @c Advanced Topics
- @c ---------------------------------------------------------------------
- @c @node Advanced Topics
- @c @chapter Advanced Topics
- @c ---------------------------------------------------------------------
- @c Appendices
- @c ---------------------------------------------------------------------
- @c ---------------------------------------------------------------------
- @c Full source code for the 'Scaling a Vector' example
- @c ---------------------------------------------------------------------
- @node Full source code for the 'Scaling a Vector' example
- @appendix Full source code for the 'Scaling a Vector' example
- @example
- #include <starpu.h>
- void scal_func(void *buffers[], void *cl_arg)
- @{
- unsigned i;
- float *factor = cl_arg;
- struct starpu_vector_interface_s *vector = buffers[0];
- /* length of the vector */
- unsigned n = STARPU_GET_VECTOR_NX(vector);
- /* local copy of the vector pointer */
- float *val = (float *)STARPU_GET_VECTOR_PTR(vector);
- for (i = 0; i < n; i++)
- val[i] *= *factor;
- @}
- starpu_codelet cl = @{
- .where = STARPU_CPU,
- .cpu_func = scal_func,
- .nbuffers = 1
- @};
- #define NX 5
- int main(int argc, char **argv)
- @{
- float vector[NX];
- starpu_data_handle vector_handle;
- float factor = 3.0;
- int i;
- starpu_init(NULL);
- for(i=0 ; i<NX; i++) vector[i] = i;
- starpu_vector_data_register(&vector_handle, 0, (uintptr_t)vector, NX, sizeof(float));
- struct starpu_task *task = starpu_task_create();
- task->cl = &cl;
- task->callback_func = NULL;
- task->buffers[0].handle = vector_handle;
- task->buffers[0].mode = STARPU_RW;
- task->cl_arg = &factor;
- task->cl_arg_size = sizeof(float);
- task->synchronous = 1;
- starpu_task_submit(task);
- for(i=0 ; i<NX ; i++) @{
- fprintf(stderr, "%f ", vector[i]);
- @}
- fprintf(stderr, "\n");
- starpu_shutdown();
- return 0;
- @}
- @end example
- @bye
|