test_interfaces.c 19 KB

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