perfmodel.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2011 Télécom-SudParis
  5. * Copyright (C) 2013 Thibaut Lambert
  6. * Copyright (C) 2016 Uppsala University
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #include <starpu.h>
  20. #include <starpu_profiling.h>
  21. #include <common/config.h>
  22. #include <common/utils.h>
  23. #ifdef HAVE_UNISTD_H
  24. #include <unistd.h>
  25. #endif
  26. #include <sys/stat.h>
  27. #include <core/perfmodel/perfmodel.h>
  28. #include <core/jobs.h>
  29. #include <core/workers.h>
  30. #include <datawizard/datawizard.h>
  31. #include <core/task.h>
  32. #ifdef STARPU_HAVE_WINDOWS
  33. #include <windows.h>
  34. #endif
  35. /* This flag indicates whether performance models should be calibrated or not.
  36. * 0: models need not be calibrated
  37. * 1: models must be calibrated
  38. * 2: models must be calibrated, existing models are overwritten.
  39. */
  40. static unsigned calibrate_flag = 0;
  41. void _starpu_set_calibrate_flag(unsigned val)
  42. {
  43. calibrate_flag = val;
  44. }
  45. unsigned _starpu_get_calibrate_flag(void)
  46. {
  47. return calibrate_flag;
  48. }
  49. struct starpu_perfmodel_arch* starpu_worker_get_perf_archtype(int workerid, unsigned sched_ctx_id)
  50. {
  51. STARPU_ASSERT(workerid>=0);
  52. if(sched_ctx_id != STARPU_NMAX_SCHED_CTXS)
  53. {
  54. unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);
  55. if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
  56. return _starpu_sched_ctx_get_perf_archtype(child_sched_ctx);
  57. struct _starpu_sched_ctx *stream_ctx = _starpu_worker_get_ctx_stream(workerid);
  58. if(stream_ctx != NULL)
  59. return _starpu_sched_ctx_get_perf_archtype(stream_ctx->id);
  60. }
  61. struct _starpu_machine_config *config = _starpu_get_machine_config();
  62. /* This workerid may either be a basic worker or a combined worker */
  63. unsigned nworkers = config->topology.nworkers;
  64. if (workerid < (int)config->topology.nworkers)
  65. return &config->workers[workerid].perf_arch;
  66. /* We have a combined worker */
  67. unsigned ncombinedworkers = config->topology.ncombinedworkers;
  68. STARPU_ASSERT(workerid < (int)(ncombinedworkers + nworkers));
  69. return &config->combined_workers[workerid - nworkers].perf_arch;
  70. }
  71. /*
  72. * PER WORKER model
  73. */
  74. static double per_worker_task_expected_perf(struct starpu_perfmodel *model, unsigned workerid, struct starpu_task *task, unsigned nimpl)
  75. {
  76. double (*worker_cost_function)(struct starpu_task *task, unsigned workerid, unsigned nimpl);
  77. worker_cost_function = model->worker_cost_function;
  78. STARPU_ASSERT_MSG(worker_cost_function, "STARPU_PER_WORKER needs worker_cost_function to be defined");
  79. return worker_cost_function(task, workerid, nimpl);
  80. }
  81. /*
  82. * PER ARCH model
  83. */
  84. static double per_arch_task_expected_perf(struct starpu_perfmodel *model, struct starpu_perfmodel_arch * arch, struct starpu_task *task, unsigned nimpl)
  85. {
  86. int comb;
  87. double (*per_arch_cost_function)(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl);
  88. if (model->arch_cost_function)
  89. return model->arch_cost_function(task, arch, nimpl);
  90. comb = starpu_perfmodel_arch_comb_get(arch->ndevices, arch->devices);
  91. STARPU_ASSERT_MSG(comb != -1, "Didn't find the proper arch combination\n");
  92. STARPU_ASSERT_MSG(model->state->per_arch[comb] != NULL, "STARPU_PER_ARCH needs per-arch cost_function to be defined");
  93. per_arch_cost_function = model->state->per_arch[comb][nimpl].cost_function;
  94. STARPU_ASSERT_MSG(per_arch_cost_function, "STARPU_PER_ARCH needs per-arch cost_function to be defined");
  95. return per_arch_cost_function(task, arch, nimpl);
  96. }
  97. /*
  98. * Common model
  99. */
  100. double starpu_worker_get_relative_speedup(struct starpu_perfmodel_arch* perf_arch)
  101. {
  102. double speedup = 0;
  103. int dev;
  104. for(dev = 0; dev < perf_arch->ndevices; dev++)
  105. {
  106. double coef = 0.0;
  107. if (perf_arch->devices[dev].type == STARPU_CPU_WORKER)
  108. coef = _STARPU_CPU_ALPHA;
  109. else if (perf_arch->devices[dev].type == STARPU_CUDA_WORKER)
  110. coef = _STARPU_CUDA_ALPHA;
  111. else if (perf_arch->devices[dev].type == STARPU_OPENCL_WORKER)
  112. coef = _STARPU_OPENCL_ALPHA;
  113. else if (perf_arch->devices[dev].type == STARPU_MIC_WORKER)
  114. coef = _STARPU_MIC_ALPHA;
  115. else if (perf_arch->devices[dev].type == STARPU_MPI_MS_WORKER)
  116. coef = _STARPU_MPI_MS_ALPHA;
  117. speedup += coef * (perf_arch->devices[dev].ncores);
  118. }
  119. return speedup;
  120. }
  121. static double common_task_expected_perf(struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, struct starpu_task *task, unsigned nimpl)
  122. {
  123. double exp;
  124. double alpha;
  125. STARPU_ASSERT_MSG(model->cost_function, "STARPU_COMMON requires common cost_function to be defined");
  126. exp = model->cost_function(task, nimpl);
  127. alpha = starpu_worker_get_relative_speedup(arch);
  128. STARPU_ASSERT(!_STARPU_IS_ZERO(alpha));
  129. return exp/alpha;
  130. }
  131. void _starpu_init_and_load_perfmodel(struct starpu_perfmodel *model)
  132. {
  133. if (!model || model->is_loaded)
  134. return;
  135. starpu_perfmodel_init(model);
  136. if (model->is_loaded)
  137. return;
  138. switch (model->type)
  139. {
  140. case STARPU_PER_WORKER:
  141. case STARPU_PER_ARCH:
  142. case STARPU_COMMON:
  143. /* Nothing more to do than init */
  144. break;
  145. case STARPU_HISTORY_BASED:
  146. case STARPU_NL_REGRESSION_BASED:
  147. _starpu_load_history_based_model(model, 1);
  148. break;
  149. case STARPU_REGRESSION_BASED:
  150. case STARPU_MULTIPLE_REGRESSION_BASED:
  151. _starpu_load_history_based_model(model, 0);
  152. break;
  153. default:
  154. STARPU_ABORT();
  155. }
  156. model->is_loaded = 1;
  157. }
  158. static double starpu_model_expected_perf(struct starpu_task *task, struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  159. {
  160. double exp_perf = 0.0;
  161. if (model)
  162. {
  163. _starpu_init_and_load_perfmodel(model);
  164. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  165. switch (model->type)
  166. {
  167. case STARPU_PER_ARCH:
  168. exp_perf = per_arch_task_expected_perf(model, arch, task, nimpl);
  169. STARPU_ASSERT_MSG(isnan(exp_perf)||exp_perf>=0,"exp_perf=%lf\n",exp_perf);
  170. break;
  171. case STARPU_COMMON:
  172. exp_perf = common_task_expected_perf(model, arch, task, nimpl);
  173. STARPU_ASSERT_MSG(isnan(exp_perf)||exp_perf>=0,"exp_perf=%lf\n",exp_perf);
  174. break;
  175. case STARPU_HISTORY_BASED:
  176. exp_perf = _starpu_history_based_job_expected_perf(model, arch, j, nimpl);
  177. STARPU_ASSERT_MSG(isnan(exp_perf)||exp_perf>=0,"exp_perf=%lf\n",exp_perf);
  178. break;
  179. case STARPU_REGRESSION_BASED:
  180. exp_perf = _starpu_regression_based_job_expected_perf(model, arch, j, nimpl);
  181. STARPU_ASSERT_MSG(isnan(exp_perf)||exp_perf>=0,"exp_perf=%lf\n",exp_perf);
  182. break;
  183. case STARPU_NL_REGRESSION_BASED:
  184. exp_perf = _starpu_non_linear_regression_based_job_expected_perf(model, arch, j,nimpl);
  185. STARPU_ASSERT_MSG(isnan(exp_perf)||exp_perf>=0,"exp_perf=%lf\n",exp_perf);
  186. break;
  187. case STARPU_MULTIPLE_REGRESSION_BASED:
  188. exp_perf = _starpu_multiple_regression_based_job_expected_perf(model, arch, j, nimpl);
  189. STARPU_ASSERT_MSG(isnan(exp_perf)||exp_perf>=0,"exp_perf=%lf\n",exp_perf);
  190. break;
  191. default:
  192. STARPU_ABORT();
  193. }
  194. }
  195. /* no model was found */
  196. return exp_perf;
  197. }
  198. static double starpu_model_worker_expected_perf(struct starpu_task *task, struct starpu_perfmodel *model, unsigned workerid, unsigned sched_ctx_id, unsigned nimpl)
  199. {
  200. if (!model)
  201. return 0.0;
  202. if (model->type == STARPU_PER_WORKER)
  203. return per_worker_task_expected_perf(model, workerid, task, nimpl);
  204. else
  205. {
  206. struct starpu_perfmodel_arch *per_arch = starpu_worker_get_perf_archtype(workerid, sched_ctx_id);
  207. return starpu_model_expected_perf(task, model, per_arch, nimpl);
  208. }
  209. }
  210. double starpu_task_expected_length(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  211. {
  212. if (!task->cl)
  213. /* Tasks without codelet don't actually take time */
  214. return 0.0;
  215. return starpu_model_expected_perf(task, task->cl->model, arch, nimpl);
  216. }
  217. double starpu_task_worker_expected_length(struct starpu_task *task, unsigned workerid, unsigned sched_ctx_id, unsigned nimpl)
  218. {
  219. if (!task->cl)
  220. /* Tasks without codelet don't actually take time */
  221. return 0.0;
  222. return starpu_model_worker_expected_perf(task, task->cl->model, workerid, sched_ctx_id, nimpl);
  223. }
  224. double starpu_task_expected_energy(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  225. {
  226. if (!task->cl)
  227. /* Tasks without codelet don't actually take time */
  228. return 0.0;
  229. return starpu_model_expected_perf(task, task->cl->energy_model, arch, nimpl);
  230. }
  231. double starpu_task_worker_expected_energy(struct starpu_task *task, unsigned workerid, unsigned sched_ctx_id, unsigned nimpl)
  232. {
  233. if (!task->cl)
  234. /* Tasks without codelet don't actually take time */
  235. return 0.0;
  236. return starpu_model_worker_expected_perf(task, task->cl->energy_model, workerid, sched_ctx_id, nimpl);
  237. }
  238. double starpu_task_expected_conversion_time(struct starpu_task *task,
  239. struct starpu_perfmodel_arch* arch,
  240. unsigned nimpl)
  241. {
  242. unsigned i;
  243. double sum = 0.0;
  244. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  245. #ifdef STARPU_DEVEL
  246. #warning TODO: conversion time with combined arch perfmodel
  247. #endif
  248. STARPU_ASSERT_MSG(arch->ndevices == 1, "TODO");
  249. for (i = 0; i < nbuffers; i++)
  250. {
  251. starpu_data_handle_t handle;
  252. struct starpu_task *conversion_task;
  253. enum starpu_node_kind node_kind;
  254. handle = STARPU_TASK_GET_HANDLE(task, i);
  255. if (!_starpu_data_is_multiformat_handle(handle))
  256. continue;
  257. node_kind = _starpu_worker_get_node_kind(arch->devices[0].type);
  258. if (!_starpu_handle_needs_conversion_task_for_arch(handle, node_kind))
  259. continue;
  260. conversion_task = _starpu_create_conversion_task_for_arch(handle, node_kind);
  261. sum += starpu_task_expected_length(conversion_task, arch, nimpl);
  262. _starpu_spin_lock(&handle->header_lock);
  263. handle->refcnt--;
  264. handle->busy_count--;
  265. if (!_starpu_data_check_not_busy(handle))
  266. _starpu_spin_unlock(&handle->header_lock);
  267. starpu_task_clean(conversion_task);
  268. free(conversion_task);
  269. }
  270. return sum;
  271. }
  272. /* Predict the transfer time (in µs) to move a handle to a memory node */
  273. double starpu_data_expected_transfer_time(starpu_data_handle_t handle, unsigned memory_node, enum starpu_data_access_mode mode)
  274. {
  275. /* If we don't need to read the content of the handle */
  276. if (!(mode & STARPU_R))
  277. return 0.0;
  278. if (starpu_data_is_on_node(handle, memory_node))
  279. return 0.0;
  280. size_t size = _starpu_data_get_size(handle);
  281. /* XXX in case we have an abstract piece of data (eg. with the
  282. * void interface, this does not introduce any overhead, and we
  283. * don't even want to consider the latency that is not
  284. * relevant). */
  285. if (size == 0)
  286. return 0.0;
  287. int src_node = _starpu_select_src_node(handle, memory_node);
  288. if (src_node < 0)
  289. /* Will just create it in place. Ideally we should take the
  290. * time to create it into account */
  291. return 0.0;
  292. #define MAX_REQUESTS 4
  293. unsigned src_nodes[MAX_REQUESTS];
  294. unsigned dst_nodes[MAX_REQUESTS];
  295. unsigned handling_nodes[MAX_REQUESTS];
  296. int nhops = _starpu_determine_request_path(handle, src_node, memory_node, mode,
  297. MAX_REQUESTS,
  298. src_nodes, dst_nodes, handling_nodes, 0);
  299. int i;
  300. double duration = 0.;
  301. for (i = 0; i < nhops; i++)
  302. duration += starpu_transfer_predict(src_nodes[i], dst_nodes[i], size);
  303. return duration;
  304. }
  305. /* Data transfer performance modeling */
  306. double starpu_task_expected_data_transfer_time(unsigned memory_node, struct starpu_task *task)
  307. {
  308. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  309. unsigned buffer;
  310. double penalty = 0.0;
  311. for (buffer = 0; buffer < nbuffers; buffer++)
  312. {
  313. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, buffer);
  314. enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, buffer);
  315. int node = _starpu_task_data_get_node_on_node(task, buffer, memory_node);
  316. penalty += starpu_data_expected_transfer_time(handle, node, mode);
  317. }
  318. return penalty;
  319. }
  320. /* Data transfer performance modeling */
  321. double starpu_task_expected_data_transfer_time_for(struct starpu_task *task, unsigned worker)
  322. {
  323. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  324. unsigned buffer;
  325. double penalty = 0.0;
  326. for (buffer = 0; buffer < nbuffers; buffer++)
  327. {
  328. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, buffer);
  329. enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, buffer);
  330. int node = _starpu_task_data_get_node_on_worker(task, buffer, worker);
  331. penalty += starpu_data_expected_transfer_time(handle, node, mode);
  332. }
  333. return penalty;
  334. }
  335. /* Return the expected duration of the entire task bundle in µs */
  336. double starpu_task_bundle_expected_length(starpu_task_bundle_t bundle, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  337. {
  338. double expected_length = 0.0;
  339. /* We expect the length of the bundle the be the sum of the different tasks length. */
  340. STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
  341. struct _starpu_task_bundle_entry *entry;
  342. entry = bundle->list;
  343. while (entry)
  344. {
  345. if(!entry->task->scheduled)
  346. {
  347. double task_length = starpu_task_expected_length(entry->task, arch, nimpl);
  348. /* In case the task is not calibrated, we consider the task
  349. * ends immediately. */
  350. if (task_length > 0.0)
  351. expected_length += task_length;
  352. }
  353. entry = entry->next;
  354. }
  355. STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
  356. return expected_length;
  357. }
  358. /* Return the expected energy consumption of the entire task bundle in J */
  359. double starpu_task_bundle_expected_energy(starpu_task_bundle_t bundle, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  360. {
  361. double expected_energy = 0.0;
  362. /* We expect total consumption of the bundle the be the sum of the different tasks consumption. */
  363. STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
  364. struct _starpu_task_bundle_entry *entry;
  365. entry = bundle->list;
  366. while (entry)
  367. {
  368. double task_energy = starpu_task_expected_energy(entry->task, arch, nimpl);
  369. /* In case the task is not calibrated, we consider the task
  370. * ends immediately. */
  371. if (task_energy > 0.0)
  372. expected_energy += task_energy;
  373. entry = entry->next;
  374. }
  375. STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
  376. return expected_energy;
  377. }
  378. /* Return the time (in µs) expected to transfer all data used within the bundle */
  379. double starpu_task_bundle_expected_data_transfer_time(starpu_task_bundle_t bundle, unsigned memory_node)
  380. {
  381. STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
  382. struct _starpu_handle_list *handles = NULL;
  383. /* We list all the handle that are accessed within the bundle. */
  384. /* For each task in the bundle */
  385. struct _starpu_task_bundle_entry *entry = bundle->list;
  386. while (entry)
  387. {
  388. struct starpu_task *task = entry->task;
  389. if (task->cl)
  390. {
  391. unsigned b;
  392. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  393. for (b = 0; b < nbuffers; b++)
  394. {
  395. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, b);
  396. enum starpu_data_access_mode mode = STARPU_TASK_GET_MODE(task, b);
  397. if (!(mode & STARPU_R))
  398. continue;
  399. /* Insert the handle in the sorted list in case
  400. * it's not already in that list. */
  401. _insertion_handle_sorted(&handles, handle, mode);
  402. }
  403. }
  404. entry = entry->next;
  405. }
  406. STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
  407. /* Compute the sum of data transfer time, and destroy the list */
  408. double total_exp = 0.0;
  409. while (handles)
  410. {
  411. struct _starpu_handle_list *current = handles;
  412. handles = handles->next;
  413. double exp;
  414. exp = starpu_data_expected_transfer_time(current->handle, memory_node, current->mode);
  415. total_exp += exp;
  416. free(current);
  417. }
  418. return total_exp;
  419. }
  420. static int directory_existence_was_tested = 0;
  421. static char *_perf_model_dir = NULL;
  422. static char *_perf_model_dir_codelet = NULL;
  423. static char *_perf_model_dir_bus = NULL;
  424. static char *_perf_model_dir_debug = NULL;
  425. #define _PERF_MODEL_DIR_MAXLEN 256
  426. void _starpu_set_perf_model_dirs()
  427. {
  428. _STARPU_MALLOC(_perf_model_dir, _PERF_MODEL_DIR_MAXLEN);
  429. _STARPU_MALLOC(_perf_model_dir_codelet, _PERF_MODEL_DIR_MAXLEN);
  430. _STARPU_MALLOC(_perf_model_dir_bus, _PERF_MODEL_DIR_MAXLEN);
  431. _STARPU_MALLOC(_perf_model_dir_debug, _PERF_MODEL_DIR_MAXLEN);
  432. #ifdef STARPU_PERF_MODEL_DIR
  433. /* use the directory specified at configure time */
  434. snprintf(_perf_model_dir, _PERF_MODEL_DIR_MAXLEN, "%s", (char *)STARPU_PERF_MODEL_DIR);
  435. #else
  436. snprintf(_perf_model_dir, _PERF_MODEL_DIR_MAXLEN, "%s/.starpu/sampling/", _starpu_get_home_path());
  437. #endif
  438. char *path = starpu_getenv("STARPU_PERF_MODEL_DIR");
  439. if (path)
  440. {
  441. snprintf(_perf_model_dir, _PERF_MODEL_DIR_MAXLEN, "%s/", path);
  442. }
  443. snprintf(_perf_model_dir_codelet, _PERF_MODEL_DIR_MAXLEN, "%s/codelets/%d/", _perf_model_dir, _STARPU_PERFMODEL_VERSION);
  444. snprintf(_perf_model_dir_bus, _PERF_MODEL_DIR_MAXLEN, "%s/bus/", _perf_model_dir);
  445. snprintf(_perf_model_dir_debug, _PERF_MODEL_DIR_MAXLEN, "%s/debug/", _perf_model_dir);
  446. }
  447. char *_starpu_get_perf_model_dir_codelet()
  448. {
  449. _starpu_create_sampling_directory_if_needed();
  450. return _perf_model_dir_codelet;
  451. }
  452. char *_starpu_get_perf_model_dir_bus()
  453. {
  454. _starpu_create_sampling_directory_if_needed();
  455. return _perf_model_dir_bus;
  456. }
  457. char *_starpu_get_perf_model_dir_debug()
  458. {
  459. _starpu_create_sampling_directory_if_needed();
  460. return _perf_model_dir_debug;
  461. }
  462. void _starpu_create_sampling_directory_if_needed(void)
  463. {
  464. if (!directory_existence_was_tested)
  465. {
  466. _starpu_set_perf_model_dirs();
  467. /* The performance of the codelets are stored in
  468. * $STARPU_PERF_MODEL_DIR/codelets/ while those of the bus are stored in
  469. * $STARPU_PERF_MODEL_DIR/bus/ so that we don't have name collisions */
  470. /* Testing if a directory exists and creating it otherwise
  471. may not be safe: it is possible that the permission are
  472. changed in between. Instead, we create it and check if
  473. it already existed before */
  474. _starpu_mkpath_and_check(_perf_model_dir, S_IRWXU);
  475. /* Per-task performance models */
  476. _starpu_mkpath_and_check(_perf_model_dir_codelet, S_IRWXU);
  477. /* Performance of the memory subsystem */
  478. _starpu_mkpath_and_check(_perf_model_dir_bus, S_IRWXU);
  479. /* Performance debug measurements */
  480. _starpu_mkpath(_perf_model_dir_debug, S_IRWXU);
  481. directory_existence_was_tested = 1;
  482. }
  483. }
  484. void starpu_perfmodel_free_sampling(void)
  485. {
  486. free(_perf_model_dir);
  487. _perf_model_dir = NULL;
  488. free(_perf_model_dir_codelet);
  489. _perf_model_dir_codelet = NULL;
  490. free(_perf_model_dir_bus);
  491. _perf_model_dir_bus = NULL;
  492. free(_perf_model_dir_debug);
  493. _perf_model_dir_debug = NULL;
  494. directory_existence_was_tested = 0;
  495. _starpu_free_arch_combs();
  496. }
  497. static double nop_cost_function(struct starpu_task *t STARPU_ATTRIBUTE_UNUSED, struct starpu_perfmodel_arch *a STARPU_ATTRIBUTE_UNUSED, unsigned i STARPU_ATTRIBUTE_UNUSED)
  498. {
  499. return 0.000001;
  500. }
  501. struct starpu_perfmodel starpu_perfmodel_nop =
  502. {
  503. .type = STARPU_PER_ARCH,
  504. .arch_cost_function = nop_cost_function,
  505. };