test_interfaces.c 20 KB

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