starpu_perfmodel_plot.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2014 Université de Bordeaux 1
  4. * Copyright (C) 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011 Télécom-SudParis
  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 <config.h>
  19. #include <assert.h>
  20. #include <unistd.h>
  21. #include <stdio.h>
  22. #include <sys/stat.h>
  23. #include <limits.h>
  24. #ifdef STARPU_USE_FXT
  25. #include <common/fxt.h>
  26. #endif
  27. #include <common/utils.h>
  28. #include <starpu.h>
  29. #include <core/perfmodel/perfmodel.h> // we need to browse the list associated to history-based models
  30. #include <core/workers.h>
  31. #if defined(_WIN32) && !defined(__CYGWIN__)
  32. #include <windows.h>
  33. #endif
  34. #define PROGNAME "starpu_perfmodel_plot"
  35. /* display all available models */
  36. static int list = 0;
  37. /* what kernel ? */
  38. static char *symbol = NULL;
  39. /* which architecture ? (NULL = all)*/
  40. static char *archname = NULL;
  41. /* Unless a FxT file is specified, we just display the model */
  42. static int no_fxt_file = 1;
  43. static int gflops = 0;
  44. #ifdef STARPU_USE_FXT
  45. static struct starpu_fxt_codelet_event *dumped_codelets;
  46. static struct starpu_fxt_options options;
  47. #endif
  48. #ifdef STARPU_USE_FXT
  49. static int **archtype_is_found[STARPU_NARCH];
  50. static char data_file_name[256];
  51. #endif
  52. static char avg_file_name[256];
  53. static char gnuplot_file_name[256];
  54. static void usage()
  55. {
  56. fprintf(stderr, "Draw a graph corresponding to the execution time of a \
  57. given perfmodel\n");
  58. fprintf(stderr, "Usage: %s [ options ]\n", PROGNAME);
  59. fprintf(stderr, "\n");
  60. fprintf(stderr, "One must specify a symbol with the -s option or use -l\n");
  61. fprintf(stderr, "Options:\n");
  62. fprintf(stderr, " -l display all available models\n");
  63. fprintf(stderr, " -s <symbol> specify the symbol\n");
  64. fprintf(stderr, " -f draw GFlops instead of time\n");
  65. fprintf(stderr, " -i <Fxt files> input FxT files generated by StarPU\n");
  66. fprintf(stderr, " -a <arch> specify the architecture (e.g. cpu, cpu:x, cuda, cuda_d, opencl, opencl_d)\n");
  67. fprintf(stderr, " -h, --help display this help and exit\n");
  68. fprintf(stderr, " -v, --version output version information and exit\n\n");
  69. fprintf(stderr, "Report bugs to <%s>.", PACKAGE_BUGREPORT);
  70. fprintf(stderr, "\n");
  71. }
  72. static void parse_args(int argc, char **argv)
  73. {
  74. #ifdef STARPU_USE_FXT
  75. /* Default options */
  76. starpu_fxt_options_init(&options);
  77. options.out_paje_path = NULL;
  78. options.activity_path = NULL;
  79. options.distrib_time_path = NULL;
  80. options.dag_path = NULL;
  81. options.dumped_codelets = &dumped_codelets;
  82. #endif
  83. /* We want to support arguments such as "-i trace_*" */
  84. unsigned reading_input_filenames = 0;
  85. int i;
  86. for (i = 1; i < argc; i++)
  87. {
  88. if (strcmp(argv[i], "-s") == 0)
  89. {
  90. symbol = argv[++i];
  91. continue;
  92. }
  93. if (strcmp(argv[i], "-i") == 0)
  94. {
  95. reading_input_filenames = 1;
  96. #ifdef STARPU_USE_FXT
  97. options.filenames[options.ninputfiles++] = argv[++i];
  98. no_fxt_file = 0;
  99. #else
  100. fprintf(stderr, "Warning: FxT support was not enabled in StarPU: FxT traces will thus be ignored!\n");
  101. #endif
  102. continue;
  103. }
  104. if (strcmp(argv[i], "-l") == 0)
  105. {
  106. list = 1;
  107. continue;
  108. }
  109. if (strcmp(argv[i], "-f") == 0)
  110. {
  111. gflops = 1;
  112. continue;
  113. }
  114. if (strcmp(argv[i], "-a") == 0)
  115. {
  116. archname = argv[++i];
  117. continue;
  118. }
  119. if (strcmp(argv[i], "-h") == 0 ||
  120. strcmp(argv[i], "--help") == 0)
  121. {
  122. usage();
  123. exit(EXIT_SUCCESS);
  124. }
  125. if (strcmp(argv[i], "-v") == 0 ||
  126. strcmp(argv[i], "--version") == 0)
  127. {
  128. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  129. exit(EXIT_SUCCESS);
  130. }
  131. /* If the reading_input_filenames flag is set, and that the
  132. * argument does not match an option, we assume this may be
  133. * another filename */
  134. if (reading_input_filenames)
  135. {
  136. #ifdef STARPU_USE_FXT
  137. options.filenames[options.ninputfiles++] = argv[i];
  138. #endif
  139. continue;
  140. }
  141. }
  142. if (!symbol && !list)
  143. {
  144. fprintf(stderr, "Incorrect usage, aborting\n");
  145. usage();
  146. exit(-1);
  147. }
  148. }
  149. static char *replace_char(char *str, char old, char new)
  150. {
  151. char *p = strdup(str);
  152. char *ptr = p;
  153. while (*ptr)
  154. {
  155. if (*ptr == old) *ptr = new;
  156. ptr ++;
  157. }
  158. return p;
  159. }
  160. static void print_comma(FILE *gnuplot_file, int *first)
  161. {
  162. if (*first)
  163. {
  164. *first = 0;
  165. }
  166. else
  167. {
  168. fprintf(gnuplot_file, ",\\\n\t");
  169. }
  170. }
  171. static void display_perf_model(FILE *gnuplot_file, struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, int *first, unsigned nimpl)
  172. {
  173. char arch_name[256];
  174. starpu_perfmodel_get_arch_name(arch, arch_name, 256, nimpl);
  175. struct starpu_perfmodel_per_arch *arch_model =
  176. &model->per_arch[arch->type][arch->devid][arch->ncore][nimpl];
  177. if (arch_model->regression.valid || arch_model->regression.nl_valid)
  178. fprintf(stderr,"Arch: %s\n", arch_name);
  179. #ifdef STARPU_USE_FXT
  180. if (!gflops && !no_fxt_file && archtype_is_found[arch->type][arch->devid][arch->ncore] && nimpl == 0)
  181. {
  182. print_comma(gnuplot_file, first);
  183. fprintf(gnuplot_file, "\"< grep -w \\^%d_%d_%d %s\" using 2:3 title \"Profiling %s\"", arch->type, arch->devid, arch->ncore, data_file_name, arch_name);
  184. }
  185. #endif
  186. /* Only display the regression model if we could actually build a model */
  187. if (!gflops && arch_model->regression.valid && !arch_model->regression.nl_valid)
  188. {
  189. print_comma(gnuplot_file, first);
  190. fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
  191. fprintf(stderr, "\t\talpha = %e\n", arch_model->regression.alpha * 0.001);
  192. fprintf(stderr, "\t\tbeta = %e\n", arch_model->regression.beta);
  193. fprintf(gnuplot_file, "0.001 * %f * x ** %f title \"Linear Regression %s\"",
  194. arch_model->regression.alpha, arch_model->regression.beta, arch_name);
  195. }
  196. if (!gflops && arch_model->regression.nl_valid)
  197. {
  198. print_comma(gnuplot_file, first);
  199. fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
  200. fprintf(stderr, "\t\ta = %e\n", arch_model->regression.a * 0.001);
  201. fprintf(stderr, "\t\tb = %e\n", arch_model->regression.b);
  202. fprintf(stderr, "\t\tc = %e\n", arch_model->regression.c * 0.001);
  203. fprintf(gnuplot_file, "0.001 * %f * x ** %f + 0.001 * %f title \"Non-Linear Regression %s\"",
  204. arch_model->regression.a, arch_model->regression.b, arch_model->regression.c, arch_name);
  205. }
  206. }
  207. static void display_history_based_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, enum starpu_worker_archtype* type, int* devid, int* ncore, int *first)
  208. {
  209. char *command;
  210. FILE *datafile;
  211. struct starpu_perfmodel_history_list *ptr;
  212. char arch_name[32];
  213. int col;
  214. size_t len;
  215. unsigned long last, minimum = 0;
  216. len = 10 + strlen(avg_file_name) + 1;
  217. command = (char *) malloc(len);
  218. datafile = fopen(avg_file_name, "w");
  219. free(command);
  220. col = 2;
  221. unsigned implid;
  222. unsigned archmin, archmax, devmin, devmax, coremin, coremax;
  223. if(type != NULL)
  224. {
  225. archmin = *type;
  226. archmax = *type +1;
  227. if(devid != NULL)
  228. {
  229. devmin = *devid;
  230. devmax = *devid +1;
  231. if(ncore != NULL)
  232. {
  233. coremin = *ncore;
  234. coremax = *ncore +1;
  235. }
  236. else
  237. {
  238. coremin = 0;
  239. coremax = 0;
  240. }
  241. }
  242. else
  243. {
  244. devmin = 0;
  245. devmax = 0;
  246. coremin = 0;
  247. coremax = 0;
  248. }
  249. }
  250. else
  251. {
  252. archmin = 0;
  253. archmax = STARPU_NARCH;
  254. devmin = 0;
  255. devmax = 0;
  256. coremin = 0;
  257. coremax = 0;
  258. }
  259. struct starpu_perfmodel_arch arch;
  260. unsigned archtype, dev, core;
  261. for (archtype = archmin; archtype < archmax; archtype++)
  262. {
  263. arch.type = archtype;
  264. if(model->per_arch[archtype]!=NULL)
  265. {
  266. for(dev = devmin; model->per_arch[archtype][dev] != NULL && (devmax == 0 || dev < devmax);dev++)
  267. {
  268. arch.devid = dev;
  269. for(core = coremin; model->per_arch[archtype][dev][core] != NULL && (coremax == 0 || core < coremax); core++)
  270. {
  271. arch.ncore = core;
  272. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  273. {
  274. struct starpu_perfmodel_per_arch *arch_model = &model->per_arch[archtype][dev][core][implid];
  275. starpu_perfmodel_get_arch_name(&arch, arch_name, 32, implid);
  276. //ptrs[arch-arch1][implid] = ptr[arch-arch1][implid] = arch_model->list;
  277. if (arch_model->list)
  278. {
  279. print_comma(gnuplot_file, first);
  280. fprintf(gnuplot_file, "\"%s\" using 1:%d:%d with errorlines title \"Average %s\"", avg_file_name, col, col+1, replace_char(arch_name, '_', '-'));
  281. col += 2;
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. /* Dump entries in size order */
  289. while (1)
  290. {
  291. last = minimum;
  292. minimum = ULONG_MAX;
  293. /* Get the next minimum */
  294. for (archtype = archmin; archtype < archmax; archtype++)
  295. {
  296. if(model->per_arch[archtype]!=NULL)
  297. {
  298. for(dev = devmin; model->per_arch[archtype][dev] != NULL && (devmax == 0 || dev < devmax);dev++)
  299. {
  300. for(core = coremin; model->per_arch[archtype][dev][core] != NULL && (coremax == 0 || core < coremax); core++)
  301. {
  302. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  303. {
  304. struct starpu_perfmodel_per_arch *arch_model = &model->per_arch[archtype][dev][core][implid];
  305. for (ptr = arch_model->list; ptr; ptr = ptr->next)
  306. {
  307. unsigned long size = ptr->entry->size;
  308. if (size > last && size < minimum)
  309. minimum = size;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. if (minimum == ULONG_MAX)
  317. break;
  318. fprintf(stderr, "%lu ", minimum);
  319. fprintf(datafile, "%-15lu ", minimum);
  320. for (archtype = archmin; archtype < archmax; archtype++)
  321. if(model->per_arch[archtype]!=NULL)
  322. for(dev = devmin; model->per_arch[archtype][dev] != NULL && (devmax == 0 || dev < devmax);dev++)
  323. for(core = coremin; model->per_arch[archtype][dev][core] != NULL && (coremax == 0 || core < coremax); core++)
  324. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  325. {
  326. struct starpu_perfmodel_per_arch *arch_model = &model->per_arch[archtype][dev][core][implid];
  327. for (ptr = arch_model->list; ptr; ptr = ptr->next)
  328. {
  329. struct starpu_perfmodel_history_entry *entry = ptr->entry;
  330. if (entry->size == minimum)
  331. {
  332. if (gflops)
  333. fprintf(datafile, "\t%-15le\t%-15le", entry->flops / (entry->mean * 1000),
  334. entry->flops / ((entry->mean + entry->deviation) * 1000) -
  335. entry->flops / (entry->mean * 1000)
  336. );
  337. else
  338. fprintf(datafile, "\t%-15le\t%-15le", 0.001*entry->mean, 0.001*entry->deviation);
  339. break;
  340. }
  341. }
  342. if (!ptr && arch_model->list)
  343. /* No value for this arch. */
  344. fprintf(datafile, "\t\"\"\t\"\"");
  345. }
  346. fprintf(datafile, "\n");
  347. }
  348. fprintf(stderr, "\n");
  349. fclose(datafile);
  350. }
  351. static void display_selected_arch_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, int *first)
  352. {
  353. unsigned implid;
  354. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  355. display_perf_model(gnuplot_file, model, arch, first, implid);
  356. }
  357. static void display_selected_device_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, enum starpu_worker_archtype archtype, int devid, int *first)
  358. {
  359. unsigned ncore;
  360. struct starpu_perfmodel_arch arch;
  361. arch.type = archtype;
  362. arch.devid = devid;
  363. for(ncore=0; model->per_arch[archtype][devid][ncore] != NULL; ncore++)
  364. {
  365. arch.ncore = ncore;
  366. display_selected_arch_perf_models(gnuplot_file,model,&arch,first);
  367. }
  368. }
  369. static void display_selected_archtype_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, enum starpu_worker_archtype archtype, int *first)
  370. {
  371. unsigned devid;
  372. for(devid=0; model->per_arch[archtype][devid] != NULL; devid++)
  373. display_selected_device_perf_models(gnuplot_file,model,archtype,devid,first);
  374. }
  375. static void display_all_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, int *first)
  376. {
  377. unsigned archtype;
  378. for(archtype = 0; archtype < STARPU_NARCH; archtype++)
  379. display_selected_archtype_perf_models(gnuplot_file,model,archtype,first);
  380. }
  381. #ifdef STARPU_USE_FXT
  382. static int ** init_archtype_is_found_per_arch(int maxdevid, unsigned* maxncore_table)
  383. {
  384. int devid, ncore;
  385. int ** archtype_is_found_per_arch = malloc(sizeof(*archtype_is_found_per_arch)*(maxdevid+1));
  386. archtype_is_found_per_arch[maxdevid] = NULL;
  387. for(devid=0; devid<maxdevid; devid++)
  388. {
  389. int maxncore;
  390. if(maxncore_table != NULL)
  391. maxncore = maxncore_table[devid];
  392. else
  393. maxncore = 1;
  394. archtype_is_found_per_arch[devid] = malloc(sizeof(*archtype_is_found_per_arch[devid])*(maxncore+1));
  395. archtype_is_found_per_arch[devid][maxncore] = 0;
  396. for(ncore=0; ncore<maxncore; ncore++)
  397. archtype_is_found_per_arch[devid][ncore] = 0;
  398. }
  399. return archtype_is_found_per_arch;
  400. }
  401. static void init_archtype_is_found(struct starpu_perfmodel *model)
  402. {
  403. unsigned archtype, devid, ndevice, ncore, *maxncore;
  404. for(archtype = 0; archtype < STARPU_NARCH; archtype++)
  405. {
  406. for(devid=0; model->per_arch[archtype][devid] != NULL; devid++)
  407. ;
  408. ndevice = devid;
  409. if(ndevice != 0)
  410. {
  411. maxncore = malloc(sizeof(*maxncore)*ndevice);
  412. for(devid=0; devid < ndevice; devid++)
  413. {
  414. for(ncore=0; model->per_arch[archtype][devid][ncore] != NULL; ncore++)
  415. ;
  416. maxncore[devid] = ncore;
  417. }
  418. }
  419. else
  420. {
  421. maxncore = NULL;
  422. }
  423. archtype_is_found[archtype] = init_archtype_is_found_per_arch(ndevice,maxncore);
  424. if(maxncore != NULL)
  425. free(maxncore);
  426. }
  427. }
  428. static void dump_data_file(FILE *data_file, struct starpu_perfmodel *model)
  429. {
  430. init_archtype_is_found(model);
  431. int i;
  432. for (i = 0; i < options.dumped_codelets_count; i++)
  433. {
  434. /* Dump only if the symbol matches user's request */
  435. if (strncmp(dumped_codelets[i].symbol, symbol, (FXT_MAX_PARAMS - 4)*sizeof(unsigned long)-1) == 0)
  436. {
  437. struct starpu_perfmodel_arch* arch = &dumped_codelets[i].arch;
  438. archtype_is_found[arch->type][arch->devid][arch->ncore] = 1;
  439. size_t size = dumped_codelets[i].size;
  440. float time = dumped_codelets[i].time;
  441. fprintf(data_file, "%d_%d_%d %f %f\n", arch->type, arch->devid, arch->ncore, (float)size, time);
  442. }
  443. }
  444. }
  445. #endif
  446. static void display_selected_models(FILE *gnuplot_file, struct starpu_perfmodel *model)
  447. {
  448. fprintf(gnuplot_file, "#!/usr/bin/gnuplot -persist\n");
  449. fprintf(gnuplot_file, "\n");
  450. fprintf(gnuplot_file, "set term postscript eps enhanced color\n");
  451. fprintf(gnuplot_file, "set output \"starpu_%s.eps\"\n", symbol);
  452. fprintf(gnuplot_file, "set title \"Model for codelet %s\"\n", replace_char(symbol, '_', '-'));
  453. fprintf(gnuplot_file, "set xlabel \"Total data size\"\n");
  454. if (gflops)
  455. fprintf(gnuplot_file, "set ylabel \"GFlops\"\n");
  456. else
  457. fprintf(gnuplot_file, "set ylabel \"Time (ms)\"\n");
  458. fprintf(gnuplot_file, "\n");
  459. fprintf(gnuplot_file, "set key top left\n");
  460. fprintf(gnuplot_file, "set logscale x\n");
  461. fprintf(gnuplot_file, "set logscale y\n");
  462. fprintf(gnuplot_file, "\n");
  463. /* If no input data is given to gnuplot, we at least need to specify an
  464. * arbitrary range. */
  465. if (no_fxt_file)
  466. fprintf(gnuplot_file, "set xrange [1:10**9]\n\n");
  467. int first = 1;
  468. fprintf(gnuplot_file, "plot\t");
  469. struct starpu_perfmodel_arch arch;
  470. struct _starpu_machine_config *conf = _starpu_get_machine_config();
  471. if (archname == NULL)
  472. {
  473. /* display all architectures */
  474. display_all_perf_models(gnuplot_file, model, &first);
  475. display_history_based_perf_models(gnuplot_file, model, NULL, NULL, NULL, &first);
  476. }
  477. else
  478. {
  479. if (strcmp(archname, "cpu") == 0)
  480. {
  481. arch.type = STARPU_CPU_WORKER;
  482. arch.devid = 1;
  483. arch.ncore = 0;
  484. display_selected_arch_perf_models(gnuplot_file, model, &arch, &first);
  485. display_history_based_perf_models(gnuplot_file, model, &arch.type, &arch.devid, &arch.ncore, &first);
  486. return;
  487. }
  488. unsigned k;
  489. if (sscanf(archname, "cpu:%u", &k) == 1)
  490. {
  491. /* For combined CPU workers */
  492. if ((k < 1) || (k > conf->topology.ncpus))
  493. {
  494. fprintf(stderr, "Invalid CPU size\n");
  495. exit(-1);
  496. }
  497. arch.type = STARPU_CPU_WORKER;
  498. arch.devid = 1;
  499. arch.ncore = k - 1;
  500. display_selected_arch_perf_models(gnuplot_file, model, &arch, &first);
  501. display_history_based_perf_models(gnuplot_file, model, &arch.type, &arch.devid, &arch.ncore, &first);
  502. return;
  503. }
  504. if (strcmp(archname, "cuda") == 0)
  505. {
  506. unsigned archtype = STARPU_CUDA_WORKER;
  507. display_selected_archtype_perf_models(gnuplot_file, model, archtype, &first);
  508. display_history_based_perf_models(gnuplot_file, model, &archtype, NULL, NULL, &first);
  509. return;
  510. }
  511. /* There must be a cleaner way ! */
  512. unsigned gpuid;
  513. int nmatched;
  514. nmatched = sscanf(archname, "cuda_%u", &gpuid);
  515. if (nmatched == 1)
  516. {
  517. if (gpuid < conf->topology.ncudagpus)
  518. {
  519. arch.type = STARPU_CUDA_WORKER;
  520. arch.devid = gpuid;
  521. arch.ncore = 0;
  522. display_selected_arch_perf_models(gnuplot_file, model, &arch, &first);
  523. display_history_based_perf_models(gnuplot_file, model, &arch.type, &arch.devid, &arch.ncore, &first);
  524. return;
  525. }
  526. else
  527. {
  528. fprintf(stderr, "Invalid CUDA device %d (last valid one is %d)\n", gpuid, STARPU_MAXCUDADEVS-1);
  529. exit(-1);
  530. }
  531. }
  532. if (strcmp(archname, "opencl") == 0)
  533. {
  534. unsigned archtype = STARPU_OPENCL_WORKER;
  535. display_selected_archtype_perf_models(gnuplot_file, model, archtype, &first);
  536. display_history_based_perf_models(gnuplot_file, model, &archtype, NULL, NULL, &first);
  537. return;
  538. }
  539. /* There must be a cleaner way ! */
  540. nmatched = sscanf(archname, "opencl_%u", &gpuid);
  541. if (nmatched == 1)
  542. {
  543. if (gpuid < conf->topology.nopenclgpus)
  544. {
  545. arch.type = STARPU_OPENCL_WORKER;
  546. arch.devid = gpuid;
  547. arch.ncore = 0;
  548. display_selected_arch_perf_models(gnuplot_file, model, &arch, &first);
  549. display_history_based_perf_models(gnuplot_file, model, &arch.type, &arch.devid, &arch.ncore, &first);
  550. return;
  551. }
  552. else
  553. {
  554. fprintf(stderr, "Invalid OpenCL device %d (last valid one is %d)\n", gpuid, STARPU_MAXOPENCLDEVS-1);
  555. exit(-1);
  556. }
  557. }
  558. fprintf(stderr, "Unknown architecture requested, aborting.\n");
  559. exit(-1);
  560. }
  561. }
  562. int main(int argc, char **argv)
  563. {
  564. int ret;
  565. struct starpu_perfmodel model = {};
  566. #if defined(_WIN32) && !defined(__CYGWIN__)
  567. WSADATA wsadata;
  568. WSAStartup(MAKEWORD(1,0), &wsadata);
  569. #endif
  570. parse_args(argc, argv);
  571. if (list)
  572. {
  573. ret = starpu_perfmodel_list(stdout);
  574. if (ret)
  575. {
  576. fprintf(stderr, "The performance model directory is invalid\n");
  577. return 1;
  578. }
  579. return 0;
  580. }
  581. /* Load the performance model associated to the symbol */
  582. ret = starpu_perfmodel_load_symbol(symbol, &model);
  583. if (ret == 1)
  584. {
  585. fprintf(stderr, "The performance model for the symbol <%s> could not be loaded\n", symbol);
  586. return 1;
  587. }
  588. /* If some FxT input was specified, we put the points on the graph */
  589. #ifdef STARPU_USE_FXT
  590. if (!no_fxt_file)
  591. {
  592. starpu_fxt_generate_trace(&options);
  593. snprintf(data_file_name, 256, "starpu_%s.data", symbol);
  594. FILE *data_file = fopen(data_file_name, "w+");
  595. STARPU_ASSERT(data_file);
  596. dump_data_file(data_file, &model);
  597. fclose(data_file);
  598. }
  599. #endif
  600. snprintf(gnuplot_file_name, 256, "starpu_%s.gp", symbol);
  601. snprintf(avg_file_name, 256, "starpu_%s_avg.data", symbol);
  602. FILE *gnuplot_file = fopen(gnuplot_file_name, "w+");
  603. STARPU_ASSERT(gnuplot_file);
  604. display_selected_models(gnuplot_file, &model);
  605. fclose(gnuplot_file);
  606. /* Retrieve the current mode of the gnuplot executable */
  607. struct stat sb;
  608. ret = stat(gnuplot_file_name, &sb);
  609. if (ret)
  610. {
  611. perror("stat");
  612. STARPU_ABORT();
  613. }
  614. /* Make the gnuplot scrit executable for the owner */
  615. ret = chmod(gnuplot_file_name, sb.st_mode|S_IXUSR);
  616. if (ret)
  617. {
  618. perror("chmod");
  619. STARPU_ABORT();
  620. }
  621. _STARPU_DISP("Gnuplot file <%s> generated\n", gnuplot_file_name);
  622. return 0;
  623. }