test_interfaces.c 19 KB

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