101_building.doxy 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. /*! \page BuildingAndInstallingStarPU Building and Installing StarPU
  17. \section InstallingABinaryPackage Installing a Binary Package
  18. One of the StarPU developers being a Debian Developer, the packages
  19. are well integrated and very uptodate. To see which packages are
  20. available, simply type:
  21. \verbatim
  22. $ apt-cache search starpu
  23. \endverbatim
  24. To install what you need, type for example:
  25. \verbatim
  26. $ sudo apt-get install libstarpu-1.3 libstarpu-dev
  27. \endverbatim
  28. \section InstallingFromSource Installing from Source
  29. StarPU can be built and installed by the standard means of the GNU
  30. autotools. The following chapter is intended to briefly remind how these tools
  31. can be used to install StarPU.
  32. \subsection OptionalDependencies Optional Dependencies
  33. The <c>hwloc</c> (http://www.open-mpi.org/software/hwloc) topology
  34. discovery library is not mandatory to use StarPU but strongly
  35. recommended. It allows for topology aware scheduling, which improves
  36. performance. <c>libhwloc</c> is available in major free operating system
  37. distributions, and for most operating systems.
  38. If <c>libhwloc</c> is installed in a standard
  39. location, no option is required, it will be detected automatically,
  40. otherwise \ref with-hwloc "--with-hwloc=<directory>" should be used to specify its
  41. location.
  42. If <c>libhwloc</c> is not available on your system, the option
  43. \ref without-hwloc "--without-hwloc" should be explicitely given when calling the
  44. script <c>configure</c>.
  45. \subsection GettingSources Getting Sources
  46. StarPU's sources can be obtained from the download page of
  47. the StarPU website (http://starpu.gforge.inria.fr/files/).
  48. All releases and the development tree of StarPU are freely available
  49. on Inria's gforge under the LGPL license. Some releases are available
  50. under the BSD license.
  51. The latest release can be downloaded from the Inria's gforge (http://gforge.inria.fr/frs/?group_id=1570) or
  52. directly from the StarPU download page (http://starpu.gforge.inria.fr/files/).
  53. The latest nightly snapshot can be downloaded from the StarPU gforge website (http://starpu.gforge.inria.fr/testing/).
  54. \verbatim
  55. $ wget http://starpu.gforge.inria.fr/testing/starpu-nightly-latest.tar.gz
  56. \endverbatim
  57. And finally, current development version is also accessible via git.
  58. It should only be used if you need the very latest changes (i.e. less
  59. than a day old!).
  60. \verbatim
  61. $ git clone https://scm.gforge.inria.fr/anonscm/git/starpu/starpu.git
  62. \endverbatim
  63. \subsection ConfiguringStarPU Configuring StarPU
  64. Running <c>autogen.sh</c> is not necessary when using the tarball
  65. releases of StarPU. However when using the source code from the git
  66. repository, you first need to generate the script <c>configure</c> and the
  67. different Makefiles. This requires the availability of <c>autoconf</c> and
  68. <c>automake</c> >= 2.60.
  69. \verbatim
  70. $ ./autogen.sh
  71. \endverbatim
  72. You then need to configure StarPU. Details about options that are
  73. useful to give to <c>configure</c> are given in \ref CompilationConfiguration.
  74. \verbatim
  75. $ ./configure
  76. \endverbatim
  77. If <c>configure</c> does not detect some software or produces errors, please
  78. make sure to post the contents of the file <c>config.log</c> when
  79. reporting the issue.
  80. By default, the files produced during the compilation are placed in
  81. the source directory. As the compilation generates a lot of files, it
  82. is advised to put them all in a separate directory. It is then
  83. easier to cleanup, and this allows to compile several configurations
  84. out of the same source tree. To do so, simply enter the directory
  85. where you want the compilation to produce its files, and invoke the
  86. script <c>configure</c> located in the StarPU source directory.
  87. \verbatim
  88. $ mkdir build
  89. $ cd build
  90. $ ../configure
  91. \endverbatim
  92. By default, StarPU will be installed in <c>/usr/local/bin</c>,
  93. <c>/usr/local/lib</c>, etc. You can specify an installation prefix
  94. other than <c>/usr/local</c> using the option <c>--prefix</c>, for
  95. instance:
  96. \verbatim
  97. $ ../configure --prefix=$HOME/starpu
  98. \endverbatim
  99. \subsection BuildingStarPU Building StarPU
  100. \verbatim
  101. $ make
  102. \endverbatim
  103. Once everything is built, you may want to test the result. An
  104. extensive set of regression tests is provided with StarPU. Running the
  105. tests is done by calling <c>make check</c>. These tests are run every night
  106. and the result from the main profile is publicly available (http://starpu.gforge.inria.fr/testing/master/).
  107. \verbatim
  108. $ make check
  109. \endverbatim
  110. \subsection InstallingStarPU Installing StarPU
  111. In order to install StarPU at the location which was specified during
  112. configuration:
  113. \verbatim
  114. $ make install
  115. \endverbatim
  116. If you have let StarPU install in <c>/usr/local/</c>, you additionally need to run
  117. \verbatim
  118. $ sudo ldconfig
  119. \endverbatim
  120. so the libraries can be found by the system.
  121. Libtool interface versioning information are included in
  122. libraries names (<c>libstarpu-1.3.so</c>, <c>libstarpumpi-1.3.so</c> and
  123. <c>libstarpufft-1.3.so</c>).
  124. \section SettingUpYourOwnCode Setting up Your Own Code
  125. \subsection SettingFlagsForCompilingLinkingAndRunningApplications Setting Flags for Compiling, Linking and Running Applications
  126. StarPU provides a <c>pkg-config</c> executable to obtain relevant compiler
  127. and linker flags. As compiling and linking an application against
  128. StarPU may require to use specific flags or libraries (for instance
  129. <c>CUDA</c> or <c>libspe2</c>).
  130. If StarPU was not installed at some standard location, the path of StarPU's
  131. library must be specified in the environment variable
  132. <c>PKG_CONFIG_PATH</c> to allow <c>pkg-config</c> to find it. For
  133. example if StarPU was installed in
  134. <c>$STARPU_PATH</c>:
  135. \verbatim
  136. $ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$STARPU_PATH/lib/pkgconfig
  137. \endverbatim
  138. The flags required to compile or link against StarPU are then
  139. accessible with the following commands:
  140. \verbatim
  141. $ pkg-config --cflags starpu-1.3 # options for the compiler
  142. $ pkg-config --libs starpu-1.3 # options for the linker
  143. \endverbatim
  144. Note that it is still possible to use the API provided in the version
  145. 1.0 of StarPU by calling <c>pkg-config</c> with the <c>starpu-1.0</c> package.
  146. Similar packages are provided for <c>starpumpi-1.0</c> and <c>starpufft-1.0</c>.
  147. It is also possible to use the API provided in the version
  148. 0.9 of StarPU by calling <c>pkg-config</c> with the <c>libstarpu</c> package.
  149. Similar packages are provided for <c>libstarpumpi</c> and <c>libstarpufft</c>.
  150. Make sure that <c>pkg-config --libs starpu-1.3</c> actually produces some output
  151. before going further: <c>PKG_CONFIG_PATH</c> has to point to the place where
  152. <c>starpu-1.3.pc</c> was installed during <c>make install</c>.
  153. Also pass the option <c>--static</c> if the application is to be
  154. linked statically.
  155. It is also necessary to set the environment variable <c>LD_LIBRARY_PATH</c> to
  156. locate dynamic libraries at runtime.
  157. \verbatim
  158. $ export LD_LIBRARY_PATH=$STARPU_PATH/lib:$LD_LIBRARY_PATH
  159. \endverbatim
  160. And it is useful to get access to the StarPU tools:
  161. \verbatim
  162. $ export PATH=$PATH:$STARPU_PATH/bin
  163. \endverbatim
  164. It is then useful to check that StarPU executes correctly and finds your hardware:
  165. \verbatim
  166. $ starpu_machine_display
  167. \endverbatim
  168. If it does not, please check the output of \c lstopo from \c hwloc and report
  169. the issue to the \c hwloc project, since this is what StarPU uses to detect the hardware.
  170. <br>
  171. A tool is provided to help setting all the environment variables
  172. needed by StarPU. Once StarPU is installed in a specific directory,
  173. calling the script <c>bin/starpu_env</c> will set in your current
  174. environment the variables <c>STARPU_PATH</c>, <c>LD_LIBRARY_PATH</c>,
  175. <c>PKG_CONFIG_PATH</c>, <c>PATH</c> and <c>MANPATH</c>.
  176. \verbatim
  177. $ source $STARPU_PATH/bin/starpu_env
  178. \endverbatim
  179. \subsection IntegratingStarPUInABuildSystem Integrating StarPU in a Build System
  180. \subsubsection StarPUInMake Integrating StarPU in a Make Build System
  181. When using a Makefile, the following lines can be added to set the
  182. options for the compiler and the linker:
  183. \verbatim
  184. CFLAGS += $$(pkg-config --cflags starpu-1.3)
  185. LDLIBS += $$(pkg-config --libs starpu-1.3)
  186. \endverbatim
  187. If you have a \c test-starpu.c file containing for instance:
  188. \code{.c}
  189. #include <starpu.h>
  190. #include <stdio.h>
  191. int main(void)
  192. {
  193. int ret;
  194. ret = starpu_init(NULL);
  195. if (ret != 0)
  196. {
  197. return 1;
  198. }
  199. printf("%d CPU cores\n", starpu_worker_get_count_by_type(STARPU_CPU_WORKER));
  200. printf("%d CUDA GPUs\n", starpu_worker_get_count_by_type(STARPU_CUDA_WORKER));
  201. printf("%d OpenCL GPUs\n", starpu_worker_get_count_by_type(STARPU_OPENCL_WORKER));
  202. starpu_shutdown();
  203. return 0;
  204. }
  205. \endcode
  206. You can build it with <code>make test-starpu</code> and run it with <code>./test-starpu</code>
  207. \subsubsection StarPUInCMake Integrating StarPU in a CMake Build System
  208. This section shows a minimal example integrating StarPU in an existing application's CMake build system.
  209. Let's assume we want to build an executable from the following source code using CMake:
  210. \code{.c}
  211. #include <starpu.h>
  212. #include <stdio.h>
  213. int main(void)
  214. {
  215. int ret;
  216. ret = starpu_init(NULL);
  217. if (ret != 0)
  218. {
  219. return 1;
  220. }
  221. printf("%d CPU cores\n", starpu_worker_get_count_by_type(STARPU_CPU_WORKER));
  222. printf("%d CUDA GPUs\n", starpu_worker_get_count_by_type(STARPU_CUDA_WORKER));
  223. printf("%d OpenCL GPUs\n", starpu_worker_get_count_by_type(STARPU_OPENCL_WORKER));
  224. starpu_shutdown();
  225. return 0;
  226. }
  227. \endcode
  228. The \c CMakeLists.txt file below uses the Pkg-Config support from CMake to
  229. autodetect the StarPU installation and library dependences (such as
  230. <c>libhwloc</c>) provided that the <c>PKG_CONFIG_PATH</c> variable is set, and
  231. is sufficient to build a statically-linked executable. This example has been
  232. successfully tested with CMake 3.2, though it may work with earlier CMake 3.x
  233. versions.
  234. \code{File CMakeLists.txt}
  235. cmake_minimum_required (VERSION 3.2)
  236. project (hello_starpu)
  237. find_package(PkgConfig)
  238. pkg_check_modules(STARPU REQUIRED starpu-1.3)
  239. if (STARPU_FOUND)
  240. include_directories (${STARPU_INCLUDE_DIRS})
  241. link_directories (${STARPU_STATIC_LIBRARY_DIRS})
  242. link_libraries (${STARPU_STATIC_LIBRARIES})
  243. else (STARPU_FOUND)
  244. message(FATAL_ERROR "StarPU not found")
  245. endif()
  246. add_executable(hello_starpu hello_starpu.c)
  247. \endcode
  248. The following \c CMakeLists.txt implements an alternative, more complex
  249. strategy, still relying on Pkg-Config, but also taking into account additional
  250. flags. While more complete, this approach makes CMake's build types (Debug,
  251. Release, ...) unavailable because of the direct affectation to variable
  252. <c>CMAKE_C_FLAGS</c>. If both the full flags support and the build types
  253. support are needed, the \c CMakeLists.txt below may be altered to work with
  254. <c>CMAKE_C_FLAGS_RELEASE</c>, <c>CMAKE_C_FLAGS_DEBUG</c>, and others as needed.
  255. This example has been successfully tested with CMake 3.2, though it may work
  256. with earlier CMake 3.x versions.
  257. \code{File CMakeLists.txt}
  258. cmake_minimum_required (VERSION 3.2)
  259. project (hello_starpu)
  260. find_package(PkgConfig)
  261. pkg_check_modules(STARPU REQUIRED starpu-1.3)
  262. # This section must appear before 'add_executable'
  263. if (STARPU_FOUND)
  264. # CFLAGS other than -I
  265. foreach(CFLAG ${STARPU_CFLAGS_OTHER})
  266. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAG}")
  267. endforeach()
  268. # Static LDFLAGS other than -L
  269. foreach(LDFLAG ${STARPU_STATIC_LDFLAGS_OTHER})
  270. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LDFLAG}")
  271. endforeach()
  272. # -L directories
  273. link_directories(${STARPU_STATIC_LIBRARY_DIRS})
  274. else (STARPU_FOUND)
  275. message(FATAL_ERROR "StarPU not found")
  276. endif()
  277. add_executable(hello_starpu hello_starpu.c)
  278. # This section must appear after 'add_executable'
  279. if (STARPU_FOUND)
  280. # -I directories
  281. target_include_directories(hello_starpu PRIVATE ${STARPU_INCLUDE_DIRS})
  282. # Static -l libs
  283. target_link_libraries(hello_starpu PRIVATE ${STARPU_STATIC_LIBRARIES})
  284. endif()
  285. \endcode
  286. \subsection RunningABasicStarPUApplication Running a Basic StarPU Application
  287. Basic examples using StarPU are built in the directory
  288. <c>examples/basic_examples/</c> (and installed in
  289. <c>$STARPU_PATH/lib/starpu/examples/</c>). You can for example run the example
  290. <c>vector_scal</c>.
  291. \verbatim
  292. $ ./examples/basic_examples/vector_scal
  293. BEFORE: First element was 1.000000
  294. AFTER: First element is 3.140000
  295. \endverbatim
  296. When StarPU is used for the first time, the directory
  297. <c>$STARPU_HOME/.starpu/</c> is created, performance models will be stored in
  298. this directory (\ref STARPU_HOME).
  299. Please note that buses are benchmarked when StarPU is launched for the
  300. first time. This may take a few minutes, or less if <c>libhwloc</c> is
  301. installed. This step is done only once per user and per machine.
  302. \subsection RunningABasicStarPUApplicationOnMicrosoft Running a Basic StarPU Application on Microsoft Visual C
  303. Batch files are provided to run StarPU applications under Microsoft
  304. Visual C. They are installed in <c>$STARPU_PATH/bin/msvc</c>.
  305. To execute a StarPU application, you first need to set the environment
  306. variable \ref STARPU_PATH.
  307. \verbatim
  308. c:\....> cd c:\cygwin\home\ci\starpu\
  309. c:\....> set STARPU_PATH=c:\cygwin\home\ci\starpu\
  310. c:\....> cd bin\msvc
  311. c:\....> starpu_open.bat starpu_simple.c
  312. \endverbatim
  313. The batch script will run Microsoft Visual C with a basic project file
  314. to run the given application.
  315. The batch script <c>starpu_clean.bat</c> can be used to delete all
  316. compilation generated files.
  317. The batch script <c>starpu_exec.bat</c> can be used to compile and execute a
  318. StarPU application from the command prompt.
  319. \verbatim
  320. c:\....> cd c:\cygwin\home\ci\starpu\
  321. c:\....> set STARPU_PATH=c:\cygwin\home\ci\starpu\
  322. c:\....> cd bin\msvc
  323. c:\....> starpu_exec.bat ..\..\..\..\examples\basic_examples\hello_world.c
  324. \endverbatim
  325. \verbatim
  326. MSVC StarPU Execution
  327. ...
  328. /out:hello_world.exe
  329. ...
  330. Hello world (params = {1, 2.00000})
  331. Callback function got argument 0000042
  332. c:\....>
  333. \endverbatim
  334. \subsection KernelThreadsStartedByStarPU Kernel Threads Started by StarPU
  335. StarPU automatically binds one thread per CPU core. It does not use
  336. SMT/hyperthreading because kernels are usually already optimized for using a
  337. full core, and using hyperthreading would make kernel calibration rather random.
  338. Since driving GPUs is a CPU-consuming task, StarPU dedicates one core
  339. per GPU.
  340. While StarPU tasks are executing, the application is not supposed to do
  341. computations in the threads it starts itself, tasks should be used instead.
  342. If the application needs to reserve some cores for its own computations, it
  343. can do so with the field starpu_conf::reserve_ncpus, get the core IDs with
  344. starpu_get_next_bindid(), and bind to them with starpu_bind_thread_on().
  345. Another option is for the application to pause StarPU by calling
  346. starpu_pause(), then to perform its own computations, and then to
  347. resume StarPU by calling starpu_resume() so that StarPU can execute
  348. tasks.
  349. \subsection EnablingOpenCL Enabling OpenCL
  350. When both CUDA and OpenCL drivers are enabled, StarPU will launch an
  351. OpenCL worker for NVIDIA GPUs only if CUDA is not already running on them.
  352. This design choice was necessary as OpenCL and CUDA can not run at the
  353. same time on the same NVIDIA GPU, as there is currently no interoperability
  354. between them.
  355. To enable OpenCL, you need either to disable CUDA when configuring StarPU:
  356. \verbatim
  357. $ ./configure --disable-cuda
  358. \endverbatim
  359. or when running applications:
  360. \verbatim
  361. $ STARPU_NCUDA=0 ./application
  362. \endverbatim
  363. OpenCL will automatically be started on any device not yet used by
  364. CUDA. So on a machine running 4 GPUS, it is therefore possible to
  365. enable CUDA on 2 devices, and OpenCL on the 2 other devices by doing
  366. so:
  367. \verbatim
  368. $ STARPU_NCUDA=2 ./application
  369. \endverbatim
  370. \section BenchmarkingStarPU Benchmarking StarPU
  371. Some interesting benchmarks are installed among examples in
  372. <c>$STARPU_PATH/lib/starpu/examples/</c>. Make sure to try various
  373. schedulers, for instance <c>STARPU_SCHED=dmda</c>.
  374. \subsection TaskSizeOverhead Task Size Overhead
  375. This benchmark gives a glimpse into how long a task should be (in µs) for StarPU overhead
  376. to be low enough to keep efficiency. Running
  377. <c>tasks_size_overhead.sh</c> generates a plot
  378. of the speedup of tasks of various sizes, depending on the number of CPUs being
  379. used.
  380. \image html tasks_size_overhead.png
  381. \image latex tasks_size_overhead.eps "" width=\textwidth
  382. \subsection DataTransferLatency Data Transfer Latency
  383. <c>local_pingpong</c> performs a ping-pong between the first two CUDA nodes, and
  384. prints the measured latency.
  385. \subsection MatrixMatrixMultiplication Matrix-Matrix Multiplication
  386. <c>sgemm</c> and <c>dgemm</c> perform a blocked matrix-matrix
  387. multiplication using BLAS and cuBLAS. They output the obtained GFlops.
  388. \subsection CholeskyFactorization Cholesky Factorization
  389. <c>cholesky_*</c> perform a Cholesky factorization (single precision). They use different dependency primitives.
  390. \subsection LUFactorization LU Factorization
  391. <c>lu_*</c> perform an LU factorization. They use different dependency primitives.
  392. \subsection SimulatedBenchmarks Simulated Benchmarks
  393. It can also be convenient to try simulated benchmarks, if you want to give a try
  394. at CPU-GPU scheduling without actually having a GPU at hand. This can be done by
  395. using the SimGrid version of StarPU: first install the SimGrid simulator from
  396. http://simgrid.gforge.inria.fr/ (we tested with SimGrid from 3.11 to 3.16, and
  397. 3.18 to 3.25. SimGrid versions 3.25 and above need to be configured with -Denable_msg=ON.
  398. Other versions may have compatibility issues, 3.17 notably does
  399. not build at all. MPI simulation does not work with version 3.22).
  400. Then configure StarPU with \ref enable-simgrid
  401. "--enable-simgrid" and rebuild and install it, and then you can simulate the performance for a
  402. few virtualized systems shipped along StarPU: attila, mirage, idgraf, and sirocco.
  403. For instance:
  404. \verbatim
  405. $ export STARPU_PERF_MODEL_DIR=$STARPU_PATH/share/starpu/perfmodels/sampling
  406. $ export STARPU_HOSTNAME=attila
  407. $ $STARPU_PATH/lib/starpu/examples/cholesky_implicit -size $((960*20)) -nblocks 20
  408. \endverbatim
  409. Will show the performance of the cholesky factorization with the attila
  410. system. It will be interesting to try with different matrix sizes and
  411. schedulers.
  412. Performance models are available for <c>cholesky_*</c>, <c>lu_*</c>, <c>*gemm</c>, with block sizes
  413. 320, 640, or 960 (plus 1440 for sirocco), and for <c>stencil</c> with block size 128x128x128, 192x192x192, and
  414. 256x256x256.
  415. Read the chapter \ref SimGridSupport for more information on the SimGrid support.
  416. */