| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 | /* StarPU --- Runtime system for heterogeneous multicore architectures. * * Copyright (C) 2018-2020  Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria * * StarPU is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or (at * your option) any later version. * * StarPU is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Lesser General Public License in COPYING.LGPL for more details. *//*! \page InteroperabilitySupport Interoperability SupportIn situations where multiple parallel software elements have to coexist withinthe same application, uncoordinated accesses to computing units may lead suchparallel software elements to collide and interfere. The purpose of theInteroperability routines of StarPU, implemented along the definition of theResource Management APIs of Project H2020 INTERTWinE, is to enable StarPU tocoexist with other parallel software elements without resulting in computingcore oversubscription or undersubscription. These routines allow theprogrammer to dynamically control the computing resources allocated to StarPU,to add or remove processor cores and/or accelerator devices from the pool ofresources used by StarPU's workers to execute tasks. They also allow multiplelibraries and applicative codes using StarPU simultaneously to select distinctsets of resources independently. Internally, the Interoperability Support isbuilt on top of Scheduling Contexts (see \ref SchedulingContexts).\section ResourceManagement StarPU Resource ManagementThe \c starpurm module is a library built on top of the \c starpu library. Itexposes a series of routines prefixed with \c starpurm_ defining the resourcemanagement API.All functions are defined in \ref API_Interop_Support.\subsection Build Linking a program with the starpurm moduleThe \c starpurm module must be linked explicitly with the applicative executableusing it. Example Makefiles in the <c>starpurm/dev/</c> subdirectories show howto do so. If the \c pkg-config command is available and the \c PKG_CONFIG_PATHenvironment variable is properly positioned, the proper settings may be obtainedwith the following \c Makefile snippet:\code{Makefile}CFLAGS += $(shell pkg-config --cflags starpurm-1.3)LDFLAGS+= $(shell pkg-config --libs-only-L starpurm-1.3)LDLIBS += $(shell pkg-config --libs-only-l starpurm-1.3)\endcode\subsection InitExit Initialization and ShutdownThe \c starpurm module is initialized with a call to starpurm_initialize()and must be finalized with a call to starpurm_shutdown(). The \c starpurmmodule supports CPU cores as well as devices. An integer ID is assigned to eachsupported device type. The ID assigned to a given device type can be queriedwith the starpurm_get_device_type_id() routine, which currently expects oneof the following strings as argument and returns the corresponding ID:<ul><li><c>"cpu"</c></li><li><c>"opencl"</c></li><li><c>"cuda"</c></li><li><c>"mic"</c></li></ul>The \c cpu pseudo device type is defined for convenience and designates CPUcores. The number of units of each type available for computation can beobtained with a call to starpu_get_nb_devices_by_type().Each CPU core unit available for computation is designated by its rank among theStarPU CPU worker threads and by its own CPUSET bit. Each non-CPU device unitcan be designated both by its rank number in the type, and by the CPUSET bitcorresponding to its StarPU device worker thread. The CPUSET of a computing unitor its associated worker can be obtained from its type ID and rank with starpurm_get_device_worker_cpuset(), which returns the corresponding HWLOC CPUSET. \subsection DefCTX Default ContextThe \c starpurm module assumes a default, global context, manipulated through aseries of routines allowing to assign and withdraw computing units from the mainStarPU context. Assigning CPU cores can be done withstarpurm_assign_cpu_to_starpu() and starpurm_assign_cpu_mask_to_starpu(), andassigning device units can be done with starpurm_assign_device_to_starpu()and starpurm_assign_device_mask_to_starpu(). Conversely, withdrawing CPUcores can be done with starpurm_withdraw_cpu_from_starpu() and starpurm_withdraw_cpu_mask_from_starpu(=,and withdrawing device units can be done withstarpurm_withdraw_device_from_starpu() and starpurm_withdraw_device_mask_from_starpu().These routine should typically be used to control resource usage for the mainapplicative code.\subsection TmpCTXS Temporary ContextsBesides the default, global context, \c starpurm can create temporary contextsand launch the computation of kernels confined to these temporary contexts.The routine starpurm_spawn_kernel_on_cpus() can be used to do so: itallocates a temporary context and spawns a kernel within this context. Thetemporary context is subsequently freed upon completion of the kernel. Thetemporary context is set as the default context for the kernel throughout itslifespan. This routine should typically be used to control resource usage for aparallel kernel handled by an external library built on StarPU. Internally, itrelies on the use of starpu_sched_ctx_set_context() to set the temporarycontext as default context for the parallel kernel, and then restore the maincontext upon completion. Note: the maximum number of temporary contextsallocated concurrently at any time should not exceed::STARPU_NMAX_SCHED_CTXS-2, otherwise, the call tostarpurm_spawn_kernel_on_cpus() may block until a temporary context becomesavailable. The routine starpurm_spawn_kernel_on_cpus() returns upon thecompletion of the parallel kernel. An asynchronous variant is available with theroutine starpurm_spawn_kernel_on_cpus_callback(). This variant returnsimmediately, however it accepts a callback function, which is subsequentlycalled to notify the calling code about the completion of the parallel kernel.*/
 |