fstarpu.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016-2020 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. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <starpu.h>
  20. #include <common/utils.h>
  21. typedef void (*_starpu_callback_func_t)(void *);
  22. static const intptr_t fstarpu_r = STARPU_R;
  23. static const intptr_t fstarpu_w = STARPU_W;
  24. static const intptr_t fstarpu_rw = STARPU_RW;
  25. static const intptr_t fstarpu_scratch = STARPU_SCRATCH;
  26. static const intptr_t fstarpu_redux = STARPU_REDUX;
  27. static const intptr_t fstarpu_commute = STARPU_COMMUTE;
  28. static const intptr_t fstarpu_ssend = STARPU_SSEND;
  29. static const intptr_t fstarpu_locality = STARPU_LOCALITY;
  30. static const intptr_t fstarpu_data_array = STARPU_DATA_ARRAY;
  31. static const intptr_t fstarpu_data_mode_array = STARPU_DATA_MODE_ARRAY;
  32. static const intptr_t fstarpu_cl_args = STARPU_CL_ARGS;
  33. static const intptr_t fstarpu_cl_args_nfree = STARPU_CL_ARGS_NFREE;
  34. static const intptr_t fstarpu_task_deps_array = STARPU_TASK_DEPS_ARRAY;
  35. static const intptr_t fstarpu_task_end_deps_array = STARPU_TASK_END_DEPS_ARRAY;
  36. static const intptr_t fstarpu_callback = STARPU_CALLBACK;
  37. static const intptr_t fstarpu_callback_with_arg = STARPU_CALLBACK_WITH_ARG;
  38. static const intptr_t fstarpu_callback_with_arg_nfree = STARPU_CALLBACK_WITH_ARG_NFREE;
  39. static const intptr_t fstarpu_callback_arg = STARPU_CALLBACK_ARG;
  40. static const intptr_t fstarpu_callback_arg_nfree= STARPU_CALLBACK_ARG_NFREE;
  41. static const intptr_t fstarpu_prologue_callback = STARPU_PROLOGUE_CALLBACK;
  42. static const intptr_t fstarpu_prologue_callback_arg = STARPU_PROLOGUE_CALLBACK_ARG;
  43. static const intptr_t fstarpu_prologue_callback_arg_nfree = STARPU_PROLOGUE_CALLBACK_ARG_NFREE;
  44. static const intptr_t fstarpu_prologue_callback_pop = STARPU_PROLOGUE_CALLBACK_POP;
  45. static const intptr_t fstarpu_prologue_callback_pop_arg = STARPU_PROLOGUE_CALLBACK_POP_ARG;
  46. static const intptr_t fstarpu_prologue_callback_pop_arg_nfree = STARPU_PROLOGUE_CALLBACK_POP_ARG_NFREE;
  47. static const intptr_t fstarpu_priority = STARPU_PRIORITY;
  48. static const intptr_t fstarpu_execute_on_node = STARPU_EXECUTE_ON_NODE;
  49. static const intptr_t fstarpu_execute_on_data = STARPU_EXECUTE_ON_DATA;
  50. static const intptr_t fstarpu_execute_where = STARPU_EXECUTE_WHERE;
  51. static const intptr_t fstarpu_execute_on_worker = STARPU_EXECUTE_ON_WORKER;
  52. static const intptr_t fstarpu_worker_order = STARPU_WORKER_ORDER;
  53. static const intptr_t fstarpu_hypervisor_tag = STARPU_HYPERVISOR_TAG;
  54. static const intptr_t fstarpu_possibly_parallel = STARPU_POSSIBLY_PARALLEL;
  55. static const intptr_t fstarpu_flops = STARPU_FLOPS;
  56. static const intptr_t fstarpu_tag = STARPU_TAG;
  57. static const intptr_t fstarpu_tag_only = STARPU_TAG_ONLY;
  58. static const intptr_t fstarpu_name = STARPU_NAME;
  59. static const intptr_t fstarpu_task_color = STARPU_TASK_COLOR;
  60. static const intptr_t fstarpu_handles_sequential_consistency = STARPU_HANDLES_SEQUENTIAL_CONSISTENCY;
  61. static const intptr_t fstarpu_task_end_dep = STARPU_TASK_END_DEP;
  62. static const intptr_t fstarpu_task_synchronous = STARPU_TASK_SYNCHRONOUS;
  63. static const intptr_t fstarpu_node_selection_policy = STARPU_NODE_SELECTION_POLICY;
  64. static const intptr_t fstarpu_task_workerids = STARPU_TASK_WORKERIDS;
  65. static const intptr_t fstarpu_sequential_consistency = STARPU_SEQUENTIAL_CONSISTENCY;
  66. static const intptr_t fstarpu_task_profiling_info = STARPU_TASK_PROFILING_INFO;
  67. static const intptr_t fstarpu_task_no_submitorder = STARPU_TASK_NO_SUBMITORDER;
  68. static const intptr_t fstarpu_task_sched_data = STARPU_TASK_SCHED_DATA;
  69. static const intptr_t fstarpu_task_file = STARPU_TASK_FILE;
  70. static const intptr_t fstarpu_task_line = STARPU_TASK_LINE;
  71. static const intptr_t fstarpu_value = STARPU_VALUE;
  72. static const intptr_t fstarpu_sched_ctx = STARPU_SCHED_CTX;
  73. static const intptr_t fstarpu_cpu_worker = STARPU_CPU_WORKER;
  74. static const intptr_t fstarpu_cuda_worker = STARPU_CUDA_WORKER;
  75. static const intptr_t fstarpu_opencl_worker = STARPU_OPENCL_WORKER;
  76. static const intptr_t fstarpu_mic_worker = STARPU_MIC_WORKER;
  77. static const intptr_t fstarpu_any_worker = STARPU_ANY_WORKER;
  78. static const intptr_t fstarpu_nmaxbufs = STARPU_NMAXBUFS;
  79. static const intptr_t fstarpu_sched_ctx_policy_name = STARPU_SCHED_CTX_POLICY_NAME;
  80. static const intptr_t fstarpu_sched_ctx_policy_struct = STARPU_SCHED_CTX_POLICY_STRUCT;
  81. static const intptr_t fstarpu_sched_ctx_policy_min_prio = STARPU_SCHED_CTX_POLICY_MIN_PRIO;
  82. static const intptr_t fstarpu_sched_ctx_policy_max_prio = STARPU_SCHED_CTX_POLICY_MAX_PRIO;
  83. static const intptr_t fstarpu_sched_ctx_hierarchy_level = STARPU_SCHED_CTX_HIERARCHY_LEVEL;
  84. static const intptr_t fstarpu_sched_ctx_nested = STARPU_SCHED_CTX_NESTED;
  85. static const intptr_t fstarpu_sched_ctx_awake_workers = STARPU_SCHED_CTX_AWAKE_WORKERS;
  86. static const intptr_t fstarpu_sched_ctx_policy_init = STARPU_SCHED_CTX_POLICY_INIT;
  87. static const intptr_t fstarpu_sched_ctx_user_data = STARPU_SCHED_CTX_USER_DATA;
  88. static const intptr_t fstarpu_starpu_nowhere = STARPU_NOWHERE;
  89. static const intptr_t fstarpu_starpu_cpu = STARPU_CPU;
  90. static const intptr_t fstarpu_starpu_cuda = STARPU_CUDA;
  91. static const intptr_t fstarpu_starpu_opencl = STARPU_OPENCL;
  92. static const intptr_t fstarpu_starpu_mic = STARPU_MIC;
  93. static const intptr_t fstarpu_starpu_codelet_simgrid_execute = STARPU_CODELET_SIMGRID_EXECUTE;
  94. static const intptr_t fstarpu_starpu_codelet_simgrid_execute_and_inject = STARPU_CODELET_SIMGRID_EXECUTE_AND_INJECT;
  95. static const intptr_t fstarpu_starpu_cuda_async = STARPU_CUDA_ASYNC;
  96. static const intptr_t fstarpu_starpu_opencl_async = STARPU_OPENCL_ASYNC;
  97. //static const intptr_t fstarpu_per_worker = STARPU_PER_WORKER;
  98. //static const intptr_t fstarpu_per_arch = STARPU_PER_ARCH;
  99. //static const intptr_t fstarpu_per_common = STARPU_COMMON;
  100. static const intptr_t fstarpu_history_based = STARPU_HISTORY_BASED;
  101. static const intptr_t fstarpu_regression_based = STARPU_REGRESSION_BASED;
  102. static const intptr_t fstarpu_nl_regression_based = STARPU_NL_REGRESSION_BASED;
  103. static const intptr_t fstarpu_multiple_regression_based = STARPU_MULTIPLE_REGRESSION_BASED;
  104. intptr_t fstarpu_get_constant(char *s)
  105. {
  106. if (!strcmp(s, "FSTARPU_R")) { return fstarpu_r; }
  107. else if (!strcmp(s, "FSTARPU_W")) { return fstarpu_w; }
  108. else if (!strcmp(s, "FSTARPU_RW")) { return fstarpu_rw; }
  109. else if (!strcmp(s, "FSTARPU_SCRATCH")) { return fstarpu_scratch; }
  110. else if (!strcmp(s, "FSTARPU_REDUX")) { return fstarpu_redux; }
  111. else if (!strcmp(s, "FSTARPU_COMMUTE")) { return fstarpu_commute; }
  112. else if (!strcmp(s, "FSTARPU_SSEND")) { return fstarpu_ssend; }
  113. else if (!strcmp(s, "FSTARPU_LOCALITY")) { return fstarpu_locality; }
  114. else if (!strcmp(s, "FSTARPU_DATA_ARRAY")) { return fstarpu_data_array; }
  115. else if (!strcmp(s, "FSTARPU_DATA_MODE_ARRAY")) { return fstarpu_data_mode_array; }
  116. else if (!strcmp(s, "FSTARPU_CL_ARGS")) { return fstarpu_cl_args; }
  117. else if (!strcmp(s, "FSTARPU_CL_ARGS_NFREE")) { return fstarpu_cl_args_nfree; }
  118. else if (!strcmp(s, "FSTARPU_TASK_DEPS_ARRAY")) { return fstarpu_task_deps_array; }
  119. else if (!strcmp(s, "FSTARPU_TASK_END_DEPS_ARRAY")) { return fstarpu_task_end_deps_array; }
  120. else if (!strcmp(s, "FSTARPU_CALLBACK")) { return fstarpu_callback; }
  121. else if (!strcmp(s, "FSTARPU_CALLBACK_WITH_ARG")) { return fstarpu_callback_with_arg; }
  122. else if (!strcmp(s, "FSTARPU_CALLBACK_WITH_ARG_NFREE")) { return fstarpu_callback_with_arg_nfree; }
  123. else if (!strcmp(s, "FSTARPU_CALLBACK_ARG")) { return fstarpu_callback_arg; }
  124. else if (!strcmp(s, "FSTARPU_CALLBACK_ARG_NFREE")) { return fstarpu_callback_arg_nfree; }
  125. else if (!strcmp(s, "FSTARPU_PROLOGUE_CALLBACK")) { return fstarpu_prologue_callback; }
  126. else if (!strcmp(s, "FSTARPU_PROLOGUE_CALLBACK_ARG")) { return fstarpu_prologue_callback_arg; }
  127. else if (!strcmp(s, "FSTARPU_PROLOGUE_CALLBACK_ARG_NFREE")) { return fstarpu_prologue_callback_arg_nfree; }
  128. else if (!strcmp(s, "FSTARPU_PROLOGUE_CALLBACK_POP")) { return fstarpu_prologue_callback_pop; }
  129. else if (!strcmp(s, "FSTARPU_PROLOGUE_CALLBACK_POP_ARG")) { return fstarpu_prologue_callback_pop_arg; }
  130. else if (!strcmp(s, "FSTARPU_PROLOGUE_CALLBACK_POP_ARG_NFREE")) { return fstarpu_prologue_callback_pop_arg_nfree; }
  131. else if (!strcmp(s, "FSTARPU_PRIORITY")) { return fstarpu_priority; }
  132. else if (!strcmp(s, "FSTARPU_EXECUTE_ON_NODE")) { return fstarpu_execute_on_node; }
  133. else if (!strcmp(s, "FSTARPU_EXECUTE_ON_DATA")) { return fstarpu_execute_on_data; }
  134. else if (!strcmp(s, "FSTARPU_EXECUTE_WHERE")) { return fstarpu_execute_where; }
  135. else if (!strcmp(s, "FSTARPU_EXECUTE_ON_WORKER")) { return fstarpu_execute_on_worker; }
  136. else if (!strcmp(s, "FSTARPU_WORKER_ORDER")) { return fstarpu_worker_order; }
  137. else if (!strcmp(s, "FSTARPU_HYPERVISOR_TAG")) { return fstarpu_hypervisor_tag; }
  138. else if (!strcmp(s, "FSTARPU_POSSIBLY_PARALLEL")) { return fstarpu_possibly_parallel; }
  139. else if (!strcmp(s, "FSTARPU_FLOPS")) { return fstarpu_flops; }
  140. else if (!strcmp(s, "FSTARPU_TAG")) { return fstarpu_tag; }
  141. else if (!strcmp(s, "FSTARPU_TAG_ONLY")) { return fstarpu_tag_only; }
  142. else if (!strcmp(s, "FSTARPU_NAME")) { return fstarpu_name; }
  143. else if (!strcmp(s, "FSTARPU_NODE_SELECTION_POLICY")) { return fstarpu_node_selection_policy; }
  144. else if (!strcmp(s, "FSTARPU_VALUE")) { return fstarpu_value; }
  145. else if (!strcmp(s, "FSTARPU_SCHED_CTX")) { return fstarpu_sched_ctx; }
  146. else if (!strcmp(s, "FSTARPU_TASK_COLOR")) { return fstarpu_task_color; }
  147. else if (!strcmp(s, "FSTARPU_HANDLES_SEQUENTIAL_CONSISTENCY")) { return fstarpu_handles_sequential_consistency; }
  148. else if (!strcmp(s, "FSTARPU_TASK_END_DEP")) { return fstarpu_task_end_dep; }
  149. else if (!strcmp(s, "FSTARPU_TASK_WORKERIDS")) { return fstarpu_task_workerids; }
  150. else if (!strcmp(s, "FSTARPU_TASK_SYNCHRONOUS")) { return fstarpu_task_synchronous; }
  151. else if (!strcmp(s, "FSTARPU_SEQUENTIAL_CONSISTENCY")) { return fstarpu_sequential_consistency; }
  152. else if (!strcmp(s, "FSTARPU_TASK_PROFILING_INFO")) { return fstarpu_task_profiling_info; }
  153. else if (!strcmp(s, "FSTARPU_TASK_NO_SUBMITORDER")) { return fstarpu_task_no_submitorder; }
  154. else if (!strcmp(s, "FSTARPU_TASK_SCHED_DATA")) { return fstarpu_task_sched_data; }
  155. else if (!strcmp(s, "FSTARPU_TASK_FILE")) { return fstarpu_task_file; }
  156. else if (!strcmp(s, "FSTARPU_TASK_LINE")) { return fstarpu_task_line; }
  157. else if (!strcmp(s, "FSTARPU_CPU_WORKER")) { return fstarpu_cpu_worker; }
  158. else if (!strcmp(s, "FSTARPU_CUDA_WORKER")) { return fstarpu_cuda_worker; }
  159. else if (!strcmp(s, "FSTARPU_OPENCL_WORKER")) { return fstarpu_opencl_worker; }
  160. else if (!strcmp(s, "FSTARPU_MIC_WORKER")) { return fstarpu_mic_worker; }
  161. else if (!strcmp(s, "FSTARPU_ANY_WORKER")) { return fstarpu_any_worker; }
  162. else if (!strcmp(s, "FSTARPU_NMAXBUFS")) { return fstarpu_nmaxbufs; }
  163. else if (!strcmp(s, "FSTARPU_SCHED_CTX_POLICY_NAME")) { return fstarpu_sched_ctx_policy_name; }
  164. else if (!strcmp(s, "FSTARPU_SCHED_CTX_POLICY_STRUCT")) { return fstarpu_sched_ctx_policy_struct; }
  165. else if (!strcmp(s, "FSTARPU_SCHED_CTX_POLICY_MIN_PRIO")) { return fstarpu_sched_ctx_policy_min_prio; }
  166. else if (!strcmp(s, "FSTARPU_SCHED_CTX_POLICY_MAX_PRIO")) { return fstarpu_sched_ctx_policy_max_prio; }
  167. else if (!strcmp(s, "FSTARPU_SCHED_CTX_HIERARCHY_LEVEL")) { return fstarpu_sched_ctx_hierarchy_level; }
  168. else if (!strcmp(s, "FSTARPU_SCHED_CTX_NESTED")) { return fstarpu_sched_ctx_nested; }
  169. else if (!strcmp(s, "FSTARPU_SCHED_CTX_AWAKE_WORKERS")) { return fstarpu_sched_ctx_awake_workers; }
  170. else if (!strcmp(s, "FSTARPU_SCHED_CTX_POLICY_INIT")) { return fstarpu_sched_ctx_policy_init; }
  171. else if (!strcmp(s, "FSTARPU_SCHED_CTX_USER_DATA")) { return fstarpu_sched_ctx_user_data; }
  172. else if (!strcmp(s, "FSTARPU_NOWHERE")) { return fstarpu_starpu_nowhere; }
  173. else if (!strcmp(s, "FSTARPU_CPU")) { return fstarpu_starpu_cpu; }
  174. else if (!strcmp(s, "FSTARPU_CUDA")) { return fstarpu_starpu_cuda; }
  175. else if (!strcmp(s, "FSTARPU_OPENCL")) { return fstarpu_starpu_opencl; }
  176. else if (!strcmp(s, "FSTARPU_MIC")) { return fstarpu_starpu_mic; }
  177. else if (!strcmp(s, "FSTARPU_CODELET_SIMGRID_EXECUTE")) { return fstarpu_starpu_codelet_simgrid_execute; }
  178. else if (!strcmp(s, "FSTARPU_CODELET_SIMGRID_EXECUTE_AND_INJECT")) { return fstarpu_starpu_codelet_simgrid_execute_and_inject; }
  179. else if (!strcmp(s, "FSTARPU_CUDA_ASYNC")) { return fstarpu_starpu_cuda_async; }
  180. else if (!strcmp(s, "FSTARPU_OPENCL_ASYNC")) { return fstarpu_starpu_opencl_async; }
  181. // else if (!strcmp(s, "FSTARPU_PER_WORKER")) { return fstarpu_per_worker; }
  182. // else if (!strcmp(s, "FSTARPU_PER_ARCH")) { return fstarpu_per_arch; }
  183. // else if (!strcmp(s, "FSTARPU_COMMON")) { return fstarpu_per_common; }
  184. else if (!strcmp(s, "FSTARPU_HISTORY_BASED")) { return fstarpu_history_based; }
  185. else if (!strcmp(s, "FSTARPU_REGRESSION_BASED")) { return fstarpu_regression_based; }
  186. else if (!strcmp(s, "FSTARPU_NL_REGRESSION_BASED")) { return fstarpu_nl_regression_based; }
  187. else if (!strcmp(s, "FSTARPU_MULTIPLE_REGRESSION_BASED")) { return fstarpu_multiple_regression_based; }
  188. else { _STARPU_ERROR("unknown constant"); }
  189. }
  190. STARPU_ATTRIBUTE_MALLOC
  191. struct starpu_conf *fstarpu_conf_allocate(void)
  192. {
  193. struct starpu_conf *conf;
  194. _STARPU_MALLOC(conf, sizeof(*conf));
  195. starpu_conf_init(conf);
  196. return conf;
  197. }
  198. void fstarpu_conf_free(struct starpu_conf *conf)
  199. {
  200. memset(conf, 0, sizeof(*conf));
  201. free(conf);
  202. }
  203. void fstarpu_conf_set_sched_policy_name(struct starpu_conf *conf, const char *sched_policy_name)
  204. {
  205. conf->sched_policy_name = sched_policy_name;
  206. }
  207. void fstarpu_conf_set_min_prio(struct starpu_conf *conf, int min_prio)
  208. {
  209. conf->global_sched_ctx_min_priority = min_prio;
  210. }
  211. void fstarpu_conf_set_max_prio(struct starpu_conf *conf, int max_prio)
  212. {
  213. conf->global_sched_ctx_max_priority = max_prio;
  214. }
  215. void fstarpu_conf_set_ncpu(struct starpu_conf *conf, int ncpu)
  216. {
  217. STARPU_ASSERT(ncpu >= 0 && ncpu <= STARPU_NMAXWORKERS);
  218. conf->ncpus = ncpu;
  219. }
  220. void fstarpu_conf_set_ncuda(struct starpu_conf *conf, int ncuda)
  221. {
  222. STARPU_ASSERT(ncuda >= 0 && ncuda <= STARPU_NMAXWORKERS);
  223. conf->ncuda = ncuda;
  224. }
  225. void fstarpu_conf_set_nopencl(struct starpu_conf *conf, int nopencl)
  226. {
  227. STARPU_ASSERT(nopencl >= 0 && nopencl <= STARPU_NMAXWORKERS);
  228. conf->nopencl = nopencl;
  229. }
  230. void fstarpu_conf_set_nmic(struct starpu_conf *conf, int nmic)
  231. {
  232. STARPU_ASSERT(nmic >= 0 && nmic <= STARPU_NMAXWORKERS);
  233. conf->nmic = nmic;
  234. }
  235. void fstarpu_conf_set_calibrate(struct starpu_conf *conf, int calibrate)
  236. {
  237. STARPU_ASSERT(calibrate == 0 || calibrate == 1);
  238. conf->calibrate = calibrate;
  239. }
  240. void fstarpu_conf_set_bus_calibrate(struct starpu_conf *conf, int bus_calibrate)
  241. {
  242. STARPU_ASSERT(bus_calibrate == 0 || bus_calibrate == 1);
  243. conf->bus_calibrate = bus_calibrate;
  244. }
  245. void fstarpu_topology_print(void)
  246. {
  247. starpu_topology_print(stderr);
  248. }
  249. STARPU_ATTRIBUTE_MALLOC
  250. struct starpu_codelet *fstarpu_codelet_allocate(void)
  251. {
  252. struct starpu_codelet *cl;
  253. _STARPU_MALLOC(cl, sizeof(*cl));
  254. starpu_codelet_init(cl);
  255. return cl;
  256. }
  257. void fstarpu_codelet_free(struct starpu_codelet *cl)
  258. {
  259. memset(cl, 0, sizeof(*cl));
  260. free(cl);
  261. }
  262. void fstarpu_codelet_set_name(struct starpu_codelet *cl, const char *cl_name)
  263. {
  264. cl->name = cl_name;
  265. }
  266. void fstarpu_codelet_set_model(struct starpu_codelet *cl, struct starpu_perfmodel *cl_perfmodel)
  267. {
  268. cl->model = cl_perfmodel;
  269. }
  270. void fstarpu_codelet_set_energy_model(struct starpu_codelet *cl, struct starpu_perfmodel *cl_perfmodel)
  271. {
  272. cl->energy_model = cl_perfmodel;
  273. }
  274. void fstarpu_codelet_add_cpu_func(struct starpu_codelet *cl, void *f_ptr)
  275. {
  276. const size_t max_cpu_funcs = sizeof(cl->cpu_funcs)/sizeof(cl->cpu_funcs[0])-1;
  277. size_t i;
  278. for (i = 0; i < max_cpu_funcs; i++)
  279. {
  280. if (cl->cpu_funcs[i] == NULL)
  281. {
  282. cl->cpu_funcs[i] = f_ptr;
  283. return;
  284. }
  285. }
  286. _STARPU_ERROR("fstarpu: too many cpu functions in Fortran codelet");
  287. }
  288. void fstarpu_codelet_add_cuda_func(struct starpu_codelet *cl, void *f_ptr)
  289. {
  290. const size_t max_cuda_funcs = sizeof(cl->cuda_funcs)/sizeof(cl->cuda_funcs[0])-1;
  291. unsigned i;
  292. for (i = 0; i < max_cuda_funcs; i++)
  293. {
  294. if (cl->cuda_funcs[i] == NULL)
  295. {
  296. cl->cuda_funcs[i] = f_ptr;
  297. return;
  298. }
  299. }
  300. _STARPU_ERROR("fstarpu: too many cuda functions in Fortran codelet");
  301. }
  302. void fstarpu_codelet_add_cuda_flags(struct starpu_codelet *cl, intptr_t flags)
  303. {
  304. const size_t max_cuda_flags = sizeof(cl->cuda_flags)/sizeof(cl->cuda_flags[0])-1;
  305. unsigned i;
  306. for (i = 0; i < max_cuda_flags; i++)
  307. {
  308. if (cl->cuda_flags[i] == 0)
  309. {
  310. cl->cuda_flags[i] = (char)flags;
  311. return;
  312. }
  313. }
  314. _STARPU_ERROR("fstarpu: too many cuda flags in Fortran codelet");
  315. }
  316. void fstarpu_codelet_add_opencl_func(struct starpu_codelet *cl, void *f_ptr)
  317. {
  318. const size_t max_opencl_funcs = sizeof(cl->opencl_funcs)/sizeof(cl->opencl_funcs[0])-1;
  319. unsigned i;
  320. for (i = 0; i < max_opencl_funcs; i++)
  321. {
  322. if (cl->opencl_funcs[i] == NULL)
  323. {
  324. cl->opencl_funcs[i] = f_ptr;
  325. return;
  326. }
  327. }
  328. _STARPU_ERROR("fstarpu: too many opencl functions in Fortran codelet");
  329. }
  330. void fstarpu_codelet_add_opencl_flags(struct starpu_codelet *cl, intptr_t flags)
  331. {
  332. const size_t max_opencl_flags = sizeof(cl->opencl_flags)/sizeof(cl->opencl_flags[0])-1;
  333. unsigned i;
  334. for (i = 0; i < max_opencl_flags; i++)
  335. {
  336. if (cl->opencl_flags[i] == 0)
  337. {
  338. cl->opencl_flags[i] = (char)flags;
  339. return;
  340. }
  341. }
  342. _STARPU_ERROR("fstarpu: too many opencl flags in Fortran codelet");
  343. }
  344. void fstarpu_codelet_add_mic_func(struct starpu_codelet *cl, void *f_ptr)
  345. {
  346. const size_t max_mic_funcs = sizeof(cl->mic_funcs)/sizeof(cl->mic_funcs[0])-1;
  347. unsigned i;
  348. for (i = 0; i < max_mic_funcs; i++)
  349. {
  350. if (cl->mic_funcs[i] == NULL)
  351. {
  352. cl->mic_funcs[i] = f_ptr;
  353. return;
  354. }
  355. }
  356. _STARPU_ERROR("fstarpu: too many mic functions in Fortran codelet");
  357. }
  358. void fstarpu_codelet_add_buffer(struct starpu_codelet *cl, intptr_t _mode)
  359. {
  360. enum starpu_data_access_mode mode = (enum starpu_data_access_mode) _mode;
  361. const size_t max_modes = sizeof(cl->modes)/sizeof(cl->modes[0])-1;
  362. if ((mode & (STARPU_ACCESS_MODE_MAX-1)) != mode)
  363. {
  364. _STARPU_ERROR("fstarpu: invalid data mode");
  365. }
  366. if (cl->nbuffers < (int) max_modes)
  367. {
  368. cl->modes[cl->nbuffers] = (unsigned int)mode;
  369. cl->nbuffers++;
  370. }
  371. else
  372. {
  373. _STARPU_ERROR("fstarpu: too many buffers in Fortran codelet");
  374. }
  375. }
  376. void fstarpu_codelet_set_variable_nbuffers(struct starpu_codelet *cl)
  377. {
  378. cl->nbuffers = STARPU_VARIABLE_NBUFFERS;
  379. }
  380. void fstarpu_codelet_set_nbuffers(struct starpu_codelet *cl, int nbuffers)
  381. {
  382. if (nbuffers >= 0)
  383. {
  384. cl->nbuffers = nbuffers;
  385. }
  386. else
  387. {
  388. _STARPU_ERROR("fstarpu: invalid nbuffers parameter");
  389. }
  390. }
  391. void fstarpu_codelet_set_flags(struct starpu_codelet *cl, intptr_t flags)
  392. {
  393. cl->flags = (int)flags;
  394. }
  395. void fstarpu_codelet_set_where(struct starpu_codelet *cl, intptr_t where)
  396. {
  397. STARPU_ASSERT(where >= 0);
  398. cl->where = (uint32_t)where;
  399. }
  400. STARPU_ATTRIBUTE_MALLOC
  401. struct starpu_perfmodel *fstarpu_perfmodel_allocate(void)
  402. {
  403. struct starpu_perfmodel *model;
  404. _STARPU_CALLOC(model, 1, sizeof(*model));
  405. return model;
  406. }
  407. void fstarpu_perfmodel_free(struct starpu_perfmodel *model)
  408. {
  409. memset(model, 0, sizeof(*model));
  410. free(model);
  411. }
  412. void fstarpu_perfmodel_set_symbol(struct starpu_perfmodel *model, const char *model_symbol)
  413. {
  414. model->symbol = model_symbol;
  415. }
  416. void fstarpu_perfmodel_set_type(struct starpu_perfmodel *model, intptr_t type)
  417. {
  418. STARPU_ASSERT(type == fstarpu_history_based || type == fstarpu_regression_based || type == fstarpu_nl_regression_based || type == fstarpu_multiple_regression_based);
  419. model->type = type;
  420. }
  421. void * fstarpu_variable_get_ptr(void *buffers[], int i)
  422. {
  423. return (void *)STARPU_VARIABLE_GET_PTR(buffers[i]);
  424. }
  425. void * fstarpu_vector_get_ptr(void *buffers[], int i)
  426. {
  427. return (void *)STARPU_VECTOR_GET_PTR(buffers[i]);
  428. }
  429. int fstarpu_vector_get_nx(void *buffers[], int i)
  430. {
  431. return STARPU_VECTOR_GET_NX(buffers[i]);
  432. }
  433. void * fstarpu_matrix_get_ptr(void *buffers[], int i)
  434. {
  435. return (void *)STARPU_MATRIX_GET_PTR(buffers[i]);
  436. }
  437. int fstarpu_matrix_get_ld(void *buffers[], int i)
  438. {
  439. return STARPU_MATRIX_GET_LD(buffers[i]);
  440. }
  441. int fstarpu_matrix_get_nx(void *buffers[], int i)
  442. {
  443. return STARPU_MATRIX_GET_NX(buffers[i]);
  444. }
  445. int fstarpu_matrix_get_ny(void *buffers[], int i)
  446. {
  447. return STARPU_MATRIX_GET_NY(buffers[i]);
  448. }
  449. void * fstarpu_block_get_ptr(void *buffers[], int i)
  450. {
  451. return (void *)STARPU_BLOCK_GET_PTR(buffers[i]);
  452. }
  453. int fstarpu_block_get_ldy(void *buffers[], int i)
  454. {
  455. return STARPU_BLOCK_GET_LDY(buffers[i]);
  456. }
  457. int fstarpu_block_get_ldz(void *buffers[], int i)
  458. {
  459. return STARPU_BLOCK_GET_LDZ(buffers[i]);
  460. }
  461. int fstarpu_block_get_nx(void *buffers[], int i)
  462. {
  463. return STARPU_BLOCK_GET_NX(buffers[i]);
  464. }
  465. int fstarpu_block_get_ny(void *buffers[], int i)
  466. {
  467. return STARPU_BLOCK_GET_NY(buffers[i]);
  468. }
  469. int fstarpu_block_get_nz(void *buffers[], int i)
  470. {
  471. return STARPU_BLOCK_GET_NZ(buffers[i]);
  472. }
  473. void fstarpu_data_acquire(starpu_data_handle_t handle, intptr_t mode)
  474. {
  475. STARPU_ASSERT(mode == fstarpu_r || mode == fstarpu_w || mode == fstarpu_rw);
  476. starpu_data_acquire(handle, (int)mode);
  477. }
  478. void fstarpu_unpack_arg(char *cl_arg, void **buffer_list)
  479. {
  480. size_t current_arg_offset = 0;
  481. int nargs, arg;
  482. /* We fill the different pointers with the appropriate arguments */
  483. memcpy(&nargs, cl_arg, sizeof(nargs));
  484. current_arg_offset += sizeof(nargs);
  485. for (arg = 0; arg < nargs; arg++)
  486. {
  487. void *argptr = buffer_list[arg];
  488. /* If not reading all cl_args */
  489. if(argptr == NULL)
  490. break;
  491. size_t arg_size;
  492. memcpy(&arg_size, cl_arg+current_arg_offset, sizeof(arg_size));
  493. current_arg_offset += sizeof(arg_size);
  494. memcpy(argptr, cl_arg+current_arg_offset, arg_size);
  495. current_arg_offset += arg_size;
  496. }
  497. }
  498. void fstarpu_sched_ctx_display_workers(int ctx)
  499. {
  500. starpu_sched_ctx_display_workers((unsigned)ctx, stderr);
  501. }
  502. intptr_t fstarpu_worker_get_type(int workerid)
  503. {
  504. return (intptr_t)starpu_worker_get_type(workerid);
  505. }
  506. int fstarpu_worker_get_count_by_type(intptr_t type)
  507. {
  508. return starpu_worker_get_count_by_type((enum starpu_worker_archtype)type);
  509. }
  510. unsigned fstarpu_worker_get_ids_by_type(intptr_t type, int *workerids, unsigned maxsize)
  511. {
  512. return starpu_worker_get_ids_by_type((enum starpu_worker_archtype)type, workerids, maxsize);
  513. }
  514. int fstarpu_worker_get_by_type(intptr_t type, int num)
  515. {
  516. return starpu_worker_get_by_type((enum starpu_worker_archtype)type, num);
  517. }
  518. int fstarpu_worker_get_by_devid(intptr_t type, int devid)
  519. {
  520. return starpu_worker_get_by_type((enum starpu_worker_archtype)type, devid);
  521. }
  522. void fstarpu_worker_get_type_as_string(intptr_t type, char *dst, size_t maxlen)
  523. {
  524. const char *str = starpu_worker_get_type_as_string((enum starpu_worker_archtype)type);
  525. snprintf(dst, maxlen, "%s", str);
  526. }
  527. STARPU_ATTRIBUTE_MALLOC
  528. starpu_data_handle_t *fstarpu_data_handle_array_alloc(int nb)
  529. {
  530. void *ptr;
  531. _STARPU_CALLOC(ptr, (size_t)nb, sizeof(starpu_data_handle_t));
  532. return ptr;
  533. }
  534. void fstarpu_data_handle_array_free(starpu_data_handle_t *handles)
  535. {
  536. free(handles);
  537. }
  538. void fstarpu_data_handle_array_set(starpu_data_handle_t *handles, int i, starpu_data_handle_t handle)
  539. {
  540. handles[i] = handle;
  541. }
  542. STARPU_ATTRIBUTE_MALLOC
  543. struct starpu_data_descr *fstarpu_data_descr_array_alloc(int nb)
  544. {
  545. void *ptr;
  546. _STARPU_CALLOC(ptr, (size_t)nb, sizeof(struct starpu_data_descr));
  547. return ptr;
  548. }
  549. STARPU_ATTRIBUTE_MALLOC
  550. struct starpu_data_descr *fstarpu_data_descr_alloc(void)
  551. {
  552. return fstarpu_data_descr_array_alloc(1);
  553. }
  554. void fstarpu_data_descr_array_free(struct starpu_data_descr *descrs)
  555. {
  556. free(descrs);
  557. }
  558. void fstarpu_data_descr_free(struct starpu_data_descr *descr)
  559. {
  560. fstarpu_data_descr_array_free(descr);
  561. }
  562. void fstarpu_data_descr_array_set(struct starpu_data_descr *descrs, int i, starpu_data_handle_t handle, intptr_t mode)
  563. {
  564. descrs[i].handle = handle;
  565. descrs[i].mode = (enum starpu_data_access_mode)mode;
  566. }
  567. void fstarpu_data_descr_set(struct starpu_data_descr *descr, starpu_data_handle_t handle, intptr_t mode)
  568. {
  569. fstarpu_data_descr_array_set(descr, 1, handle, mode);
  570. }
  571. STARPU_ATTRIBUTE_MALLOC
  572. struct starpu_data_filter *fstarpu_data_filter_allocate(void)
  573. {
  574. struct starpu_data_filter *filter;
  575. _STARPU_CALLOC(filter, 1, sizeof(*filter));
  576. return filter;
  577. }
  578. /* Note: use fstarpu_df_alloc_ prefix instead of fstarpu_data_filter_allocate_ to fit within the
  579. * Fortran id length limit */
  580. #define _FSTARPU_DATA_FILTER_ALLOCATOR(name) \
  581. STARPU_ATTRIBUTE_MALLOC \
  582. struct starpu_data_filter *fstarpu_df_alloc_##name(void) \
  583. { \
  584. struct starpu_data_filter *filter = fstarpu_data_filter_allocate(); \
  585. filter->filter_func = starpu_##name; \
  586. return filter; \
  587. }
  588. _FSTARPU_DATA_FILTER_ALLOCATOR(bcsr_filter_canonical_block);
  589. _FSTARPU_DATA_FILTER_ALLOCATOR(csr_filter_vertical_block);
  590. _FSTARPU_DATA_FILTER_ALLOCATOR(matrix_filter_block);
  591. _FSTARPU_DATA_FILTER_ALLOCATOR(matrix_filter_block_shadow);
  592. _FSTARPU_DATA_FILTER_ALLOCATOR(matrix_filter_vertical_block);
  593. _FSTARPU_DATA_FILTER_ALLOCATOR(matrix_filter_vertical_block_shadow);
  594. _FSTARPU_DATA_FILTER_ALLOCATOR(vector_filter_block);
  595. _FSTARPU_DATA_FILTER_ALLOCATOR(vector_filter_block_shadow);
  596. _FSTARPU_DATA_FILTER_ALLOCATOR(vector_filter_list);
  597. _FSTARPU_DATA_FILTER_ALLOCATOR(vector_filter_divide_in_2);
  598. _FSTARPU_DATA_FILTER_ALLOCATOR(block_filter_block);
  599. _FSTARPU_DATA_FILTER_ALLOCATOR(block_filter_block_shadow);
  600. _FSTARPU_DATA_FILTER_ALLOCATOR(block_filter_vertical_block);
  601. _FSTARPU_DATA_FILTER_ALLOCATOR(block_filter_vertical_block_shadow);
  602. #undef _FSTARPU_DATA_FILTER_ALLOCATOR
  603. void fstarpu_data_filter_free(struct starpu_data_filter *filter)
  604. {
  605. memset(filter, 0, sizeof(*filter));
  606. free(filter);
  607. }
  608. void fstarpu_data_filter_set_filter_func(struct starpu_data_filter *filter, void *f_ptr)
  609. {
  610. STARPU_ASSERT(f_ptr != NULL);
  611. filter->filter_func = f_ptr;
  612. }
  613. void fstarpu_data_filter_set_nchildren(struct starpu_data_filter *filter, int nchildren)
  614. {
  615. STARPU_ASSERT(nchildren >= 0);
  616. filter->nchildren = nchildren;
  617. }
  618. void fstarpu_data_filter_set_get_nchildren_func(struct starpu_data_filter *filter, void *f_ptr)
  619. {
  620. filter->get_nchildren = f_ptr;
  621. }
  622. void fstarpu_data_filter_set_get_child_ops_func(struct starpu_data_filter *filter, void *f_ptr)
  623. {
  624. filter->get_child_ops = f_ptr;
  625. }
  626. void fstarpu_data_filter_set_filter_arg(struct starpu_data_filter *filter, int filter_arg)
  627. {
  628. STARPU_ASSERT(filter_arg >= 0); /* starpu_data_filter.filter_arg is unsigned, but
  629. * Fortran does not support unsigned types */
  630. filter->filter_arg = (unsigned)filter_arg;
  631. }
  632. void fstarpu_data_filter_set_filter_arg_ptr(struct starpu_data_filter *filter, void *filter_arg_ptr)
  633. {
  634. filter->filter_arg_ptr = filter_arg_ptr;
  635. }