starpu.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2017 Inria
  4. * Copyright (C) 2009-2014,2016-2019 Université de Bordeaux
  5. * Copyright (C) 2010-2015,2017,2019 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_H__
  19. #define __STARPU_H__
  20. #include <stdlib.h>
  21. #ifndef _MSC_VER
  22. #include <stdint.h>
  23. #else
  24. #include <windows.h>
  25. typedef unsigned char uint8_t;
  26. typedef unsigned short uint16_t;
  27. typedef unsigned int uint32_t;
  28. typedef unsigned long long uint64_t;
  29. typedef UINT_PTR uintptr_t;
  30. typedef char int8_t;
  31. typedef short int16_t;
  32. typedef int int32_t;
  33. typedef long long int64_t;
  34. typedef INT_PTR intptr_t;
  35. #endif
  36. #include <starpu_config.h>
  37. #ifdef STARPU_HAVE_WINDOWS
  38. #include <windows.h>
  39. #endif
  40. #if defined(STARPU_USE_OPENCL) && !defined(__CUDACC__)
  41. #include <starpu_opencl.h>
  42. #endif
  43. #include <starpu_thread.h>
  44. #include <starpu_thread_util.h>
  45. #include <starpu_util.h>
  46. #include <starpu_data.h>
  47. #include <starpu_helper.h>
  48. #include <starpu_disk.h>
  49. #include <starpu_data_interfaces.h>
  50. #include <starpu_data_filters.h>
  51. #include <starpu_stdlib.h>
  52. #include <starpu_task_bundle.h>
  53. #include <starpu_task_dep.h>
  54. #include <starpu_task.h>
  55. #include <starpu_worker.h>
  56. #include <starpu_perfmodel.h>
  57. #include <starpu_worker.h>
  58. #ifndef BUILDING_STARPU
  59. #include <starpu_task_list.h>
  60. #endif
  61. #include <starpu_task_util.h>
  62. #include <starpu_scheduler.h>
  63. #include <starpu_sched_ctx.h>
  64. #include <starpu_expert.h>
  65. #include <starpu_rand.h>
  66. #include <starpu_cuda.h>
  67. #include <starpu_cublas.h>
  68. #include <starpu_cusparse.h>
  69. #include <starpu_bound.h>
  70. #include <starpu_hash.h>
  71. #include <starpu_profiling.h>
  72. #include <starpu_fxt.h>
  73. #include <starpu_driver.h>
  74. #include <starpu_tree.h>
  75. #include <starpu_openmp.h>
  76. #include <starpu_simgrid_wrap.h>
  77. #include <starpu_bitmap.h>
  78. #include <starpu_clusters.h>
  79. #include <starpu_perf_monitoring.h>
  80. #include <starpu_perf_steering.h>
  81. #ifdef __cplusplus
  82. extern "C"
  83. {
  84. #endif
  85. /**
  86. @defgroup API_Initialization_and_Termination Initialization and Termination
  87. @{
  88. */
  89. /**
  90. Structure passed to the starpu_init() function to configure StarPU.
  91. It has to be initialized with starpu_conf_init(). When the default
  92. value is used, StarPU automatically selects the number of
  93. processing units and takes the default scheduling policy. The
  94. environment variables overwrite the equivalent parameters.
  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. Name of the scheduling policy. This can also be specified
  106. with the environment variable \ref STARPU_SCHED. (default =
  107. <c>NULL</c>).
  108. */
  109. const char *sched_policy_name;
  110. /**
  111. Definition of the scheduling policy. This field is ignored
  112. if starpu_conf::sched_policy_name is set.
  113. (default = <c>NULL</c>)
  114. */
  115. struct starpu_sched_policy *sched_policy;
  116. void (*sched_policy_init)(unsigned);
  117. /**
  118. Number of CPU cores that StarPU can use. This can also be
  119. specified with the environment variable \ref STARPU_NCPU.
  120. (default = -1)
  121. */
  122. int ncpus;
  123. /**
  124. Number of CPU cores to that StarPU should leave aside. They can then
  125. be used by application threads, by calling starpu_get_next_bindid() to
  126. get their ID, and starpu_bind_thread_on() to bind the current thread to them.
  127. */
  128. int reserve_ncpus;
  129. /**
  130. Number of CUDA devices that StarPU can use. This can also
  131. be specified with the environment variable \ref
  132. STARPU_NCUDA.
  133. (default = -1)
  134. */
  135. int ncuda;
  136. /**
  137. Number of OpenCL devices that StarPU can use. This can also
  138. be specified with the environment variable \ref
  139. STARPU_NOPENCL.
  140. (default = -1)
  141. */
  142. int nopencl;
  143. /**
  144. Number of MIC devices that StarPU can use. This can also be
  145. specified with the environment variable \ref STARPU_NMIC.
  146. (default = -1)
  147. */
  148. int nmic;
  149. /**
  150. Number of MPI Master Slave devices that StarPU can use.
  151. This can also be specified with the environment variable
  152. \ref STARPU_NMPI_MS.
  153. (default = -1)
  154. */
  155. int nmpi_ms;
  156. /**
  157. If this flag is set, the starpu_conf::workers_bindid array
  158. indicates where the different workers are bound, otherwise
  159. StarPU automatically selects where to bind the different
  160. workers. This can also be specified with the environment
  161. variable \ref STARPU_WORKERS_CPUID.
  162. (default = 0)
  163. */
  164. unsigned use_explicit_workers_bindid;
  165. /**
  166. If the starpu_conf::use_explicit_workers_bindid flag is
  167. set, this array indicates where to bind the different
  168. workers. The i-th entry of the starpu_conf::workers_bindid
  169. indicates the logical identifier of the processor which
  170. should execute the i-th worker. Note that the logical
  171. ordering of the CPUs is either determined by the OS, or
  172. provided by the hwloc library in case it is available.
  173. */
  174. unsigned workers_bindid[STARPU_NMAXWORKERS];
  175. /**
  176. If this flag is set, the CUDA workers will be attached to
  177. the CUDA devices specified in the
  178. starpu_conf::workers_cuda_gpuid array. Otherwise, StarPU
  179. affects the CUDA devices in a round-robin fashion. This can
  180. also be specified with the environment variable \ref
  181. STARPU_WORKERS_CUDAID.
  182. (default = 0)
  183. */
  184. unsigned use_explicit_workers_cuda_gpuid;
  185. /**
  186. If the starpu_conf::use_explicit_workers_cuda_gpuid flag is
  187. set, this array contains the logical identifiers of the
  188. CUDA devices (as used by \c cudaGetDevice()).
  189. */
  190. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  191. /**
  192. If this flag is set, the OpenCL workers will be attached to
  193. the OpenCL devices specified in the
  194. starpu_conf::workers_opencl_gpuid array. Otherwise, StarPU
  195. affects the OpenCL devices in a round-robin fashion. This
  196. can also be specified with the environment variable \ref
  197. STARPU_WORKERS_OPENCLID.
  198. (default = 0)
  199. */
  200. unsigned use_explicit_workers_opencl_gpuid;
  201. /**
  202. If the starpu_conf::use_explicit_workers_opencl_gpuid flag
  203. is set, this array contains the logical identifiers of the
  204. OpenCL devices to be used.
  205. */
  206. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  207. /**
  208. If this flag is set, the MIC workers will be attached to
  209. the MIC devices specified in the array
  210. starpu_conf::workers_mic_deviceid. Otherwise, StarPU
  211. affects the MIC devices in a round-robin fashion. This can
  212. also be specified with the environment variable \ref
  213. STARPU_WORKERS_MICID.
  214. (default = 0)
  215. */
  216. unsigned use_explicit_workers_mic_deviceid;
  217. /**
  218. If the flag starpu_conf::use_explicit_workers_mic_deviceid
  219. is set, the array contains the logical identifiers of the
  220. MIC devices to be used.
  221. */
  222. unsigned workers_mic_deviceid[STARPU_NMAXWORKERS];
  223. /**
  224. If this flag is set, the MPI Master Slave workers will be
  225. attached to the MPI Master Slave devices specified in the
  226. array starpu_conf::workers_mpi_ms_deviceid. Otherwise,
  227. StarPU affects the MPI Master Slave devices in a
  228. round-robin fashion.
  229. (default = 0)
  230. */
  231. unsigned use_explicit_workers_mpi_ms_deviceid;
  232. /**
  233. If the flag
  234. starpu_conf::use_explicit_workers_mpi_ms_deviceid is set,
  235. the array contains the logical identifiers of the MPI
  236. Master Slave devices to be used.
  237. */
  238. unsigned workers_mpi_ms_deviceid[STARPU_NMAXWORKERS];
  239. /**
  240. If this flag is set, StarPU will recalibrate the bus. If
  241. this value is equal to -1, the default value is used. This
  242. can also be specified with the environment variable \ref
  243. STARPU_BUS_CALIBRATE.
  244. (default = 0)
  245. */
  246. int bus_calibrate;
  247. /**
  248. If this flag is set, StarPU will calibrate the performance
  249. models when executing tasks. If this value is equal to -1,
  250. the default value is used. If the value is equal to 1, it
  251. will force continuing calibration. If the value is equal to
  252. 2, the existing performance models will be overwritten.
  253. This can also be specified with the environment variable
  254. \ref STARPU_CALIBRATE.
  255. (default = 0)
  256. */
  257. int calibrate;
  258. /**
  259. By default, StarPU executes parallel tasks concurrently.
  260. Some parallel libraries (e.g. most OpenMP implementations)
  261. however do not support concurrent calls to parallel code.
  262. In such case, setting this flag makes StarPU only start one
  263. parallel task at a time (but other CPU and GPU tasks are
  264. not affected and can be run concurrently). The parallel
  265. task scheduler will however still try varying combined
  266. worker sizes to look for the most efficient ones.
  267. This can also be specified with the environment variable
  268. \ref STARPU_SINGLE_COMBINED_WORKER.
  269. (default = 0)
  270. */
  271. int single_combined_worker;
  272. /**
  273. Path to the kernel to execute on the MIC device, compiled
  274. for MIC architecture. When set to <c>NULL</c>, StarPU
  275. automatically looks next to the host program location.
  276. (default = <c>NULL</c>)
  277. */
  278. char *mic_sink_program_path;
  279. /**
  280. This flag should be set to 1 to disable asynchronous copies
  281. between CPUs and all accelerators.
  282. The AMD implementation of OpenCL is known to fail when
  283. copying data asynchronously. When using this
  284. implementation, it is therefore necessary to disable
  285. asynchronous data transfers.
  286. This can also be specified with the environment variable
  287. \ref STARPU_DISABLE_ASYNCHRONOUS_COPY.
  288. This can also be specified at compilation time by giving to
  289. the configure script the option \ref
  290. disable-asynchronous-copy "--disable-asynchronous-copy".
  291. (default = 0)
  292. */
  293. int disable_asynchronous_copy;
  294. /**
  295. This flag should be set to 1 to disable asynchronous copies
  296. between CPUs and CUDA accelerators.
  297. This can also be specified with the environment variable
  298. \ref STARPU_DISABLE_ASYNCHRONOUS_CUDA_COPY.
  299. This can also be specified at compilation time by giving to
  300. the configure script the option \ref
  301. disable-asynchronous-cuda-copy
  302. "--disable-asynchronous-cuda-copy".
  303. (default = 0)
  304. */
  305. int disable_asynchronous_cuda_copy;
  306. /**
  307. This flag should be set to 1 to disable asynchronous copies
  308. between CPUs and OpenCL accelerators.
  309. The AMD implementation of OpenCL is known to fail when
  310. copying data asynchronously. When using this
  311. implementation, it is therefore necessary to disable
  312. asynchronous data transfers.
  313. This can also be specified with the environment variable
  314. \ref STARPU_DISABLE_ASYNCHRONOUS_OPENCL_COPY.
  315. This can also be specified at compilation time by giving to
  316. the configure script the option \ref
  317. disable-asynchronous-opencl-copy
  318. "--disable-asynchronous-opencl-copy".
  319. (default = 0)
  320. */
  321. int disable_asynchronous_opencl_copy;
  322. /**
  323. This flag should be set to 1 to disable asynchronous copies
  324. between CPUs and MIC accelerators.
  325. This can also be specified with the environment variable
  326. \ref STARPU_DISABLE_ASYNCHRONOUS_MIC_COPY.
  327. This can also be specified at compilation time by giving to
  328. the configure script the option \ref
  329. disable-asynchronous-mic-copy
  330. "--disable-asynchronous-mic-copy".
  331. (default = 0).
  332. */
  333. int disable_asynchronous_mic_copy;
  334. /**
  335. This flag should be set to 1 to disable asynchronous copies
  336. between CPUs and MPI Master Slave devices.
  337. This can also be specified with the environment variable
  338. \ref STARPU_DISABLE_ASYNCHRONOUS_MPI_MS_COPY.
  339. This can also be specified at compilation time by giving to
  340. the configure script the option \ref
  341. disable-asynchronous-mpi-master-slave-copy
  342. "--disable-asynchronous-mpi-master-slave-copy".
  343. (default = 0).
  344. */
  345. int disable_asynchronous_mpi_ms_copy;
  346. /**
  347. Enable CUDA/OpenGL interoperation on these CUDA devices.
  348. This can be set to an array of CUDA device identifiers for
  349. which \c cudaGLSetGLDevice() should be called instead of \c
  350. cudaSetDevice(). Its size is specified by the
  351. starpu_conf::n_cuda_opengl_interoperability field below
  352. (default = <c>NULL</c>)
  353. */
  354. unsigned *cuda_opengl_interoperability;
  355. /**
  356. Size of the array starpu_conf::cuda_opengl_interoperability
  357. */
  358. unsigned n_cuda_opengl_interoperability;
  359. /**
  360. Array of drivers that should not be launched by StarPU. The
  361. application will run in one of its own threads.
  362. (default = <c>NULL</c>)
  363. */
  364. struct starpu_driver *not_launched_drivers;
  365. /**
  366. The number of StarPU drivers that should not be launched by
  367. StarPU, i.e number of elements of the array
  368. starpu_conf::not_launched_drivers.
  369. (default = 0)
  370. */
  371. unsigned n_not_launched_drivers;
  372. /**
  373. Specify the buffer size used for FxT tracing. Starting from
  374. FxT version 0.2.12, the buffer will automatically be
  375. flushed when it fills in, but it may still be interesting
  376. to specify a bigger value to avoid any flushing (which
  377. would disturb the trace).
  378. */
  379. unsigned trace_buffer_size;
  380. int global_sched_ctx_min_priority;
  381. int global_sched_ctx_max_priority;
  382. #ifdef STARPU_WORKER_CALLBACKS
  383. void (*callback_worker_going_to_sleep)(unsigned workerid);
  384. void (*callback_worker_waking_up)(unsigned workerid);
  385. #endif
  386. /**
  387. Specify if StarPU should catch SIGINT, SIGSEGV and SIGTRAP
  388. signals to make sure final actions (e.g dumping FxT trace
  389. files) are done even though the application has crashed. By
  390. default (value = \c 1), signals are catched. It should be
  391. disabled on systems which already catch these signals for
  392. their own needs (e.g JVM)
  393. This can also be specified with the environment variable
  394. \ref STARPU_CATCH_SIGNALS
  395. */
  396. int catch_signals;
  397. /**
  398. Specify whether StarPU should automatically start to collect
  399. performance counters after initialization
  400. */
  401. unsigned start_perf_counter_collection;
  402. };
  403. /**
  404. Initialize the \p conf structure with the default values. In case
  405. some configuration parameters are already specified through
  406. environment variables, starpu_conf_init() initializes the fields of
  407. \p conf according to the environment variables.
  408. For instance if \ref STARPU_CALIBRATE is set, its value is put in
  409. the field starpu_conf::calibrate of \p conf.
  410. Upon successful completion, this function returns 0. Otherwise,
  411. <c>-EINVAL</c> indicates that the argument was <c>NULL</c>.
  412. */
  413. int starpu_conf_init(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 MIC devices
  506. are disabled.
  507. */
  508. int starpu_asynchronous_mic_copy_disabled(void);
  509. /**
  510. Return 1 if asynchronous data transfers between CPU and MPI Slave
  511. devices are disabled.
  512. */
  513. int starpu_asynchronous_mpi_ms_copy_disabled(void);
  514. void starpu_display_stats(void);
  515. void starpu_get_version(int *major, int *minor, int *release);
  516. /** @} */
  517. #ifdef __cplusplus
  518. }
  519. #endif
  520. #include "starpu_deprecated_api.h"
  521. #endif /* __STARPU_H__ */