starpu_perfmodel_plot.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2014 Université de Bordeaux 1
  4. * Copyright (C) 2011, 2012, 2013 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. #ifdef __MINGW32__
  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 void print_comma(FILE *gnuplot_file, int *first)
  150. {
  151. if (*first)
  152. {
  153. *first = 0;
  154. }
  155. else
  156. {
  157. fprintf(gnuplot_file, ",\\\n\t");
  158. }
  159. }
  160. static void display_perf_model(FILE *gnuplot_file, struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, int *first, unsigned nimpl)
  161. {
  162. char arch_name[256];
  163. starpu_perfmodel_get_arch_name(arch, arch_name, 256, nimpl);
  164. struct starpu_perfmodel_per_arch *arch_model =
  165. &model->per_arch[arch->type][arch->devid][arch->ncore][nimpl];
  166. if (arch_model->regression.valid || arch_model->regression.nl_valid)
  167. fprintf(stderr,"Arch: %s\n", arch_name);
  168. #ifdef STARPU_USE_FXT
  169. if (!gflops && !no_fxt_file && archtype_is_found[arch->type][arch->devid][arch->ncore] && nimpl == 0)
  170. {
  171. print_comma(gnuplot_file, first);
  172. 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);
  173. }
  174. #endif
  175. /* Only display the regression model if we could actually build a model */
  176. if (!gflops && arch_model->regression.valid && !arch_model->regression.nl_valid)
  177. {
  178. print_comma(gnuplot_file, first);
  179. fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
  180. fprintf(stderr, "\t\talpha = %e\n", arch_model->regression.alpha * 0.001);
  181. fprintf(stderr, "\t\tbeta = %e\n", arch_model->regression.beta);
  182. fprintf(gnuplot_file, "0.001 * %f * x ** %f title \"Linear Regression %s\"",
  183. arch_model->regression.alpha, arch_model->regression.beta, arch_name);
  184. }
  185. if (!gflops && arch_model->regression.nl_valid)
  186. {
  187. print_comma(gnuplot_file, first);
  188. fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
  189. fprintf(stderr, "\t\ta = %e\n", arch_model->regression.a * 0.001);
  190. fprintf(stderr, "\t\tb = %e\n", arch_model->regression.b);
  191. fprintf(stderr, "\t\tc = %e\n", arch_model->regression.c * 0.001);
  192. fprintf(gnuplot_file, "0.001 * %f * x ** %f + 0.001 * %f title \"Non-Linear Regression %s\"",
  193. arch_model->regression.a, arch_model->regression.b, arch_model->regression.c, arch_name);
  194. }
  195. }
  196. 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)
  197. {
  198. char *command;
  199. FILE *datafile;
  200. struct starpu_perfmodel_history_list *ptr;
  201. char arch_name[32];
  202. int col;
  203. size_t len;
  204. unsigned long last, minimum = 0;
  205. len = 10 + strlen(avg_file_name) + 1;
  206. command = (char *) malloc(len);
  207. datafile = fopen(avg_file_name, "w");
  208. free(command);
  209. col = 2;
  210. unsigned implid;
  211. unsigned archmin, archmax, devmin, devmax, coremin, coremax;
  212. if(type != NULL)
  213. {
  214. archmin = *type;
  215. archmax = *type +1;
  216. if(devid != NULL)
  217. {
  218. devmin = *devid;
  219. devmax = *devid +1;
  220. if(ncore != NULL)
  221. {
  222. coremin = *ncore;
  223. coremax = *ncore +1;
  224. }
  225. else
  226. {
  227. coremin = 0;
  228. coremax = 0;
  229. }
  230. }
  231. else
  232. {
  233. devmin = 0;
  234. devmax = 0;
  235. coremin = 0;
  236. coremax = 0;
  237. }
  238. }
  239. else
  240. {
  241. archmin = 0;
  242. archmax = STARPU_NARCH;
  243. devmin = 0;
  244. devmax = 0;
  245. coremin = 0;
  246. coremax = 0;
  247. }
  248. struct starpu_perfmodel_arch arch;
  249. unsigned archtype, dev, core;
  250. for (archtype = archmin; archtype < archmax; archtype++)
  251. {
  252. arch.type = archtype;
  253. if(model->per_arch[archtype]!=NULL)
  254. {
  255. for(dev = devmin; model->per_arch[archtype][dev] != NULL && (devmax == 0 || dev < devmax);dev++)
  256. {
  257. arch.devid = dev;
  258. for(core = coremin; model->per_arch[archtype][dev][core] != NULL && (coremax == 0 || core < coremax); core++)
  259. {
  260. arch.ncore = core;
  261. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  262. {
  263. struct starpu_perfmodel_per_arch *arch_model = &model->per_arch[archtype][dev][core][implid];
  264. starpu_perfmodel_get_arch_name(&arch, arch_name, 32, implid);
  265. //ptrs[arch-arch1][implid] = ptr[arch-arch1][implid] = arch_model->list;
  266. if (arch_model->list)
  267. {
  268. print_comma(gnuplot_file, first);
  269. fprintf(gnuplot_file, "\"%s\" using 1:%d:%d with errorlines title \"Average %s\"", avg_file_name, col, col+1, arch_name);
  270. col += 2;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }
  277. /* Dump entries in size order */
  278. while (1)
  279. {
  280. last = minimum;
  281. minimum = ULONG_MAX;
  282. /* Get the next minimum */
  283. for (archtype = archmin; archtype < archmax; archtype++)
  284. {
  285. if(model->per_arch[archtype]!=NULL)
  286. {
  287. for(dev = devmin; model->per_arch[archtype][dev] != NULL && (devmax == 0 || dev < devmax);dev++)
  288. {
  289. for(core = coremin; model->per_arch[archtype][dev][core] != NULL && (coremax == 0 || core < coremax); core++)
  290. {
  291. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  292. {
  293. struct starpu_perfmodel_per_arch *arch_model = &model->per_arch[archtype][dev][core][implid];
  294. for (ptr = arch_model->list; ptr; ptr = ptr->next)
  295. {
  296. unsigned long size = ptr->entry->size;
  297. if (size > last && size < minimum)
  298. minimum = size;
  299. }
  300. }
  301. }
  302. }
  303. }
  304. }
  305. if (minimum == ULONG_MAX)
  306. break;
  307. fprintf(stderr, "%lu ", minimum);
  308. fprintf(datafile, "%-15lu ", minimum);
  309. for (archtype = archmin; archtype < archmax; archtype++)
  310. if(model->per_arch[archtype]!=NULL)
  311. for(dev = devmin; model->per_arch[archtype][dev] != NULL && (devmax == 0 || dev < devmax);dev++)
  312. for(core = coremin; model->per_arch[archtype][dev][core] != NULL && (coremax == 0 || core < coremax); core++)
  313. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  314. {
  315. struct starpu_perfmodel_per_arch *arch_model = &model->per_arch[archtype][dev][core][implid];
  316. for (ptr = arch_model->list; ptr; ptr = ptr->next)
  317. {
  318. struct starpu_perfmodel_history_entry *entry = ptr->entry;
  319. if (entry->size == minimum)
  320. {
  321. if (gflops)
  322. fprintf(datafile, "\t%-15le\t%-15le", entry->flops / (entry->mean * 1000),
  323. entry->flops / ((entry->mean + entry->deviation) * 1000) -
  324. entry->flops / (entry->mean * 1000)
  325. );
  326. else
  327. fprintf(datafile, "\t%-15le\t%-15le", 0.001*entry->mean, 0.001*entry->deviation);
  328. break;
  329. }
  330. }
  331. if (!ptr && arch_model->list)
  332. /* No value for this arch. */
  333. fprintf(datafile, "\t\"\"\t\"\"");
  334. }
  335. fprintf(datafile, "\n");
  336. }
  337. fprintf(stderr, "\n");
  338. fclose(datafile);
  339. }
  340. static void display_selected_arch_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, int *first)
  341. {
  342. unsigned implid;
  343. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  344. display_perf_model(gnuplot_file, model, arch, first, implid);
  345. }
  346. static void display_selected_device_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, enum starpu_worker_archtype archtype, int devid, int *first)
  347. {
  348. unsigned ncore;
  349. struct starpu_perfmodel_arch arch;
  350. arch.type = archtype;
  351. arch.devid = devid;
  352. for(ncore=0; model->per_arch[archtype][devid][ncore] != NULL; ncore++)
  353. {
  354. arch.ncore = ncore;
  355. display_selected_arch_perf_models(gnuplot_file,model,&arch,first);
  356. }
  357. }
  358. static void display_selected_archtype_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, enum starpu_worker_archtype archtype, int *first)
  359. {
  360. unsigned devid;
  361. for(devid=0; model->per_arch[archtype][devid] != NULL; devid++)
  362. display_selected_device_perf_models(gnuplot_file,model,archtype,devid,first);
  363. }
  364. static void display_all_perf_models(FILE *gnuplot_file, struct starpu_perfmodel *model, int *first)
  365. {
  366. unsigned archtype;
  367. for(archtype = 0; archtype < STARPU_NARCH; archtype++)
  368. display_selected_archtype_perf_models(gnuplot_file,model,archtype,first);
  369. }
  370. #ifdef STARPU_USE_FXT
  371. static int ** init_archtype_is_found_per_arch(int maxdevid, unsigned* maxncore_table)
  372. {
  373. int devid, ncore;
  374. int ** archtype_is_found_per_arch = malloc(sizeof(*archtype_is_found_per_arch)*(maxdevid+1));
  375. archtype_is_found_per_arch[maxdevid] = NULL;
  376. for(devid=0; devid<maxdevid; devid++)
  377. {
  378. int maxncore;
  379. if(maxncore_table != NULL)
  380. maxncore = maxncore_table[devid];
  381. else
  382. maxncore = 1;
  383. archtype_is_found_per_arch[devid] = malloc(sizeof(*archtype_is_found_per_arch[devid])*(maxncore+1));
  384. archtype_is_found_per_arch[devid][maxncore] = 0;
  385. for(ncore=0; ncore<maxncore; ncore++)
  386. archtype_is_found_per_arch[devid][ncore] = 0;
  387. }
  388. return archtype_is_found_per_arch;
  389. }
  390. static void init_archtype_is_found(struct starpu_perfmodel *model)
  391. {
  392. unsigned archtype, devid, ndevice, ncore, *maxncore;
  393. for(archtype = 0; archtype < STARPU_NARCH; archtype++)
  394. {
  395. for(devid=0; model->per_arch[archtype][devid] != NULL; devid++)
  396. ;
  397. ndevice = devid;
  398. if(ndevice != 0)
  399. {
  400. maxncore = malloc(sizeof(*maxncore)*ndevice);
  401. for(devid=0; devid < ndevice; devid++)
  402. {
  403. for(ncore=0; model->per_arch[archtype][devid][ncore] != NULL; ncore++)
  404. ;
  405. maxncore[devid] = ncore;
  406. }
  407. }
  408. else
  409. {
  410. maxncore = NULL;
  411. }
  412. archtype_is_found[archtype] = init_archtype_is_found_per_arch(ndevice,maxncore);
  413. if(maxncore != NULL)
  414. free(maxncore);
  415. }
  416. }
  417. static void dump_data_file(FILE *data_file, struct starpu_perfmodel *model)
  418. {
  419. init_archtype_is_found(model);
  420. int i;
  421. for (i = 0; i < options.dumped_codelets_count; i++)
  422. {
  423. /* Dump only if the symbol matches user's request */
  424. if (strncmp(dumped_codelets[i].symbol, symbol, (FXT_MAX_PARAMS - 4)*sizeof(unsigned long)-1) == 0)
  425. {
  426. struct starpu_perfmodel_arch* arch = &dumped_codelets[i].arch;
  427. archtype_is_found[arch->type][arch->devid][arch->ncore] = 1;
  428. size_t size = dumped_codelets[i].size;
  429. float time = dumped_codelets[i].time;
  430. fprintf(data_file, "%d_%d_%d %f %f\n", arch->type, arch->devid, arch->ncore, (float)size, time);
  431. }
  432. }
  433. }
  434. #endif
  435. static void display_selected_models(FILE *gnuplot_file, struct starpu_perfmodel *model)
  436. {
  437. fprintf(gnuplot_file, "#!/usr/bin/gnuplot -persist\n");
  438. fprintf(gnuplot_file, "\n");
  439. fprintf(gnuplot_file, "set term postscript eps enhanced color\n");
  440. fprintf(gnuplot_file, "set output \"starpu_%s.eps\"\n", symbol);
  441. fprintf(gnuplot_file, "set title \"Model for codelet %s\"\n", symbol);
  442. fprintf(gnuplot_file, "set xlabel \"Total data size\"\n");
  443. if (gflops)
  444. fprintf(gnuplot_file, "set ylabel \"GFlops\"\n");
  445. else
  446. fprintf(gnuplot_file, "set ylabel \"Time (ms)\"\n");
  447. fprintf(gnuplot_file, "\n");
  448. fprintf(gnuplot_file, "set key top left\n");
  449. fprintf(gnuplot_file, "set logscale x\n");
  450. fprintf(gnuplot_file, "set logscale y\n");
  451. fprintf(gnuplot_file, "\n");
  452. /* If no input data is given to gnuplot, we at least need to specify an
  453. * arbitrary range. */
  454. if (no_fxt_file)
  455. fprintf(gnuplot_file, "set xrange [1:10**9]\n\n");
  456. int first = 1;
  457. fprintf(gnuplot_file, "plot\t");
  458. struct starpu_perfmodel_arch arch;
  459. struct _starpu_machine_config *conf = _starpu_get_machine_config();
  460. if (archname == NULL)
  461. {
  462. /* display all architectures */
  463. display_all_perf_models(gnuplot_file, model, &first);
  464. display_history_based_perf_models(gnuplot_file, model, NULL, NULL, NULL, &first);
  465. }
  466. else
  467. {
  468. if (strcmp(archname, "cpu") == 0)
  469. {
  470. arch.type = STARPU_CPU_WORKER;
  471. arch.devid = 1;
  472. arch.ncore = 0;
  473. display_selected_arch_perf_models(gnuplot_file, model, &arch, &first);
  474. display_history_based_perf_models(gnuplot_file, model, &arch.type, &arch.devid, &arch.ncore, &first);
  475. return;
  476. }
  477. unsigned k;
  478. if (sscanf(archname, "cpu:%u", &k) == 1)
  479. {
  480. /* For combined CPU workers */
  481. if ((k < 1) || (k > conf->topology.ncpus))
  482. {
  483. fprintf(stderr, "Invalid CPU size\n");
  484. exit(-1);
  485. }
  486. arch.type = STARPU_CPU_WORKER;
  487. arch.devid = 1;
  488. arch.ncore = k - 1;
  489. display_selected_arch_perf_models(gnuplot_file, model, &arch, &first);
  490. display_history_based_perf_models(gnuplot_file, model, &arch.type, &arch.devid, &arch.ncore, &first);
  491. return;
  492. }
  493. if (strcmp(archname, "cuda") == 0)
  494. {
  495. unsigned archtype = STARPU_CUDA_WORKER;
  496. display_selected_archtype_perf_models(gnuplot_file, model, archtype, &first);
  497. display_history_based_perf_models(gnuplot_file, model, &archtype, NULL, NULL, &first);
  498. return;
  499. }
  500. /* There must be a cleaner way ! */
  501. unsigned gpuid;
  502. int nmatched;
  503. nmatched = sscanf(archname, "cuda_%u", &gpuid);
  504. if (nmatched == 1)
  505. {
  506. if (gpuid < conf->topology.ncudagpus)
  507. {
  508. arch.type = STARPU_CUDA_WORKER;
  509. arch.devid = gpuid;
  510. arch.ncore = 0;
  511. display_selected_arch_perf_models(gnuplot_file, model, &arch, &first);
  512. display_history_based_perf_models(gnuplot_file, model, &arch.type, &arch.devid, &arch.ncore, &first);
  513. return;
  514. }
  515. else
  516. {
  517. fprintf(stderr, "Invalid CUDA device %d (last valid one is %d)\n", gpuid, STARPU_MAXCUDADEVS-1);
  518. exit(-1);
  519. }
  520. }
  521. if (strcmp(archname, "opencl") == 0)
  522. {
  523. unsigned archtype = STARPU_OPENCL_WORKER;
  524. display_selected_archtype_perf_models(gnuplot_file, model, archtype, &first);
  525. display_history_based_perf_models(gnuplot_file, model, &archtype, NULL, NULL, &first);
  526. return;
  527. }
  528. /* There must be a cleaner way ! */
  529. nmatched = sscanf(archname, "opencl_%u", &gpuid);
  530. if (nmatched == 1)
  531. {
  532. if (gpuid < conf->topology.nopenclgpus)
  533. {
  534. arch.type = STARPU_OPENCL_WORKER;
  535. arch.devid = gpuid;
  536. arch.ncore = 0;
  537. display_selected_arch_perf_models(gnuplot_file, model, &arch, &first);
  538. display_history_based_perf_models(gnuplot_file, model, &arch.type, &arch.devid, &arch.ncore, &first);
  539. return;
  540. }
  541. else
  542. {
  543. fprintf(stderr, "Invalid OpenCL device %d (last valid one is %d)\n", gpuid, STARPU_MAXOPENCLDEVS-1);
  544. exit(-1);
  545. }
  546. }
  547. fprintf(stderr, "Unknown architecture requested, aborting.\n");
  548. exit(-1);
  549. }
  550. }
  551. int main(int argc, char **argv)
  552. {
  553. int ret;
  554. struct starpu_perfmodel model = {};
  555. #ifdef __MINGW32__
  556. WSADATA wsadata;
  557. WSAStartup(MAKEWORD(1,0), &wsadata);
  558. #endif
  559. parse_args(argc, argv);
  560. if (list)
  561. {
  562. ret = starpu_perfmodel_list(stdout);
  563. if (ret)
  564. {
  565. fprintf(stderr, "The performance model directory is invalid\n");
  566. return 1;
  567. }
  568. return 0;
  569. }
  570. /* Load the performance model associated to the symbol */
  571. ret = starpu_perfmodel_load_symbol(symbol, &model);
  572. if (ret == 1)
  573. {
  574. fprintf(stderr, "The performance model for the symbol <%s> could not be loaded\n", symbol);
  575. return 1;
  576. }
  577. /* If some FxT input was specified, we put the points on the graph */
  578. #ifdef STARPU_USE_FXT
  579. if (!no_fxt_file)
  580. {
  581. starpu_fxt_generate_trace(&options);
  582. snprintf(data_file_name, 256, "starpu_%s.data", symbol);
  583. FILE *data_file = fopen(data_file_name, "w+");
  584. STARPU_ASSERT(data_file);
  585. dump_data_file(data_file, &model);
  586. fclose(data_file);
  587. }
  588. #endif
  589. snprintf(gnuplot_file_name, 256, "starpu_%s.gp", symbol);
  590. snprintf(avg_file_name, 256, "starpu_%s_avg.data", symbol);
  591. FILE *gnuplot_file = fopen(gnuplot_file_name, "w+");
  592. STARPU_ASSERT(gnuplot_file);
  593. display_selected_models(gnuplot_file, &model);
  594. fclose(gnuplot_file);
  595. /* Retrieve the current mode of the gnuplot executable */
  596. struct stat sb;
  597. ret = stat(gnuplot_file_name, &sb);
  598. if (ret)
  599. {
  600. perror("stat");
  601. STARPU_ABORT();
  602. }
  603. /* Make the gnuplot scrit executable for the owner */
  604. ret = chmod(gnuplot_file_name, sb.st_mode|S_IXUSR);
  605. if (ret)
  606. {
  607. perror("chmod");
  608. STARPU_ABORT();
  609. }
  610. _STARPU_DISP("Gnuplot file <%s> generated\n", gnuplot_file_name);
  611. return 0;
  612. }