fstarpu.c 23 KB

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