test_interfaces.c 16 KB

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