495_interoperability.doxy 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2018-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 InteroperabilitySupport Interoperability Support
  17. In situations where multiple parallel software elements have to coexist within
  18. the same application, uncoordinated accesses to computing units may lead such
  19. parallel software elements to collide and interfere. The purpose of the
  20. Interoperability routines of StarPU, implemented along the definition of the
  21. Resource Management APIs of Project H2020 INTERTWinE, is to enable StarPU to
  22. coexist with other parallel software elements without resulting in computing
  23. core oversubscription or undersubscription. These routines allow the
  24. programmer to dynamically control the computing resources allocated to StarPU,
  25. to add or remove processor cores and/or accelerator devices from the pool of
  26. resources used by StarPU's workers to execute tasks. They also allow multiple
  27. libraries and applicative codes using StarPU simultaneously to select distinct
  28. sets of resources independently. Internally, the Interoperability Support is
  29. built on top of Scheduling Contexts (see \ref SchedulingContexts).
  30. \section ResourceManagement StarPU Resource Management
  31. The \c starpurm module is a library built on top of the \c starpu library. It
  32. exposes a series of routines prefixed with \c starpurm_ defining the resource
  33. management API.
  34. All functions are defined in \ref API_Interop_Support.
  35. \subsection Build Linking a program with the starpurm module
  36. The \c starpurm module must be linked explicitly with the applicative executable
  37. using it. Example Makefiles in the <c>starpurm/dev/</c> subdirectories show how
  38. to do so. If the \c pkg-config command is available and the \c PKG_CONFIG_PATH
  39. environment variable is properly positioned, the proper settings may be obtained
  40. with the following \c Makefile snippet:
  41. \code{Makefile}
  42. CFLAGS += $(shell pkg-config --cflags starpurm-1.3)
  43. LDFLAGS+= $(shell pkg-config --libs-only-L starpurm-1.3)
  44. LDLIBS += $(shell pkg-config --libs-only-l starpurm-1.3)
  45. \endcode
  46. \subsection InitExit Initialization and Shutdown
  47. The \c starpurm module is initialized with a call to starpurm_initialize()
  48. and must be finalized with a call to starpurm_shutdown(). The \c starpurm
  49. module supports CPU cores as well as devices. An integer ID is assigned to each
  50. supported device type. The ID assigned to a given device type can be queried
  51. with the starpurm_get_device_type_id() routine, which currently expects one
  52. of the following strings as argument and returns the corresponding ID:
  53. <ul>
  54. <li><c>"cpu"</c></li>
  55. <li><c>"opencl"</c></li>
  56. <li><c>"cuda"</c></li>
  57. <li><c>"mic"</c></li>
  58. </ul>
  59. The \c cpu pseudo device type is defined for convenience and designates CPU
  60. cores. The number of units of each type available for computation can be
  61. obtained with a call to starpu_get_nb_devices_by_type().
  62. Each CPU core unit available for computation is designated by its rank among the
  63. StarPU CPU worker threads and by its own CPUSET bit. Each non-CPU device unit
  64. can be designated both by its rank number in the type, and by the CPUSET bit
  65. corresponding to its StarPU device worker thread. The CPUSET of a computing unit
  66. or its associated worker can be obtained from its type ID and rank with
  67. starpurm_get_device_worker_cpuset(), which returns the corresponding HWLOC CPUSET.
  68. \subsection DefCTX Default Context
  69. The \c starpurm module assumes a default, global context, manipulated through a
  70. series of routines allowing to assign and withdraw computing units from the main
  71. StarPU context. Assigning CPU cores can be done with
  72. starpurm_assign_cpu_to_starpu() and starpurm_assign_cpu_mask_to_starpu(), and
  73. assigning device units can be done with starpurm_assign_device_to_starpu()
  74. and starpurm_assign_device_mask_to_starpu(). Conversely, withdrawing CPU
  75. cores can be done with starpurm_withdraw_cpu_from_starpu() and starpurm_withdraw_cpu_mask_from_starpu(=,
  76. and withdrawing device units can be done with
  77. starpurm_withdraw_device_from_starpu() and starpurm_withdraw_device_mask_from_starpu().
  78. These routine should typically be used to control resource usage for the main
  79. applicative code.
  80. \subsection TmpCTXS Temporary Contexts
  81. Besides the default, global context, \c starpurm can create temporary contexts
  82. and launch the computation of kernels confined to these temporary contexts.
  83. The routine starpurm_spawn_kernel_on_cpus() can be used to do so: it
  84. allocates a temporary context and spawns a kernel within this context. The
  85. temporary context is subsequently freed upon completion of the kernel. The
  86. temporary context is set as the default context for the kernel throughout its
  87. lifespan. This routine should typically be used to control resource usage for a
  88. parallel kernel handled by an external library built on StarPU. Internally, it
  89. relies on the use of starpu_sched_ctx_set_context() to set the temporary
  90. context as default context for the parallel kernel, and then restore the main
  91. context upon completion. Note: the maximum number of temporary contexts
  92. allocated concurrently at any time should not exceed
  93. ::STARPU_NMAX_SCHED_CTXS-2, otherwise, the call to
  94. starpurm_spawn_kernel_on_cpus() may block until a temporary context becomes
  95. available. The routine starpurm_spawn_kernel_on_cpus() returns upon the
  96. completion of the parallel kernel. An asynchronous variant is available with the
  97. routine starpurm_spawn_kernel_on_cpus_callback(). This variant returns
  98. immediately, however it accepts a callback function, which is subsequently
  99. called to notify the calling code about the completion of the parallel kernel.
  100. */