test_interfaces.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013,2017 Inria
  4. * Copyright (C) 2012-2015,2017 CNRS
  5. * Copyright (C) 2013,2015 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 <starpu.h>
  19. /* XXX Why cant we dereference a handle without this one ? */
  20. #include <core/sched_policy.h>
  21. #include <assert.h>
  22. #include "test_interfaces.h"
  23. #include "../../helper.h"
  24. /*
  25. * This is definitely note thread-safe.
  26. */
  27. static struct test_config *current_config;
  28. /* TODO :
  29. - OpenCL to OpenCL support
  30. */
  31. static char *
  32. enum_to_string(int exit_code)
  33. {
  34. switch (exit_code)
  35. {
  36. case SUCCESS:
  37. return "Success";
  38. case FAILURE:
  39. return "Failure";
  40. case UNTESTED:
  41. return "Untested";
  42. case TASK_CREATION_FAILURE:
  43. return "Task creation failed";
  44. case TASK_SUBMISSION_FAILURE:
  45. return "Task submission failed";
  46. default:
  47. assert(0);
  48. }
  49. }
  50. struct data_interface_test_summary
  51. {
  52. int success;
  53. /* Copy methods */
  54. #ifdef STARPU_USE_CPU
  55. int cpu_to_cpu;
  56. #endif
  57. #ifdef STARPU_USE_CUDA
  58. int cpu_to_cuda;
  59. int cuda_to_cuda;
  60. int cuda_to_cpu;
  61. int cpu_to_cuda_async;
  62. int cuda_to_cpu_async;
  63. int cuda_to_cuda_async;
  64. #endif
  65. #ifdef STARPU_USE_OPENCL
  66. int cpu_to_opencl;
  67. int opencl_to_cpu;
  68. int cpu_to_opencl_async;
  69. int opencl_to_cpu_async;
  70. #endif
  71. #ifdef STARPU_USE_MIC
  72. int cpu_to_mic;
  73. int mic_to_cpu;
  74. int cpu_to_mic_async;
  75. int mic_to_cpu_async;
  76. #endif
  77. /* Other stuff */
  78. int compare;
  79. #ifdef STARPU_USE_CPU
  80. int handle_to_pointer;
  81. #endif
  82. };
  83. void data_interface_test_summary_print(FILE *f,
  84. struct data_interface_test_summary *s)
  85. {
  86. if (!f)
  87. f = stderr;
  88. FPRINTF(f, "%s : %s\n",
  89. current_config->name, enum_to_string(s->success));
  90. FPRINTF(f, "Asynchronous :\n");
  91. #ifdef STARPU_USE_CUDA
  92. FPRINTF(f, "\tCPU -> CUDA : %s\n",
  93. enum_to_string(s->cpu_to_cuda_async));
  94. FPRINTF(f, "\tCUDA -> CUDA : %s\n",
  95. enum_to_string(s->cuda_to_cuda_async));
  96. FPRINTF(f, "\tCUDA -> CPU : %s\n",
  97. enum_to_string(s->cuda_to_cpu_async));
  98. #endif /* !STARPU_USE_CUDA */
  99. #ifdef STARPU_USE_OPENCL
  100. FPRINTF(f, "\tCPU -> OpenCl : %s\n",
  101. enum_to_string(s->cpu_to_opencl_async));
  102. FPRINTF(f, "\tOpenCl -> CPU : %s\n",
  103. enum_to_string(s->opencl_to_cpu_async));
  104. #endif /* !STARPU_USE_OPENCL */
  105. #ifdef STARPU_USE_MIC
  106. FPRINTF(f, "\tCPU -> MIC : %s\n",
  107. enum_to_string(s->cpu_to_mic_async));
  108. FPRINTF(f, "\tMIC -> CPU : %s\n",
  109. enum_to_string(s->mic_to_cpu_async));
  110. #endif
  111. FPRINTF(f, "Synchronous :\n");
  112. #ifdef STARPU_USE_CUDA
  113. FPRINTF(f, "\tCPU -> CUDA ; %s\n",
  114. enum_to_string(s->cpu_to_cuda));
  115. FPRINTF(f, "\tCUDA -> CUDA : %s\n",
  116. enum_to_string(s->cuda_to_cuda));
  117. FPRINTF(f, "\tCUDA -> CPU : %s\n",
  118. enum_to_string(s->cuda_to_cpu));
  119. #endif /* !STARPU_USE_CUDA */
  120. #ifdef STARPU_USE_OPENCL
  121. FPRINTF(f, "\tCPU -> OpenCl : %s\n",
  122. enum_to_string(s->cpu_to_opencl));
  123. FPRINTF(f, "\tOpenCl -> CPU : %s\n",
  124. enum_to_string(s->opencl_to_cpu));
  125. #endif /* !STARPU_USE_OPENCL */
  126. #ifdef STARPU_USE_MIC
  127. FPRINTF(f, "\tCPU -> MIC : %s\n",
  128. enum_to_string(s->cpu_to_mic));
  129. FPRINTF(f, "\tMIC -> CPU : %s\n",
  130. enum_to_string(s->mic_to_cpu));
  131. #endif
  132. #ifdef STARPU_USE_CPU
  133. FPRINTF(f, "CPU -> CPU : %s\n",
  134. enum_to_string(s->cpu_to_cpu));
  135. FPRINTF(f, "handle_to_pointer() : %s\n",
  136. enum_to_string(s->handle_to_pointer));
  137. #endif /* !STARPU_USE_CPU */
  138. FPRINTF(f, "compare() : %s\n",
  139. enum_to_string(s->compare));
  140. }
  141. int
  142. data_interface_test_summary_success(data_interface_test_summary *s)
  143. {
  144. return s->success;
  145. }
  146. enum operation
  147. {
  148. #ifdef STARPU_USE_CUDA
  149. CPU_TO_CUDA,
  150. CUDA_TO_CUDA,
  151. CUDA_TO_CPU,
  152. #endif /* !STARPU_USE_CUDA */
  153. #ifdef STARPU_USE_OPENCL
  154. CPU_TO_OPENCL,
  155. OPENCL_TO_CPU,
  156. #endif /* !STARPU_USE_OPENCL */
  157. #ifdef STARPU_USE_MIC
  158. CPU_TO_MIC,
  159. MIC_TO_CPU,
  160. #endif
  161. CPU_TO_CPU
  162. };
  163. static int*
  164. get_field(struct data_interface_test_summary *s, int async, enum operation op)
  165. {
  166. switch (op)
  167. {
  168. #ifdef STARPU_USE_CPU
  169. case CPU_TO_CPU:
  170. return &s->cpu_to_cpu;
  171. #endif
  172. #ifdef STARPU_USE_CUDA
  173. case CPU_TO_CUDA:
  174. return async?&s->cpu_to_cuda_async:&s->cpu_to_cuda;
  175. case CUDA_TO_CUDA:
  176. return async?&s->cuda_to_cuda_async:&s->cuda_to_cuda;
  177. case CUDA_TO_CPU:
  178. return async?&s->cuda_to_cpu_async:&s->cuda_to_cpu;
  179. #endif /* !STARPU_USE_CUDA */
  180. #ifdef STARPU_USE_OPENCL
  181. case CPU_TO_OPENCL:
  182. return async?&s->cpu_to_opencl_async:&s->cpu_to_opencl;
  183. case OPENCL_TO_CPU:
  184. return async?&s->opencl_to_cpu_async:&s->opencl_to_cpu;
  185. #endif /* !STARPU_USE_OPENCL */
  186. #ifdef STARPU_USE_MIC
  187. case CPU_TO_MIC:
  188. return async?&s->cpu_to_mic_async:&s->cpu_to_mic;
  189. case MIC_TO_CPU:
  190. return async?&s->mic_to_cpu_async:&s->mic_to_cpu;
  191. #endif
  192. default:
  193. STARPU_ABORT();
  194. }
  195. /* that instruction should never be reached */
  196. return NULL;
  197. }
  198. static void
  199. set_field(struct data_interface_test_summary *s, int async,
  200. enum operation op, int ret)
  201. {
  202. int *field = get_field(s, async, op);
  203. switch (ret)
  204. {
  205. case SUCCESS:
  206. *field = SUCCESS;
  207. break;
  208. case FAILURE:
  209. *field = FAILURE;
  210. s->success = FAILURE;
  211. break;
  212. case UNTESTED:
  213. *field = UNTESTED;
  214. break;
  215. case TASK_CREATION_FAILURE:
  216. *field = TASK_CREATION_FAILURE;
  217. break;
  218. case TASK_SUBMISSION_FAILURE:
  219. *field = TASK_SUBMISSION_FAILURE;
  220. break;
  221. default:
  222. STARPU_ABORT();
  223. }
  224. }
  225. static struct data_interface_test_summary summary =
  226. {
  227. #ifdef STARPU_USE_CPU
  228. .cpu_to_cpu = UNTESTED,
  229. .compare = UNTESTED,
  230. #endif
  231. #ifdef STARPU_USE_CUDA
  232. .cpu_to_cuda = UNTESTED,
  233. .cuda_to_cuda = UNTESTED,
  234. .cuda_to_cpu = UNTESTED,
  235. .cpu_to_cuda_async = UNTESTED,
  236. .cuda_to_cpu_async = UNTESTED,
  237. .cuda_to_cuda_async = UNTESTED,
  238. #endif
  239. #ifdef STARPU_USE_OPENCL
  240. .cpu_to_opencl = UNTESTED,
  241. .opencl_to_cpu = UNTESTED,
  242. .cpu_to_opencl_async = UNTESTED,
  243. .opencl_to_cpu_async = UNTESTED,
  244. #endif
  245. #ifdef STARPU_USE_MIC
  246. .cpu_to_mic = UNTESTED,
  247. .mic_to_cpu = UNTESTED,
  248. .cpu_to_mic_async = UNTESTED,
  249. .mic_to_cpu_async = UNTESTED,
  250. #endif
  251. #ifdef STARPU_USE_CPU
  252. .handle_to_pointer = UNTESTED,
  253. #endif
  254. .success = SUCCESS
  255. };
  256. /*
  257. * This variable has to be either -1 or 1.
  258. * The kernels should check that the ith value stored in the data interface is
  259. * equal to i, if factor == 1, or -i, if factor == -1.
  260. */
  261. static int factor = -1;
  262. /*
  263. * Creates a complete task, only knowing on what device it should be executed.
  264. * Note that the global variable <current_config> is heavily used here.
  265. * Arguments :
  266. * - taskp : a pointer to a valid task
  267. * - type : STARPU_{CPU,CUDA,OPENCL}_WORKER.
  268. * - id : -1 if you dont care about the device where the task will be
  269. * executed, as long as it has the right type.
  270. * >= 0 if you want to make sure the task will be executed on the
  271. * idth device that has the specified type.
  272. * Return values :
  273. * -ENODEV
  274. * 0 : success.
  275. */
  276. static int
  277. create_task(struct starpu_task **taskp, enum starpu_worker_archtype type, int id)
  278. {
  279. static int cpu_workers[STARPU_MAXCPUS];
  280. #ifdef STARPU_USE_CUDA
  281. static int cuda_workers[STARPU_MAXCUDADEVS];
  282. #endif
  283. #ifdef STARPU_USE_OPENCL
  284. static int opencl_workers[STARPU_MAXOPENCLDEVS];
  285. #endif
  286. #ifdef STARPU_USE_MIC
  287. static int mic_workers[STARPU_MAXMICDEVS];
  288. #endif
  289. static int n_cpus = -1;
  290. #ifdef STARPU_USE_CUDA
  291. static int n_cudas = -1;
  292. #endif
  293. #ifdef STARPU_USE_OPENCL
  294. static int n_opencls = -1;
  295. #endif
  296. #ifdef STARPU_USE_MIC
  297. static int n_mics = -1;
  298. #endif
  299. if (n_cpus == -1) /* First time here */
  300. {
  301. /* We do not check the return values of the calls to
  302. * starpu_worker_get_ids_by_type now, because it is simpler to
  303. * detect a problem in the switch that comes right after this
  304. * block of code. */
  305. n_cpus = starpu_worker_get_ids_by_type(STARPU_CPU_WORKER,
  306. cpu_workers,
  307. STARPU_MAXCPUS);
  308. #ifdef STARPU_USE_CUDA
  309. n_cudas = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
  310. cuda_workers,
  311. STARPU_MAXCUDADEVS);
  312. #endif
  313. #ifdef STARPU_USE_OPENCL
  314. n_opencls = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
  315. opencl_workers,
  316. STARPU_MAXOPENCLDEVS);
  317. #endif
  318. #ifdef STARPU_USE_MIC
  319. n_mics = starpu_worker_get_ids_by_type(STARPU_MIC_WORKER,
  320. mic_workers,
  321. STARPU_MAXMICDEVS);
  322. #endif
  323. }
  324. int workerid=0;
  325. static struct starpu_codelet cl;
  326. cl.nbuffers = 1;
  327. cl.modes[0] = STARPU_RW;
  328. switch (type)
  329. {
  330. case STARPU_CPU_WORKER:
  331. if (id != -1)
  332. {
  333. if (id >= n_cpus)
  334. {
  335. FPRINTF(stderr, "Not enough CPU workers\n");
  336. return -ENODEV;
  337. }
  338. workerid = *(cpu_workers + id);
  339. }
  340. cl.where = STARPU_CPU;
  341. cl.cpu_funcs[0] = current_config->cpu_func;
  342. break;
  343. #ifdef STARPU_USE_CUDA
  344. case STARPU_CUDA_WORKER:
  345. if (id != -1)
  346. {
  347. if (id >= n_cudas)
  348. {
  349. FPRINTF(stderr, "Not enough CUDA workers\n");
  350. return -ENODEV;
  351. }
  352. workerid = cuda_workers[id];
  353. }
  354. cl.where = STARPU_CUDA;
  355. cl.cuda_funcs[0] = current_config->cuda_func;
  356. break;
  357. #endif /* !STARPU_USE_CUDA */
  358. #ifdef STARPU_USE_OPENCL
  359. case STARPU_OPENCL_WORKER:
  360. if (id != -1)
  361. {
  362. if (id >= n_opencls)
  363. {
  364. FPRINTF(stderr, "Not enough OpenCL workers\n");
  365. return -ENODEV;
  366. }
  367. workerid = *(opencl_workers + id);
  368. }
  369. cl.where = STARPU_OPENCL;
  370. cl.opencl_funcs[0] = current_config->opencl_func;
  371. break;
  372. #endif /* ! STARPU_USE_OPENCL */
  373. #ifdef STARPU_USE_MIC
  374. case STARPU_MIC_WORKER:
  375. if (id != -1)
  376. {
  377. if (id >= n_mics)
  378. {
  379. FPRINTF(stderr, "Not enough MIC workers\n");
  380. return -ENODEV;
  381. }
  382. workerid = mic_workers[id];
  383. }
  384. cl.where = STARPU_MIC;
  385. cl.cpu_funcs_name[0] = current_config->cpu_func_name;
  386. break;
  387. #endif
  388. default:
  389. return -ENODEV;
  390. }
  391. struct starpu_task *task = starpu_task_create();
  392. task->synchronous = 1;
  393. task->cl = &cl;
  394. task->handles[0] = *current_config->handle;
  395. task->destroy = 0;
  396. if (id != -1)
  397. {
  398. task->execute_on_a_specific_worker = 1;
  399. task->workerid = workerid;
  400. }
  401. factor = -factor;
  402. task->cl_arg = &factor;
  403. task->cl_arg_size = sizeof(factor);
  404. *taskp = task;
  405. return 0;
  406. }
  407. /*
  408. * <device1>_to_<device2> functions.
  409. * They all create and submit a task that has to be executed on <device2>,
  410. * forcing a copy between <device1> and <device2>.
  411. * XXX : could we sometimes use starpu_task_insert() ? It seems hars because we
  412. * need to set the execute_on_a_specific_worker field...
  413. */
  414. #ifdef STARPU_USE_CUDA
  415. static enum exit_code
  416. ram_to_cuda(void)
  417. {
  418. int err;
  419. struct starpu_task *task;
  420. err = create_task(&task, STARPU_CUDA_WORKER, 0);
  421. if (err != 0)
  422. return TASK_CREATION_FAILURE;
  423. err = starpu_task_submit(task);
  424. if (err != 0)
  425. return TASK_SUBMISSION_FAILURE;
  426. FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
  427. return current_config->copy_failed;
  428. }
  429. #ifdef STARPU_HAVE_CUDA_MEMCPY_PEER
  430. static enum exit_code
  431. cuda_to_cuda(void)
  432. {
  433. int err;
  434. struct starpu_task *task;
  435. err = create_task(&task, STARPU_CUDA_WORKER, 1);
  436. if (err != 0)
  437. return TASK_CREATION_FAILURE;
  438. err = starpu_task_submit(task);
  439. if (err != 0)
  440. return TASK_SUBMISSION_FAILURE;
  441. FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
  442. return current_config->copy_failed;
  443. }
  444. #endif
  445. static enum exit_code
  446. cuda_to_ram(void)
  447. {
  448. int err;
  449. struct starpu_task *task;
  450. err = create_task(&task, STARPU_CPU_WORKER, -1);
  451. if (err != 0)
  452. return TASK_CREATION_FAILURE;
  453. err = starpu_task_submit(task);
  454. if (err != 0)
  455. return TASK_SUBMISSION_FAILURE;
  456. FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
  457. return current_config->copy_failed;
  458. }
  459. #endif /* !STARPU_USE_CUDA */
  460. #ifdef STARPU_USE_OPENCL
  461. static enum exit_code
  462. ram_to_opencl(void)
  463. {
  464. int err;
  465. struct starpu_task *task;
  466. err = create_task(&task, STARPU_OPENCL_WORKER, 0);
  467. if (err != 0)
  468. return TASK_CREATION_FAILURE;
  469. err = starpu_task_submit(task);
  470. if (err != 0)
  471. return TASK_SUBMISSION_FAILURE;
  472. FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
  473. return current_config->copy_failed;
  474. }
  475. static enum exit_code
  476. opencl_to_ram(void)
  477. {
  478. int err;
  479. struct starpu_task *task;
  480. err = create_task(&task, STARPU_CPU_WORKER, -1);
  481. if (err != 0)
  482. return TASK_CREATION_FAILURE;
  483. err = starpu_task_submit(task);
  484. if (err != 0)
  485. return TASK_SUBMISSION_FAILURE;
  486. FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
  487. return current_config->copy_failed;
  488. }
  489. #endif /* !STARPU_USE_OPENCL */
  490. #ifdef STARPU_USE_MIC
  491. static enum exit_code
  492. ram_to_mic()
  493. {
  494. int err;
  495. struct starpu_task *task;
  496. err = create_task(&task, STARPU_MIC_WORKER, 0);
  497. if (err != 0)
  498. return TASK_CREATION_FAILURE;
  499. err = starpu_task_submit(task);
  500. if (err != 0)
  501. return TASK_SUBMISSION_FAILURE;
  502. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  503. return current_config->copy_failed;
  504. }
  505. static enum exit_code
  506. mic_to_ram()
  507. {
  508. int err;
  509. struct starpu_task *task;
  510. err = create_task(&task, STARPU_CPU_WORKER, -1);
  511. if (err != 0)
  512. return TASK_CREATION_FAILURE;
  513. err = starpu_task_submit(task);
  514. if (err != 0)
  515. return TASK_SUBMISSION_FAILURE;
  516. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  517. return current_config->copy_failed;
  518. }
  519. #endif
  520. /* End of the <device1>_to_<device2> functions. */
  521. #ifdef STARPU_USE_CUDA
  522. static void
  523. run_cuda(int async)
  524. {
  525. /* RAM -> CUDA (-> CUDA) -> RAM */
  526. int err;
  527. err = ram_to_cuda();
  528. set_field(&summary, async, CPU_TO_CUDA, err);
  529. /* If this failed, there is no point in continuing. */
  530. if (err != SUCCESS)
  531. return;
  532. #ifdef STARPU_HAVE_CUDA_MEMCPY_PEER
  533. if (starpu_cuda_worker_get_count() >= 2)
  534. {
  535. err = cuda_to_cuda();
  536. set_field(&summary, async, CUDA_TO_CUDA, err);
  537. /* Even if cuda_to_cuda() failed, a valid copy is left on the first
  538. * cuda device, which means we can safely test cuda_to_ram() */
  539. }
  540. else
  541. {
  542. summary.cuda_to_cuda_async = UNTESTED;
  543. }
  544. #else
  545. summary.cuda_to_cuda_async = UNTESTED;
  546. #endif /* !STARPU_HAVE_CUDA_MEMCPY_PEER */
  547. #ifdef STARPU_USE_CPU
  548. err = cuda_to_ram();
  549. set_field(&summary, async, CUDA_TO_CPU, err);
  550. #endif /* !STARPU_USE_CPU */
  551. }
  552. #endif /* !STARPU_USE_CUDA */
  553. #ifdef STARPU_USE_OPENCL
  554. static void
  555. run_opencl(int async)
  556. {
  557. /* RAM -> OpenCL -> RAM */
  558. int err;
  559. err = ram_to_opencl();
  560. set_field(&summary, async, CPU_TO_OPENCL, err);
  561. if (err != SUCCESS)
  562. return;
  563. #ifdef STARPU_USE_CPU
  564. err = opencl_to_ram();
  565. set_field(&summary, async, OPENCL_TO_CPU, err);
  566. #endif /*!STARPU_USE_CPU */
  567. }
  568. #endif /* !STARPU_USE_OPENCL */
  569. #ifdef STARPU_USE_MIC
  570. static void
  571. run_mic(int async)
  572. {
  573. int err;
  574. err = ram_to_mic();
  575. set_field(&summary, async, CPU_TO_MIC, err);
  576. if (err != SUCCESS)
  577. return;
  578. #ifdef STARPU_USE_CPU
  579. err = mic_to_ram();
  580. set_field(&summary, async, MIC_TO_CPU, err);
  581. #endif
  582. }
  583. #endif /* STARPU_USE_PIC */
  584. #ifdef STARPU_USE_CPU
  585. /* Valid data should be in RAM before calling this function */
  586. static void
  587. ram_to_ram(void)
  588. {
  589. int err;
  590. struct starpu_task *task;
  591. starpu_data_handle_t src, dst;
  592. void *src_interface, *dst_interface;
  593. src = *current_config->handle;
  594. dst = *current_config->dummy_handle;
  595. /* We do not care about the nodes */
  596. src_interface = starpu_data_get_interface_on_node(src, STARPU_MAIN_RAM);
  597. dst_interface = starpu_data_get_interface_on_node(dst, STARPU_MAIN_RAM);
  598. if (src->ops->copy_methods->ram_to_ram)
  599. src->ops->copy_methods->ram_to_ram(src_interface, STARPU_MAIN_RAM, dst_interface, STARPU_MAIN_RAM);
  600. else
  601. src->ops->copy_methods->any_to_any(src_interface, STARPU_MAIN_RAM, dst_interface, STARPU_MAIN_RAM, NULL);
  602. err = create_task(&task, STARPU_CPU_WORKER, -1);
  603. if (err != 0)
  604. goto out;
  605. task->handles[0] = dst;
  606. err = starpu_task_submit(task);
  607. starpu_task_destroy(task);
  608. if (err != 0)
  609. {
  610. err = TASK_SUBMISSION_FAILURE;
  611. goto out;
  612. }
  613. FPRINTF(stderr, "[%s] : %d\n", __starpu_func__, current_config->copy_failed);
  614. err = current_config->copy_failed;
  615. out:
  616. set_field(&summary, 0, CPU_TO_CPU, err);
  617. }
  618. #endif /* !STARPU_USE_CPU */
  619. static void
  620. run_async(void)
  621. {
  622. int async = starpu_asynchronous_copy_disabled();
  623. if (async == 1)
  624. {
  625. FPRINTF(stderr, "Asynchronous copies have been disabled\n");
  626. return;
  627. }
  628. #ifdef STARPU_USE_CUDA
  629. run_cuda(1);
  630. #endif /* !STARPU_USE_CUDA */
  631. #ifdef STARPU_USE_OPENCL
  632. run_opencl(1);
  633. #endif /* !STARPU_USE_OPENCL */
  634. #ifdef STARPU_USE_MIC
  635. run_mic(1);
  636. #endif
  637. }
  638. static void
  639. run_sync(void)
  640. {
  641. starpu_data_handle_t handle = *current_config->handle;
  642. struct starpu_data_copy_methods new_copy_methods;
  643. struct starpu_data_copy_methods *old_copy_methods;
  644. old_copy_methods = (struct starpu_data_copy_methods *) handle->ops->copy_methods;
  645. memcpy(&new_copy_methods,
  646. old_copy_methods,
  647. sizeof(struct starpu_data_copy_methods));
  648. #ifdef STARPU_USE_CUDA
  649. new_copy_methods.ram_to_cuda_async = NULL;
  650. new_copy_methods.cuda_to_cuda_async = NULL;
  651. new_copy_methods.cuda_to_ram_async = NULL;
  652. #endif /* !STARPU_USE_CUDA */
  653. #ifdef STARPU_USE_OPENCL
  654. new_copy_methods.ram_to_opencl_async = NULL;
  655. new_copy_methods.opencl_to_ram_async = NULL;
  656. #endif /* !STARPU_USE_OPENCL */
  657. #ifdef STARPU_USE_MIC
  658. new_copy_methods.ram_to_mic_async = NULL;
  659. new_copy_methods.mic_to_ram_async = NULL;
  660. #endif
  661. handle->ops->copy_methods = &new_copy_methods;
  662. #ifdef STARPU_USE_CUDA
  663. run_cuda(0);
  664. #endif /* !STARPU_USE_CUDA */
  665. #ifdef STARPU_USE_OPENCL
  666. run_opencl(0);
  667. #endif /* !STARPU_USE_OPENCL */
  668. #ifdef STARPU_USE_MIC
  669. run_mic(0);
  670. #endif
  671. handle->ops->copy_methods = old_copy_methods;
  672. }
  673. static void
  674. compare(void)
  675. {
  676. int err;
  677. void *interface_a, *interface_b;
  678. starpu_data_handle_t handle, dummy_handle;
  679. handle = *current_config->handle;
  680. dummy_handle = *current_config->dummy_handle;
  681. interface_a = starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  682. interface_b = starpu_data_get_interface_on_node(dummy_handle, STARPU_MAIN_RAM);
  683. err = handle->ops->compare(interface_a, interface_b);
  684. if (err == 0)
  685. {
  686. summary.compare = FAILURE;
  687. summary.success = FAILURE;
  688. }
  689. else
  690. {
  691. summary.compare = SUCCESS;
  692. }
  693. }
  694. #ifdef STARPU_USE_CPU
  695. static void
  696. handle_to_pointer(void)
  697. {
  698. void *ptr;
  699. unsigned int node;
  700. unsigned int tests = 0;
  701. starpu_data_handle_t handle;
  702. handle = *current_config->handle;
  703. if (!handle->ops->handle_to_pointer)
  704. return;
  705. for (node = 0; node < STARPU_MAXNODES; node++)
  706. {
  707. if (starpu_node_get_kind(node) != STARPU_CPU_RAM)
  708. continue;
  709. if (!starpu_data_test_if_allocated_on_node(handle, node))
  710. continue;
  711. ptr = handle->ops->handle_to_pointer(handle, node);
  712. if (starpu_data_lookup(ptr) != handle)
  713. {
  714. summary.handle_to_pointer = FAILURE;
  715. return;
  716. }
  717. tests++;
  718. }
  719. if (tests > 0)
  720. summary.handle_to_pointer = SUCCESS;
  721. }
  722. #endif /* !STARPU_USE_CPU */
  723. static int
  724. load_conf(struct test_config *config)
  725. {
  726. if (!config ||
  727. #ifdef STARPU_USE_CPU
  728. !config->cpu_func ||
  729. !config->dummy_handle ||
  730. #endif
  731. #ifdef STARPU_USE_CUDA
  732. !config->cuda_func ||
  733. #endif
  734. #ifdef STARPU_USE_OPENCL
  735. !config->opencl_func ||
  736. #endif
  737. #ifdef STARPU_USE_MIC
  738. !config->cpu_func_name ||
  739. #endif
  740. !config->handle)
  741. {
  742. return 1;
  743. }
  744. current_config = config;
  745. return 0;
  746. }
  747. data_interface_test_summary*
  748. run_tests(struct test_config *conf)
  749. {
  750. if (load_conf(conf) == 1)
  751. {
  752. FPRINTF(stderr, "Failed to load conf.\n");
  753. return NULL;
  754. }
  755. run_async();
  756. run_sync();
  757. #ifdef STARPU_USE_CPU
  758. ram_to_ram();
  759. compare();
  760. handle_to_pointer();
  761. #endif
  762. return &summary;
  763. }