starpu.h 20 KB

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