test_interfaces.c 16 KB

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