starpu.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. #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. Name of the scheduling policy. This can also be specified
  104. with the environment variable \ref STARPU_SCHED. (default =
  105. <c>NULL</c>).
  106. */
  107. const char *sched_policy_name;
  108. /**
  109. Definition of the scheduling policy. This field is ignored
  110. if starpu_conf::sched_policy_name is set.
  111. (default = <c>NULL</c>)
  112. */
  113. struct starpu_sched_policy *sched_policy;
  114. void (*sched_policy_init)(unsigned);
  115. /**
  116. Number of CPU cores that StarPU can use. This can also be
  117. specified with the environment variable \ref STARPU_NCPU.
  118. (default = -1)
  119. */
  120. int ncpus;
  121. /**
  122. Number of CPU cores to that StarPU should leave aside. They can then
  123. be used by application threads, by calling starpu_get_next_bindid() to
  124. get their ID, and starpu_bind_thread_on() to bind the current thread to them.
  125. */
  126. int reserve_ncpus;
  127. /**
  128. Number of CUDA devices that StarPU can use. This can also
  129. be specified with the environment variable \ref
  130. STARPU_NCUDA.
  131. (default = -1)
  132. */
  133. int ncuda;
  134. /**
  135. Number of OpenCL devices that StarPU can use. This can also
  136. be specified with the environment variable \ref
  137. STARPU_NOPENCL.
  138. (default = -1)
  139. */
  140. int nopencl;
  141. /**
  142. Number of MIC devices that StarPU can use. This can also be
  143. specified with the environment variable \ref STARPU_NMIC.
  144. (default = -1)
  145. */
  146. int nmic;
  147. /**
  148. Number of MPI Master Slave devices that StarPU can use.
  149. This can also be specified with the environment variable
  150. \ref STARPU_NMPI_MS.
  151. (default = -1)
  152. */
  153. int nmpi_ms;
  154. /**
  155. If this flag is set, the starpu_conf::workers_bindid array
  156. indicates where the different workers are bound, otherwise
  157. StarPU automatically selects where to bind the different
  158. workers. This can also be specified with the environment
  159. variable \ref STARPU_WORKERS_CPUID.
  160. (default = 0)
  161. */
  162. unsigned use_explicit_workers_bindid;
  163. /**
  164. If the starpu_conf::use_explicit_workers_bindid flag is
  165. set, this array indicates where to bind the different
  166. workers. The i-th entry of the starpu_conf::workers_bindid
  167. indicates the logical identifier of the processor which
  168. should execute the i-th worker. Note that the logical
  169. ordering of the CPUs is either determined by the OS, or
  170. provided by the hwloc library in case it is available.
  171. */
  172. unsigned workers_bindid[STARPU_NMAXWORKERS];
  173. /**
  174. If this flag is set, the CUDA workers will be attached to
  175. the CUDA devices specified in the
  176. starpu_conf::workers_cuda_gpuid array. Otherwise, StarPU
  177. affects the CUDA devices in a round-robin fashion. This can
  178. also be specified with the environment variable \ref
  179. STARPU_WORKERS_CUDAID.
  180. (default = 0)
  181. */
  182. unsigned use_explicit_workers_cuda_gpuid;
  183. /**
  184. If the starpu_conf::use_explicit_workers_cuda_gpuid flag is
  185. set, this array contains the logical identifiers of the
  186. CUDA devices (as used by \c cudaGetDevice()).
  187. */
  188. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  189. /**
  190. If this flag is set, the OpenCL workers will be attached to
  191. the OpenCL devices specified in the
  192. starpu_conf::workers_opencl_gpuid array. Otherwise, StarPU
  193. affects the OpenCL devices in a round-robin fashion. This
  194. can also be specified with the environment variable \ref
  195. STARPU_WORKERS_OPENCLID.
  196. (default = 0)
  197. */
  198. unsigned use_explicit_workers_opencl_gpuid;
  199. /**
  200. If the starpu_conf::use_explicit_workers_opencl_gpuid flag
  201. is set, this array contains the logical identifiers of the
  202. OpenCL devices to be used.
  203. */
  204. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  205. /**
  206. If this flag is set, the MIC workers will be attached to
  207. the MIC devices specified in the array
  208. starpu_conf::workers_mic_deviceid. Otherwise, StarPU
  209. affects the MIC devices in a round-robin fashion. This can
  210. also be specified with the environment variable \ref
  211. STARPU_WORKERS_MICID.
  212. (default = 0)
  213. */
  214. unsigned use_explicit_workers_mic_deviceid;
  215. /**
  216. If the flag starpu_conf::use_explicit_workers_mic_deviceid
  217. is set, the array contains the logical identifiers of the
  218. MIC devices to be used.
  219. */
  220. unsigned workers_mic_deviceid[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 = 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 = 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 = 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 = 0)
  268. */
  269. int single_combined_worker;
  270. /**
  271. Path to the kernel to execute on the MIC device, compiled
  272. for MIC architecture. When set to <c>NULL</c>, StarPU
  273. automatically looks next to the host program location.
  274. (default = <c>NULL</c>)
  275. */
  276. char *mic_sink_program_path;
  277. /**
  278. This flag should be set to 1 to disable asynchronous copies
  279. between CPUs and all accelerators.
  280. The AMD implementation of OpenCL is known to fail when
  281. copying data asynchronously. When using this
  282. implementation, it is therefore necessary to disable
  283. asynchronous data transfers.
  284. This can also be specified with the environment variable
  285. \ref STARPU_DISABLE_ASYNCHRONOUS_COPY.
  286. This can also be specified at compilation time by giving to
  287. the configure script the option \ref
  288. disable-asynchronous-copy "--disable-asynchronous-copy".
  289. (default = 0)
  290. */
  291. int disable_asynchronous_copy;
  292. /**
  293. This flag should be set to 1 to disable asynchronous copies
  294. between CPUs and CUDA accelerators.
  295. This can also be specified with the environment variable
  296. \ref STARPU_DISABLE_ASYNCHRONOUS_CUDA_COPY.
  297. This can also be specified at compilation time by giving to
  298. the configure script the option \ref
  299. disable-asynchronous-cuda-copy
  300. "--disable-asynchronous-cuda-copy".
  301. (default = 0)
  302. */
  303. int disable_asynchronous_cuda_copy;
  304. /**
  305. This flag should be set to 1 to disable asynchronous copies
  306. between CPUs and OpenCL accelerators.
  307. The AMD implementation of OpenCL is known to fail when
  308. copying data asynchronously. When using this
  309. implementation, it is therefore necessary to disable
  310. asynchronous data transfers.
  311. This can also be specified with the environment variable
  312. \ref STARPU_DISABLE_ASYNCHRONOUS_OPENCL_COPY.
  313. This can also be specified at compilation time by giving to
  314. the configure script the option \ref
  315. disable-asynchronous-opencl-copy
  316. "--disable-asynchronous-opencl-copy".
  317. (default = 0)
  318. */
  319. int disable_asynchronous_opencl_copy;
  320. /**
  321. This flag should be set to 1 to disable asynchronous copies
  322. between CPUs and MIC accelerators.
  323. This can also be specified with the environment variable
  324. \ref STARPU_DISABLE_ASYNCHRONOUS_MIC_COPY.
  325. This can also be specified at compilation time by giving to
  326. the configure script the option \ref
  327. disable-asynchronous-mic-copy
  328. "--disable-asynchronous-mic-copy".
  329. (default = 0).
  330. */
  331. int disable_asynchronous_mic_copy;
  332. /**
  333. This flag should be set to 1 to disable asynchronous copies
  334. between CPUs and MPI Master Slave devices.
  335. This can also be specified with the environment variable
  336. \ref STARPU_DISABLE_ASYNCHRONOUS_MPI_MS_COPY.
  337. This can also be specified at compilation time by giving to
  338. the configure script the option \ref
  339. disable-asynchronous-mpi-master-slave-copy
  340. "--disable-asynchronous-mpi-master-slave-copy".
  341. (default = 0).
  342. */
  343. int disable_asynchronous_mpi_ms_copy;
  344. /**
  345. Enable CUDA/OpenGL interoperation on these CUDA devices.
  346. This can be set to an array of CUDA device identifiers for
  347. which \c cudaGLSetGLDevice() should be called instead of \c
  348. cudaSetDevice(). Its size is specified by the
  349. starpu_conf::n_cuda_opengl_interoperability field below
  350. (default = <c>NULL</c>)
  351. */
  352. unsigned *cuda_opengl_interoperability;
  353. /**
  354. Size of the array starpu_conf::cuda_opengl_interoperability
  355. */
  356. unsigned n_cuda_opengl_interoperability;
  357. /**
  358. Array of drivers that should not be launched by StarPU. The
  359. application will run in one of its own threads.
  360. (default = <c>NULL</c>)
  361. */
  362. struct starpu_driver *not_launched_drivers;
  363. /**
  364. The number of StarPU drivers that should not be launched by
  365. StarPU, i.e number of elements of the array
  366. starpu_conf::not_launched_drivers.
  367. (default = 0)
  368. */
  369. unsigned n_not_launched_drivers;
  370. /**
  371. Specify the buffer size used for FxT tracing. Starting from
  372. FxT version 0.2.12, the buffer will automatically be
  373. flushed when it fills in, but it may still be interesting
  374. to specify a bigger value to avoid any flushing (which
  375. would disturb the trace).
  376. */
  377. unsigned trace_buffer_size;
  378. int global_sched_ctx_min_priority;
  379. int global_sched_ctx_max_priority;
  380. #ifdef STARPU_WORKER_CALLBACKS
  381. void (*callback_worker_going_to_sleep)(unsigned workerid);
  382. void (*callback_worker_waking_up)(unsigned workerid);
  383. #endif
  384. /**
  385. Specify if StarPU should catch SIGINT, SIGSEGV and SIGTRAP
  386. signals to make sure final actions (e.g dumping FxT trace
  387. files) are done even though the application has crashed. By
  388. default (value = \c 1), signals are catched. It should be
  389. disabled on systems which already catch these signals for
  390. their own needs (e.g JVM)
  391. This can also be specified with the environment variable
  392. \ref STARPU_CATCH_SIGNALS
  393. */
  394. int catch_signals;
  395. };
  396. /**
  397. Initialize the \p conf structure with the default values. In case
  398. some configuration parameters are already specified through
  399. environment variables, starpu_conf_init() initializes the fields of
  400. \p conf according to the environment variables.
  401. For instance if \ref STARPU_CALIBRATE is set, its value is put in
  402. the field starpu_conf::calibrate of \p conf.
  403. Upon successful completion, this function returns 0. Otherwise,
  404. <c>-EINVAL</c> indicates that the argument was <c>NULL</c>.
  405. */
  406. int starpu_conf_init(struct starpu_conf *conf);
  407. /**
  408. StarPU initialization method, must be called prior to any other
  409. StarPU call. It is possible to specify StarPU’s configuration (e.g.
  410. scheduling policy, number of cores, ...) by passing a
  411. non-<c>NULL</c> \p conf. Default configuration is used if \p conf
  412. is <c>NULL</c>. Upon successful completion, this function returns
  413. 0. Otherwise, <c>-ENODEV</c> indicates that no worker was available
  414. (and thus StarPU was not initialized).
  415. */
  416. int starpu_init(struct starpu_conf *conf) STARPU_WARN_UNUSED_RESULT;
  417. /**
  418. Similar to starpu_init(), but also take the \p argc and \p argv as
  419. defined by the application.
  420. Do not call starpu_init() and starpu_initialize() in the same
  421. program.
  422. */
  423. int starpu_initialize(struct starpu_conf *user_conf, int *argc, char ***argv);
  424. /**
  425. Return 1 if StarPU is already initialized.
  426. */
  427. int starpu_is_initialized(void);
  428. /**
  429. Wait for starpu_init() call to finish.
  430. */
  431. void starpu_wait_initialized(void);
  432. /**
  433. StarPU termination method, must be called at the end of the
  434. application: statistics and other post-mortem debugging information
  435. are not guaranteed to be available until this method has been
  436. called.
  437. */
  438. void starpu_shutdown(void);
  439. /**
  440. Suspend the processing of new tasks by workers. It can be used in a
  441. program where StarPU is used during only a part of the execution.
  442. Without this call, the workers continue to poll for new tasks in a
  443. tight loop, wasting CPU time. The symmetric call to starpu_resume()
  444. should be used to unfreeze the workers.
  445. */
  446. void starpu_pause(void);
  447. /**
  448. Symmetrical call to starpu_pause(), used to resume the workers
  449. polling for new tasks.
  450. */
  451. void starpu_resume(void);
  452. /**
  453. Value to be passed to starpu_get_next_bindid() and
  454. starpu_bind_thread_on() when binding a thread which will
  455. significantly eat CPU time, and should thus have its own dedicated
  456. CPU.
  457. */
  458. #define STARPU_THREAD_ACTIVE (1 << 0)
  459. /**
  460. Return a PU binding ID which can be used to bind threads with
  461. starpu_bind_thread_on(). \p flags can be set to
  462. STARPU_THREAD_ACTIVE or 0. When \p npreferred is set to non-zero,
  463. \p preferred is an array of size \p npreferred in which a
  464. preference of PU binding IDs can be set. By default StarPU will
  465. return the first PU available for binding.
  466. */
  467. unsigned starpu_get_next_bindid(unsigned flags, unsigned *preferred, unsigned npreferred);
  468. /**
  469. Bind the calling thread on the given \p cpuid (which should have
  470. been obtained with starpu_get_next_bindid()).
  471. Return -1 if a thread was already bound to this PU (but binding
  472. will still have been done, and a warning will have been printed),
  473. so the caller can tell the user how to avoid the issue.
  474. \p name should be set to a unique string so that different calls
  475. with the same name for the same cpuid does not produce a warning.
  476. */
  477. int starpu_bind_thread_on(int cpuid, unsigned flags, const char *name);
  478. /**
  479. Print a description of the topology on \p f.
  480. */
  481. void starpu_topology_print(FILE *f);
  482. /**
  483. Return 1 if asynchronous data transfers between CPU and
  484. accelerators are disabled.
  485. */
  486. int starpu_asynchronous_copy_disabled(void);
  487. /**
  488. Return 1 if asynchronous data transfers between CPU and CUDA
  489. accelerators are disabled.
  490. */
  491. int starpu_asynchronous_cuda_copy_disabled(void);
  492. /**
  493. Return 1 if asynchronous data transfers between CPU and OpenCL
  494. accelerators are disabled.
  495. */
  496. int starpu_asynchronous_opencl_copy_disabled(void);
  497. /**
  498. Return 1 if asynchronous data transfers between CPU and MIC devices
  499. are disabled.
  500. */
  501. int starpu_asynchronous_mic_copy_disabled(void);
  502. /**
  503. Return 1 if asynchronous data transfers between CPU and MPI Slave
  504. devices are disabled.
  505. */
  506. int starpu_asynchronous_mpi_ms_copy_disabled(void);
  507. void starpu_display_stats(void);
  508. void starpu_get_version(int *major, int *minor, int *release);
  509. /** @} */
  510. #ifdef __cplusplus
  511. }
  512. #endif
  513. #include "starpu_deprecated_api.h"
  514. #endif /* __STARPU_H__ */