test_interfaces.c 17 KB

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