starpu.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2021 Federal University of Rio Grande do Sul (UFRGS)
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __STARPU_H__
  18. #define __STARPU_H__
  19. #include <stdlib.h>
  20. #ifndef _MSC_VER
  21. #include <stdint.h>
  22. #else
  23. #include <windows.h>
  24. typedef unsigned char uint8_t;
  25. typedef unsigned short uint16_t;
  26. typedef unsigned int uint32_t;
  27. typedef unsigned long long uint64_t;
  28. typedef UINT_PTR uintptr_t;
  29. typedef char int8_t;
  30. typedef short int16_t;
  31. typedef int int32_t;
  32. typedef long long int64_t;
  33. typedef INT_PTR intptr_t;
  34. #endif
  35. #include <starpu_config.h>
  36. #ifdef STARPU_HAVE_WINDOWS
  37. #include <windows.h>
  38. #endif
  39. #if defined(STARPU_USE_OPENCL) && !defined(__CUDACC__)
  40. #include <starpu_opencl.h>
  41. #endif
  42. #include <starpu_thread.h>
  43. #include <starpu_thread_util.h>
  44. #include <starpu_util.h>
  45. #include <starpu_data.h>
  46. #include <starpu_helper.h>
  47. #include <starpu_disk.h>
  48. #include <starpu_data_interfaces.h>
  49. #include <starpu_data_filters.h>
  50. #include <starpu_stdlib.h>
  51. #include <starpu_task_bundle.h>
  52. #include <starpu_task_dep.h>
  53. #include <starpu_task.h>
  54. #include <starpu_worker.h>
  55. #include <starpu_perfmodel.h>
  56. #include <starpu_worker.h>
  57. #ifndef BUILDING_STARPU
  58. #include <starpu_task_list.h>
  59. #endif
  60. #include <starpu_task_util.h>
  61. #include <starpu_scheduler.h>
  62. #include <starpu_sched_ctx.h>
  63. #include <starpu_expert.h>
  64. #include <starpu_rand.h>
  65. #include <starpu_cuda.h>
  66. #include <starpu_cublas.h>
  67. #include <starpu_cusparse.h>
  68. #include <starpu_bound.h>
  69. #include <starpu_hash.h>
  70. #include <starpu_profiling.h>
  71. #include <starpu_fxt.h>
  72. #include <starpu_driver.h>
  73. #include <starpu_tree.h>
  74. #include <starpu_openmp.h>
  75. #include <starpu_simgrid_wrap.h>
  76. #include <starpu_bitmap.h>
  77. #include <starpu_clusters.h>
  78. #include <starpu_perf_monitoring.h>
  79. #include <starpu_perf_steering.h>
  80. #ifdef __cplusplus
  81. extern "C"
  82. {
  83. #endif
  84. /**
  85. @defgroup API_Initialization_and_Termination Initialization and Termination
  86. @{
  87. */
  88. /**
  89. Structure passed to the starpu_init() function to configure StarPU.
  90. It has to be initialized with starpu_conf_init(). When the default
  91. value is used, StarPU automatically selects the number of
  92. processing units and takes the default scheduling policy. The
  93. environment variables overwrite the equivalent parameters unless
  94. starpu_conf::precedence_over_environment_variables is set.
  95. */
  96. struct starpu_conf
  97. {
  98. /**
  99. @private
  100. Will be initialized by starpu_conf_init(). Should not be
  101. set by hand.
  102. */
  103. int magic;
  104. /**
  105. @private
  106. Tell starpu_init() if MPI will be initialized later.
  107. */
  108. int will_use_mpi;
  109. /**
  110. Name of the scheduling policy. This can also be specified
  111. with the environment variable \ref STARPU_SCHED. (default =
  112. <c>NULL</c>).
  113. */
  114. const char *sched_policy_name;
  115. /**
  116. Definition of the scheduling policy. This field is ignored
  117. if starpu_conf::sched_policy_name is set.
  118. (default = <c>NULL</c>)
  119. */
  120. struct starpu_sched_policy *sched_policy;
  121. /**
  122. Callback function that can later be used by the scheduler.
  123. The scheduler can retrieve this function by calling
  124. starpu_sched_ctx_get_sched_policy_callback()
  125. */
  126. void (*sched_policy_callback)(unsigned);
  127. /**
  128. For all parameters specified in this structure that can
  129. also be set with environment variables, by default,
  130. StarPU chooses the value of the environment variable
  131. against the value set in starpu_conf. Setting the parameter
  132. starpu_conf::precedence_over_environment_variables to 1 allows to give precedence
  133. to the value set in the structure over the environment
  134. variable.
  135. */
  136. int precedence_over_environment_variables;
  137. /**
  138. Number of CPU cores that StarPU can use. This can also be
  139. specified with the environment variable \ref STARPU_NCPU.
  140. (default = \c -1)
  141. */
  142. int ncpus;
  143. /**
  144. Number of CPU cores to that StarPU should leave aside. They can then
  145. be used by application threads, by calling starpu_get_next_bindid() to
  146. get their ID, and starpu_bind_thread_on() to bind the current thread to them.
  147. */
  148. int reserve_ncpus;
  149. /**
  150. Number of CUDA devices that StarPU can use. This can also
  151. be specified with the environment variable \ref
  152. STARPU_NCUDA.
  153. (default = \c -1)
  154. */
  155. int ncuda;
  156. /**
  157. Number of OpenCL devices that StarPU can use. This can also
  158. be specified with the environment variable \ref
  159. STARPU_NOPENCL.
  160. (default = \c -1)
  161. */
  162. int nopencl;
  163. /**
  164. Number of MPI Master Slave devices that StarPU can use.
  165. This can also be specified with the environment variable
  166. \ref STARPU_NMPI_MS.
  167. (default = \c -1)
  168. */
  169. int nmpi_ms;
  170. /**
  171. If this flag is set, the starpu_conf::workers_bindid array
  172. indicates where the different workers are bound, otherwise
  173. StarPU automatically selects where to bind the different
  174. workers. This can also be specified with the environment
  175. variable \ref STARPU_WORKERS_CPUID.
  176. (default = \c 0)
  177. */
  178. unsigned use_explicit_workers_bindid;
  179. /**
  180. If the starpu_conf::use_explicit_workers_bindid flag is
  181. set, this array indicates where to bind the different
  182. workers. The i-th entry of the starpu_conf::workers_bindid
  183. indicates the logical identifier of the processor which
  184. should execute the i-th worker. Note that the logical
  185. ordering of the CPUs is either determined by the OS, or
  186. provided by the \c hwloc library in case it is available.
  187. */
  188. unsigned workers_bindid[STARPU_NMAXWORKERS];
  189. /**
  190. If this flag is set, the CUDA workers will be attached to
  191. the CUDA devices specified in the
  192. starpu_conf::workers_cuda_gpuid array. Otherwise, StarPU
  193. affects the CUDA devices in a round-robin fashion. This can
  194. also be specified with the environment variable \ref
  195. STARPU_WORKERS_CUDAID.
  196. (default = \c 0)
  197. */
  198. unsigned use_explicit_workers_cuda_gpuid;
  199. /**
  200. If the starpu_conf::use_explicit_workers_cuda_gpuid flag is
  201. set, this array contains the logical identifiers of the
  202. CUDA devices (as used by \c cudaGetDevice()).
  203. */
  204. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  205. /**
  206. If this flag is set, the OpenCL workers will be attached to
  207. the OpenCL devices specified in the
  208. starpu_conf::workers_opencl_gpuid array. Otherwise, StarPU
  209. affects the OpenCL devices in a round-robin fashion. This
  210. can also be specified with the environment variable \ref
  211. STARPU_WORKERS_OPENCLID.
  212. (default = \c 0)
  213. */
  214. unsigned use_explicit_workers_opencl_gpuid;
  215. /**
  216. If the starpu_conf::use_explicit_workers_opencl_gpuid flag
  217. is set, this array contains the logical identifiers of the
  218. OpenCL devices to be used.
  219. */
  220. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  221. /**
  222. If this flag is set, the MPI Master Slave workers will be
  223. attached to the MPI Master Slave devices specified in the
  224. array starpu_conf::workers_mpi_ms_deviceid. Otherwise,
  225. StarPU affects the MPI Master Slave devices in a
  226. round-robin fashion.
  227. (default = \c 0)
  228. */
  229. unsigned use_explicit_workers_mpi_ms_deviceid;
  230. /**
  231. If the flag
  232. starpu_conf::use_explicit_workers_mpi_ms_deviceid is set,
  233. the array contains the logical identifiers of the MPI
  234. Master Slave devices to be used.
  235. */
  236. unsigned workers_mpi_ms_deviceid[STARPU_NMAXWORKERS];
  237. /**
  238. If this flag is set, StarPU will recalibrate the bus. If
  239. this value is equal to -1, the default value is used. This
  240. can also be specified with the environment variable \ref
  241. STARPU_BUS_CALIBRATE.
  242. (default = \c 0)
  243. */
  244. int bus_calibrate;
  245. /**
  246. If this flag is set, StarPU will calibrate the performance
  247. models when executing tasks. If this value is equal to -1,
  248. the default value is used. If the value is equal to 1, it
  249. will force continuing calibration. If the value is equal to
  250. 2, the existing performance models will be overwritten.
  251. This can also be specified with the environment variable
  252. \ref STARPU_CALIBRATE.
  253. (default = \c 0)
  254. */
  255. int calibrate;
  256. /**
  257. By default, StarPU executes parallel tasks concurrently.
  258. Some parallel libraries (e.g. most OpenMP implementations)
  259. however do not support concurrent calls to parallel code.
  260. In such case, setting this flag makes StarPU only start one
  261. parallel task at a time (but other CPU and GPU tasks are
  262. not affected and can be run concurrently). The parallel
  263. task scheduler will however still try varying combined
  264. worker sizes to look for the most efficient ones.
  265. This can also be specified with the environment variable
  266. \ref STARPU_SINGLE_COMBINED_WORKER.
  267. (default = \c 0)
  268. */
  269. int single_combined_worker;
  270. /**
  271. This flag should be set to 1 to disable asynchronous copies
  272. between CPUs and all accelerators.
  273. The AMD implementation of OpenCL is known to fail when
  274. copying data asynchronously. When using this
  275. implementation, it is therefore necessary to disable
  276. asynchronous data transfers.
  277. This can also be specified with the environment variable
  278. \ref STARPU_DISABLE_ASYNCHRONOUS_COPY.
  279. This can also be specified at compilation time by giving to
  280. the configure script the option \ref
  281. disable-asynchronous-copy "--disable-asynchronous-copy".
  282. (default = \c 0)
  283. */
  284. int disable_asynchronous_copy;
  285. /**
  286. This flag should be set to 1 to disable asynchronous copies
  287. between CPUs and CUDA accelerators.
  288. This can also be specified with the environment variable
  289. \ref STARPU_DISABLE_ASYNCHRONOUS_CUDA_COPY.
  290. This can also be specified at compilation time by giving to
  291. the configure script the option \ref
  292. disable-asynchronous-cuda-copy
  293. "--disable-asynchronous-cuda-copy".
  294. (default = \c 0)
  295. */
  296. int disable_asynchronous_cuda_copy;
  297. /**
  298. This flag should be set to 1 to disable asynchronous copies
  299. between CPUs and OpenCL accelerators.
  300. The AMD implementation of OpenCL is known to fail when
  301. copying data asynchronously. When using this
  302. implementation, it is therefore necessary to disable
  303. asynchronous data transfers.
  304. This can also be specified with the environment variable
  305. \ref STARPU_DISABLE_ASYNCHRONOUS_OPENCL_COPY.
  306. This can also be specified at compilation time by giving to
  307. the configure script the option \ref
  308. disable-asynchronous-opencl-copy
  309. "--disable-asynchronous-opencl-copy".
  310. (default = \c 0)
  311. */
  312. int disable_asynchronous_opencl_copy;
  313. /**
  314. This flag should be set to 1 to disable asynchronous copies
  315. between CPUs and MPI Master Slave devices.
  316. This can also be specified with the environment variable
  317. \ref STARPU_DISABLE_ASYNCHRONOUS_MPI_MS_COPY.
  318. This can also be specified at compilation time by giving to
  319. the configure script the option \ref
  320. disable-asynchronous-mpi-master-slave-copy
  321. "--disable-asynchronous-mpi-master-slave-copy".
  322. (default = \c 0).
  323. */
  324. int disable_asynchronous_mpi_ms_copy;
  325. /**
  326. Enable CUDA/OpenGL interoperation on these CUDA devices.
  327. This can be set to an array of CUDA device identifiers for
  328. which \c cudaGLSetGLDevice() should be called instead of \c
  329. cudaSetDevice(). Its size is specified by the
  330. starpu_conf::n_cuda_opengl_interoperability field below
  331. (default = <c>NULL</c>)
  332. */
  333. unsigned *cuda_opengl_interoperability;
  334. /**
  335. Size of the array starpu_conf::cuda_opengl_interoperability
  336. */
  337. unsigned n_cuda_opengl_interoperability;
  338. /**
  339. Array of drivers that should not be launched by StarPU. The
  340. application will run in one of its own threads.
  341. (default = <c>NULL</c>)
  342. */
  343. struct starpu_driver *not_launched_drivers;
  344. /**
  345. The number of StarPU drivers that should not be launched by
  346. StarPU, i.e number of elements of the array
  347. starpu_conf::not_launched_drivers.
  348. (default = \c 0)
  349. */
  350. unsigned n_not_launched_drivers;
  351. /**
  352. Specify the buffer size used for FxT tracing. Starting from
  353. FxT version 0.2.12, the buffer will automatically be
  354. flushed when it fills in, but it may still be interesting
  355. to specify a bigger value to avoid any flushing (which
  356. would disturb the trace).
  357. */
  358. uint64_t trace_buffer_size;
  359. /**
  360. Set the mininum priority used by priorities-aware
  361. schedulers.
  362. This also can be specified with the environment variable \ref
  363. STARPU_MIN_PRIO
  364. */
  365. int global_sched_ctx_min_priority;
  366. /**
  367. Set the maxinum priority used by priorities-aware
  368. schedulers.
  369. This also can be specified with the environment variable \ref
  370. STARPU_MAX_PRIO
  371. */
  372. int global_sched_ctx_max_priority;
  373. #ifdef STARPU_WORKER_CALLBACKS
  374. void (*callback_worker_going_to_sleep)(unsigned workerid);
  375. void (*callback_worker_waking_up)(unsigned workerid);
  376. #endif
  377. /**
  378. Specify if StarPU should catch \c SIGINT, \c SIGSEGV and \c SIGTRAP
  379. signals to make sure final actions (e.g dumping FxT trace
  380. files) are done even though the application has crashed. By
  381. default (value = \c 1), signals are catched. It should be
  382. disabled on systems which already catch these signals for
  383. their own needs (e.g JVM)
  384. This can also be specified with the environment variable
  385. \ref STARPU_CATCH_SIGNALS.
  386. */
  387. int catch_signals;
  388. /**
  389. Specify whether StarPU should automatically start to collect
  390. performance counters after initialization
  391. */
  392. unsigned start_perf_counter_collection;
  393. /**
  394. Minimum spinning backoff of drivers (default = \c 1)
  395. */
  396. unsigned driver_spinning_backoff_min;
  397. /**
  398. Maximum spinning backoff of drivers. (default = \c 32)
  399. */
  400. unsigned driver_spinning_backoff_max;
  401. /**
  402. Specify if CUDA workers should do only fast allocations
  403. when running the datawizard progress of
  404. other memory nodes. This will pass the interval value
  405. _STARPU_DATAWIZARD_ONLY_FAST_ALLOC to the allocation method.
  406. Default value is 0, allowing CUDA workers to do slow
  407. allocations.
  408. This can also be specified with the environment variable
  409. \ref STARPU_CUDA_ONLY_FAST_ALLOC_OTHER_MEMNODES.
  410. */
  411. int cuda_only_fast_alloc_other_memnodes;
  412. };
  413. /**
  414. Initialize the \p conf structure with the default values. In case
  415. some configuration parameters are already specified through
  416. environment variables, starpu_conf_init() initializes the fields of
  417. \p conf according to the environment variables.
  418. For instance if \ref STARPU_CALIBRATE is set, its value is put in
  419. the field starpu_conf::calibrate of \p conf.
  420. Upon successful completion, this function returns 0. Otherwise,
  421. <c>-EINVAL</c> indicates that the argument was <c>NULL</c>.
  422. */
  423. int starpu_conf_init(struct starpu_conf *conf);
  424. /**
  425. Set fields of \p conf so that no worker is enabled, i.e. set
  426. starpu_conf::ncpus = 0, starpu_conf::ncuda = 0, etc.
  427. This allows to portably enable only a given type of worker:
  428. <br/>
  429. <c>
  430. starpu_conf_noworker(&conf);<br/>
  431. conf.ncpus = -1;
  432. </c>
  433. */
  434. int starpu_conf_noworker(struct starpu_conf *conf);
  435. /**
  436. StarPU initialization method, must be called prior to any other
  437. StarPU call. It is possible to specify StarPU’s configuration (e.g.
  438. scheduling policy, number of cores, ...) by passing a
  439. non-<c>NULL</c> \p conf. Default configuration is used if \p conf
  440. is <c>NULL</c>. Upon successful completion, this function returns
  441. 0. Otherwise, <c>-ENODEV</c> indicates that no worker was available
  442. (and thus StarPU was not initialized).
  443. */
  444. int starpu_init(struct starpu_conf *conf) STARPU_WARN_UNUSED_RESULT;
  445. /**
  446. Similar to starpu_init(), but also take the \p argc and \p argv as
  447. defined by the application, which is necessary when running in
  448. Simgrid mode or MPI Master Slave mode.
  449. Do not call starpu_init() and starpu_initialize() in the same
  450. program.
  451. */
  452. int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv);
  453. /**
  454. Return 1 if StarPU is already initialized.
  455. */
  456. int starpu_is_initialized(void);
  457. /**
  458. Wait for starpu_init() call to finish.
  459. */
  460. void starpu_wait_initialized(void);
  461. /**
  462. StarPU termination method, must be called at the end of the
  463. application: statistics and other post-mortem debugging information
  464. are not guaranteed to be available until this method has been
  465. called.
  466. */
  467. void starpu_shutdown(void);
  468. /**
  469. Suspend the processing of new tasks by workers. It can be used in a
  470. program where StarPU is used during only a part of the execution.
  471. Without this call, the workers continue to poll for new tasks in a
  472. tight loop, wasting CPU time. The symmetric call to starpu_resume()
  473. should be used to unfreeze the workers.
  474. */
  475. void starpu_pause(void);
  476. /**
  477. Symmetrical call to starpu_pause(), used to resume the workers
  478. polling for new tasks.
  479. */
  480. void starpu_resume(void);
  481. /**
  482. Return !0 if task processing by workers is currently paused, 0 otherwise.
  483. */
  484. int starpu_is_paused(void);
  485. /**
  486. Value to be passed to starpu_get_next_bindid() and
  487. starpu_bind_thread_on() when binding a thread which will
  488. significantly eat CPU time, and should thus have its own dedicated
  489. CPU.
  490. */
  491. #define STARPU_THREAD_ACTIVE (1 << 0)
  492. /**
  493. Return a PU binding ID which can be used to bind threads with
  494. starpu_bind_thread_on(). \p flags can be set to
  495. ::STARPU_THREAD_ACTIVE or 0. When \p npreferred is set to non-zero,
  496. \p preferred is an array of size \p npreferred in which a
  497. preference of PU binding IDs can be set. By default StarPU will
  498. return the first PU available for binding.
  499. */
  500. unsigned starpu_get_next_bindid(unsigned flags, unsigned *preferred, unsigned npreferred);
  501. /**
  502. Bind the calling thread on the given \p cpuid (which should have
  503. been obtained with starpu_get_next_bindid()).
  504. Return -1 if a thread was already bound to this PU (but binding
  505. will still have been done, and a warning will have been printed),
  506. so the caller can tell the user how to avoid the issue.
  507. \p name should be set to a unique string so that different calls
  508. with the same name for the same \p cpuid does not produce a warning.
  509. */
  510. int starpu_bind_thread_on(int cpuid, unsigned flags, const char *name);
  511. /**
  512. Print a description of the topology on \p f.
  513. */
  514. void starpu_topology_print(FILE *f);
  515. /**
  516. Return 1 if asynchronous data transfers between CPU and
  517. accelerators are disabled.
  518. */
  519. int starpu_asynchronous_copy_disabled(void);
  520. /**
  521. Return 1 if asynchronous data transfers between CPU and CUDA
  522. accelerators are disabled.
  523. */
  524. int starpu_asynchronous_cuda_copy_disabled(void);
  525. /**
  526. Return 1 if asynchronous data transfers between CPU and OpenCL
  527. accelerators are disabled.
  528. */
  529. int starpu_asynchronous_opencl_copy_disabled(void);
  530. /**
  531. Return 1 if asynchronous data transfers between CPU and MPI Slave
  532. devices are disabled.
  533. */
  534. int starpu_asynchronous_mpi_ms_copy_disabled(void);
  535. /**
  536. Call starpu_profiling_bus_helper_display_summary() and
  537. starpu_profiling_worker_helper_display_summary()
  538. */
  539. void starpu_display_stats(void);
  540. /** @} */
  541. /**
  542. @defgroup API_Versioning Versioning
  543. @{
  544. */
  545. /**
  546. Return as 3 integers the version of StarPU used when running the
  547. application.
  548. */
  549. void starpu_get_version(int *major, int *minor, int *release);
  550. /** @} */
  551. #ifdef __cplusplus
  552. }
  553. #endif
  554. #include "starpu_deprecated_api.h"
  555. #endif /* __STARPU_H__ */