starpu.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. /**
  120. Callback function that can later be used by the scheduler.
  121. The scheduler can retrieve this function by calling
  122. starpu_sched_ctx_get_sched_policy_callback()
  123. */
  124. void (*sched_policy_callback)(unsigned);
  125. /**
  126. For all parameters specified in this structure that can
  127. also be set with environment variables, by default,
  128. StarPU chooses the value of the environment variable
  129. against the value set in starpu_conf. Setting the parameter
  130. starpu_conf::precedence_over_environment_variables to 1 allows to give precedence
  131. to the value set in the structure over the environment
  132. variable.
  133. */
  134. int precedence_over_environment_variables;
  135. /**
  136. Number of CPU cores that StarPU can use. This can also be
  137. specified with the environment variable \ref STARPU_NCPU.
  138. (default = -1)
  139. */
  140. int ncpus;
  141. /**
  142. Number of CPU cores to that StarPU should leave aside. They can then
  143. be used by application threads, by calling starpu_get_next_bindid() to
  144. get their ID, and starpu_bind_thread_on() to bind the current thread to them.
  145. */
  146. int reserve_ncpus;
  147. /**
  148. Number of CUDA devices that StarPU can use. This can also
  149. be specified with the environment variable \ref
  150. STARPU_NCUDA.
  151. (default = -1)
  152. */
  153. int ncuda;
  154. /**
  155. Number of OpenCL devices that StarPU can use. This can also
  156. be specified with the environment variable \ref
  157. STARPU_NOPENCL.
  158. (default = -1)
  159. */
  160. int nopencl;
  161. /**
  162. Number of MPI Master Slave devices that StarPU can use.
  163. This can also be specified with the environment variable
  164. \ref STARPU_NMPI_MS.
  165. (default = -1)
  166. */
  167. int nmpi_ms;
  168. /**
  169. If this flag is set, the starpu_conf::workers_bindid array
  170. indicates where the different workers are bound, otherwise
  171. StarPU automatically selects where to bind the different
  172. workers. This can also be specified with the environment
  173. variable \ref STARPU_WORKERS_CPUID.
  174. (default = 0)
  175. */
  176. unsigned use_explicit_workers_bindid;
  177. /**
  178. If the starpu_conf::use_explicit_workers_bindid flag is
  179. set, this array indicates where to bind the different
  180. workers. The i-th entry of the starpu_conf::workers_bindid
  181. indicates the logical identifier of the processor which
  182. should execute the i-th worker. Note that the logical
  183. ordering of the CPUs is either determined by the OS, or
  184. provided by the hwloc library in case it is available.
  185. */
  186. unsigned workers_bindid[STARPU_NMAXWORKERS];
  187. /**
  188. If this flag is set, the CUDA workers will be attached to
  189. the CUDA devices specified in the
  190. starpu_conf::workers_cuda_gpuid array. Otherwise, StarPU
  191. affects the CUDA devices in a round-robin fashion. This can
  192. also be specified with the environment variable \ref
  193. STARPU_WORKERS_CUDAID.
  194. (default = 0)
  195. */
  196. unsigned use_explicit_workers_cuda_gpuid;
  197. /**
  198. If the starpu_conf::use_explicit_workers_cuda_gpuid flag is
  199. set, this array contains the logical identifiers of the
  200. CUDA devices (as used by \c cudaGetDevice()).
  201. */
  202. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  203. /**
  204. If this flag is set, the OpenCL workers will be attached to
  205. the OpenCL devices specified in the
  206. starpu_conf::workers_opencl_gpuid array. Otherwise, StarPU
  207. affects the OpenCL devices in a round-robin fashion. This
  208. can also be specified with the environment variable \ref
  209. STARPU_WORKERS_OPENCLID.
  210. (default = 0)
  211. */
  212. unsigned use_explicit_workers_opencl_gpuid;
  213. /**
  214. If the starpu_conf::use_explicit_workers_opencl_gpuid flag
  215. is set, this array contains the logical identifiers of the
  216. OpenCL devices to be used.
  217. */
  218. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  219. /**
  220. If this flag is set, the MPI Master Slave workers will be
  221. attached to the MPI Master Slave devices specified in the
  222. array starpu_conf::workers_mpi_ms_deviceid. Otherwise,
  223. StarPU affects the MPI Master Slave devices in a
  224. round-robin fashion.
  225. (default = 0)
  226. */
  227. unsigned use_explicit_workers_mpi_ms_deviceid;
  228. /**
  229. If the flag
  230. starpu_conf::use_explicit_workers_mpi_ms_deviceid is set,
  231. the array contains the logical identifiers of the MPI
  232. Master Slave devices to be used.
  233. */
  234. unsigned workers_mpi_ms_deviceid[STARPU_NMAXWORKERS];
  235. /**
  236. If this flag is set, StarPU will recalibrate the bus. If
  237. this value is equal to -1, the default value is used. This
  238. can also be specified with the environment variable \ref
  239. STARPU_BUS_CALIBRATE.
  240. (default = 0)
  241. */
  242. int bus_calibrate;
  243. /**
  244. If this flag is set, StarPU will calibrate the performance
  245. models when executing tasks. If this value is equal to -1,
  246. the default value is used. If the value is equal to 1, it
  247. will force continuing calibration. If the value is equal to
  248. 2, the existing performance models will be overwritten.
  249. This can also be specified with the environment variable
  250. \ref STARPU_CALIBRATE.
  251. (default = 0)
  252. */
  253. int calibrate;
  254. /**
  255. By default, StarPU executes parallel tasks concurrently.
  256. Some parallel libraries (e.g. most OpenMP implementations)
  257. however do not support concurrent calls to parallel code.
  258. In such case, setting this flag makes StarPU only start one
  259. parallel task at a time (but other CPU and GPU tasks are
  260. not affected and can be run concurrently). The parallel
  261. task scheduler will however still try varying combined
  262. worker sizes to look for the most efficient ones.
  263. This can also be specified with the environment variable
  264. \ref STARPU_SINGLE_COMBINED_WORKER.
  265. (default = 0)
  266. */
  267. int single_combined_worker;
  268. /**
  269. This flag should be set to 1 to disable asynchronous copies
  270. between CPUs and all accelerators.
  271. The AMD implementation of OpenCL is known to fail when
  272. copying data asynchronously. When using this
  273. implementation, it is therefore necessary to disable
  274. asynchronous data transfers.
  275. This can also be specified with the environment variable
  276. \ref STARPU_DISABLE_ASYNCHRONOUS_COPY.
  277. This can also be specified at compilation time by giving to
  278. the configure script the option \ref
  279. disable-asynchronous-copy "--disable-asynchronous-copy".
  280. (default = 0)
  281. */
  282. int disable_asynchronous_copy;
  283. /**
  284. This flag should be set to 1 to disable asynchronous copies
  285. between CPUs and CUDA accelerators.
  286. This can also be specified with the environment variable
  287. \ref STARPU_DISABLE_ASYNCHRONOUS_CUDA_COPY.
  288. This can also be specified at compilation time by giving to
  289. the configure script the option \ref
  290. disable-asynchronous-cuda-copy
  291. "--disable-asynchronous-cuda-copy".
  292. (default = 0)
  293. */
  294. int disable_asynchronous_cuda_copy;
  295. /**
  296. This flag should be set to 1 to disable asynchronous copies
  297. between CPUs and OpenCL accelerators.
  298. The AMD implementation of OpenCL is known to fail when
  299. copying data asynchronously. When using this
  300. implementation, it is therefore necessary to disable
  301. asynchronous data transfers.
  302. This can also be specified with the environment variable
  303. \ref STARPU_DISABLE_ASYNCHRONOUS_OPENCL_COPY.
  304. This can also be specified at compilation time by giving to
  305. the configure script the option \ref
  306. disable-asynchronous-opencl-copy
  307. "--disable-asynchronous-opencl-copy".
  308. (default = 0)
  309. */
  310. int disable_asynchronous_opencl_copy;
  311. /**
  312. This flag should be set to 1 to disable asynchronous copies
  313. between CPUs and MPI Master Slave devices.
  314. This can also be specified with the environment variable
  315. \ref STARPU_DISABLE_ASYNCHRONOUS_MPI_MS_COPY.
  316. This can also be specified at compilation time by giving to
  317. the configure script the option \ref
  318. disable-asynchronous-mpi-master-slave-copy
  319. "--disable-asynchronous-mpi-master-slave-copy".
  320. (default = 0).
  321. */
  322. int disable_asynchronous_mpi_ms_copy;
  323. /**
  324. Enable CUDA/OpenGL interoperation on these CUDA devices.
  325. This can be set to an array of CUDA device identifiers for
  326. which \c cudaGLSetGLDevice() should be called instead of \c
  327. cudaSetDevice(). Its size is specified by the
  328. starpu_conf::n_cuda_opengl_interoperability field below
  329. (default = <c>NULL</c>)
  330. */
  331. unsigned *cuda_opengl_interoperability;
  332. /**
  333. Size of the array starpu_conf::cuda_opengl_interoperability
  334. */
  335. unsigned n_cuda_opengl_interoperability;
  336. /**
  337. Array of drivers that should not be launched by StarPU. The
  338. application will run in one of its own threads.
  339. (default = <c>NULL</c>)
  340. */
  341. struct starpu_driver *not_launched_drivers;
  342. /**
  343. The number of StarPU drivers that should not be launched by
  344. StarPU, i.e number of elements of the array
  345. starpu_conf::not_launched_drivers.
  346. (default = 0)
  347. */
  348. unsigned n_not_launched_drivers;
  349. /**
  350. Specify the buffer size used for FxT tracing. Starting from
  351. FxT version 0.2.12, the buffer will automatically be
  352. flushed when it fills in, but it may still be interesting
  353. to specify a bigger value to avoid any flushing (which
  354. would disturb the trace).
  355. */
  356. uint64_t trace_buffer_size;
  357. int global_sched_ctx_min_priority;
  358. int global_sched_ctx_max_priority;
  359. #ifdef STARPU_WORKER_CALLBACKS
  360. void (*callback_worker_going_to_sleep)(unsigned workerid);
  361. void (*callback_worker_waking_up)(unsigned workerid);
  362. #endif
  363. /**
  364. Specify if StarPU should catch SIGINT, SIGSEGV and SIGTRAP
  365. signals to make sure final actions (e.g dumping FxT trace
  366. files) are done even though the application has crashed. By
  367. default (value = \c 1), signals are catched. It should be
  368. disabled on systems which already catch these signals for
  369. their own needs (e.g JVM)
  370. This can also be specified with the environment variable
  371. \ref STARPU_CATCH_SIGNALS
  372. */
  373. int catch_signals;
  374. /**
  375. Specify whether StarPU should automatically start to collect
  376. performance counters after initialization
  377. */
  378. unsigned start_perf_counter_collection;
  379. /**
  380. Minimum spinning backoff of drivers. Default value: \c 1
  381. */
  382. unsigned driver_spinning_backoff_min;
  383. /**
  384. Maximum spinning backoff of drivers. Default value: \c 32
  385. */
  386. unsigned driver_spinning_backoff_max;
  387. /**
  388. Specify if CUDA workers should do only fast allocations
  389. when running the datawizard progress of
  390. other memory nodes. This will pass STARPU_DATAWIZARD_ONLY_FAST_ALLOC.
  391. Default value is 0, allowing CUDA workers to do slow allocations.
  392. */
  393. int cuda_only_fast_alloc_other_memnodes;
  394. };
  395. /**
  396. Initialize the \p conf structure with the default values. In case
  397. some configuration parameters are already specified through
  398. environment variables, starpu_conf_init() initializes the fields of
  399. \p conf according to the environment variables.
  400. For instance if \ref STARPU_CALIBRATE is set, its value is put in
  401. the field starpu_conf::calibrate of \p conf.
  402. Upon successful completion, this function returns 0. Otherwise,
  403. <c>-EINVAL</c> indicates that the argument was <c>NULL</c>.
  404. */
  405. int starpu_conf_init(struct starpu_conf *conf);
  406. /**
  407. Set fields of \p conf so that no worker is enabled, i.e. set
  408. starpu_conf::ncpus = 0, starpu_conf::ncuda = 0, etc.
  409. This allows to portably enable only a given type of worker:
  410. starpu_conf_noworker(&conf);
  411. conf.ncpus = -1;
  412. */
  413. int starpu_conf_noworker(struct starpu_conf *conf);
  414. /**
  415. StarPU initialization method, must be called prior to any other
  416. StarPU call. It is possible to specify StarPU’s configuration (e.g.
  417. scheduling policy, number of cores, ...) by passing a
  418. non-<c>NULL</c> \p conf. Default configuration is used if \p conf
  419. is <c>NULL</c>. Upon successful completion, this function returns
  420. 0. Otherwise, <c>-ENODEV</c> indicates that no worker was available
  421. (and thus StarPU was not initialized).
  422. */
  423. int starpu_init(struct starpu_conf *conf) STARPU_WARN_UNUSED_RESULT;
  424. /**
  425. Similar to starpu_init(), but also take the \p argc and \p argv as
  426. defined by the application.
  427. Do not call starpu_init() and starpu_initialize() in the same
  428. program.
  429. */
  430. int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv);
  431. /**
  432. Return 1 if StarPU is already initialized.
  433. */
  434. int starpu_is_initialized(void);
  435. /**
  436. Wait for starpu_init() call to finish.
  437. */
  438. void starpu_wait_initialized(void);
  439. /**
  440. StarPU termination method, must be called at the end of the
  441. application: statistics and other post-mortem debugging information
  442. are not guaranteed to be available until this method has been
  443. called.
  444. */
  445. void starpu_shutdown(void);
  446. /**
  447. Suspend the processing of new tasks by workers. It can be used in a
  448. program where StarPU is used during only a part of the execution.
  449. Without this call, the workers continue to poll for new tasks in a
  450. tight loop, wasting CPU time. The symmetric call to starpu_resume()
  451. should be used to unfreeze the workers.
  452. */
  453. void starpu_pause(void);
  454. /**
  455. Symmetrical call to starpu_pause(), used to resume the workers
  456. polling for new tasks.
  457. */
  458. void starpu_resume(void);
  459. /**
  460. Value to be passed to starpu_get_next_bindid() and
  461. starpu_bind_thread_on() when binding a thread which will
  462. significantly eat CPU time, and should thus have its own dedicated
  463. CPU.
  464. */
  465. #define STARPU_THREAD_ACTIVE (1 << 0)
  466. /**
  467. Return a PU binding ID which can be used to bind threads with
  468. starpu_bind_thread_on(). \p flags can be set to
  469. STARPU_THREAD_ACTIVE or 0. When \p npreferred is set to non-zero,
  470. \p preferred is an array of size \p npreferred in which a
  471. preference of PU binding IDs can be set. By default StarPU will
  472. return the first PU available for binding.
  473. */
  474. unsigned starpu_get_next_bindid(unsigned flags, unsigned *preferred, unsigned npreferred);
  475. /**
  476. Bind the calling thread on the given \p cpuid (which should have
  477. been obtained with starpu_get_next_bindid()).
  478. Return -1 if a thread was already bound to this PU (but binding
  479. will still have been done, and a warning will have been printed),
  480. so the caller can tell the user how to avoid the issue.
  481. \p name should be set to a unique string so that different calls
  482. with the same name for the same cpuid does not produce a warning.
  483. */
  484. int starpu_bind_thread_on(int cpuid, unsigned flags, const char *name);
  485. /**
  486. Print a description of the topology on \p f.
  487. */
  488. void starpu_topology_print(FILE *f);
  489. /**
  490. Return 1 if asynchronous data transfers between CPU and
  491. accelerators are disabled.
  492. */
  493. int starpu_asynchronous_copy_disabled(void);
  494. /**
  495. Return 1 if asynchronous data transfers between CPU and CUDA
  496. accelerators are disabled.
  497. */
  498. int starpu_asynchronous_cuda_copy_disabled(void);
  499. /**
  500. Return 1 if asynchronous data transfers between CPU and OpenCL
  501. accelerators are disabled.
  502. */
  503. int starpu_asynchronous_opencl_copy_disabled(void);
  504. /**
  505. Return 1 if asynchronous data transfers between CPU and MPI Slave
  506. devices are disabled.
  507. */
  508. int starpu_asynchronous_mpi_ms_copy_disabled(void);
  509. /**
  510. Call starpu_profiling_bus_helper_display_summary() and
  511. starpu_profiling_worker_helper_display_summary()
  512. */
  513. void starpu_display_stats(void);
  514. /** @} */
  515. /**
  516. @defgroup API_Versioning Versioning
  517. @{
  518. */
  519. /**
  520. Return as 3 integers the version of StarPU used when running the
  521. application.
  522. */
  523. void starpu_get_version(int *major, int *minor, int *release);
  524. /** @} */
  525. #ifdef __cplusplus
  526. }
  527. #endif
  528. #include "starpu_deprecated_api.h"
  529. #endif /* __STARPU_H__ */