test_interfaces.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. }
  182. static void
  183. set_field(struct data_interface_test_summary *s, int async,
  184. enum operation op, int ret)
  185. {
  186. int *field = get_field(s, async, op);
  187. switch (ret)
  188. {
  189. case SUCCESS:
  190. *field = SUCCESS;
  191. break;
  192. case FAILURE:
  193. *field = FAILURE;
  194. s->success = FAILURE;
  195. break;
  196. case UNTESTED:
  197. *field = UNTESTED;
  198. break;
  199. case TASK_CREATION_FAILURE:
  200. *field = TASK_CREATION_FAILURE;
  201. break;
  202. case TASK_SUBMISSION_FAILURE:
  203. *field = TASK_SUBMISSION_FAILURE;
  204. break;
  205. default:
  206. STARPU_ASSERT(0);
  207. }
  208. }
  209. static struct data_interface_test_summary summary =
  210. {
  211. #ifdef STARPU_USE_CPU
  212. .cpu_to_cpu = UNTESTED,
  213. .compare = UNTESTED,
  214. #endif
  215. #ifdef STARPU_USE_CUDA
  216. .cpu_to_cuda = UNTESTED,
  217. .cuda_to_cuda = UNTESTED,
  218. .cuda_to_cpu = UNTESTED,
  219. .cpu_to_cuda_async = UNTESTED,
  220. .cuda_to_cpu_async = UNTESTED,
  221. .cuda_to_cuda_async = UNTESTED,
  222. #endif
  223. #ifdef STARPU_USE_OPENCL
  224. .cpu_to_opencl = UNTESTED,
  225. .opencl_to_cpu = UNTESTED,
  226. .cpu_to_opencl_async = UNTESTED,
  227. .opencl_to_cpu_async = UNTESTED,
  228. #endif
  229. #ifdef STARPU_USE_CPU
  230. .handle_to_pointer = UNTESTED,
  231. #endif
  232. .success = SUCCESS
  233. };
  234. /*
  235. * This variable has to be either -1 or 1.
  236. * The kernels should check that the ith value stored in the data interface is
  237. * equal to i, if factor == 1, or -i, if factor == -1.
  238. */
  239. static int factor = -1;
  240. /*
  241. * Creates a complete task, only knowing on what device it should be executed.
  242. * Note that the global variable <current_config> is heavily used here.
  243. * Arguments :
  244. * - taskp : a pointer to a valid task
  245. * - type : STARPU_{CPU,CUDA,OPENCL}_WORKER. Gordon is not supported.
  246. * - id : -1 if you dont care about the device where the task will be
  247. * executed, as long as it has the right type.
  248. * >= 0 if you want to make sure the task will be executed on the
  249. * idth device that has the specified type.
  250. * Return values :
  251. * -ENODEV
  252. * 0 : success.
  253. */
  254. static int
  255. create_task(struct starpu_task **taskp, enum starpu_archtype type, int id)
  256. {
  257. static int cpu_workers[STARPU_MAXCPUS];
  258. #ifdef STARPU_USE_CUDA
  259. static int cuda_workers[STARPU_MAXCUDADEVS];
  260. #endif
  261. #ifdef STARPU_USE_OPENCL
  262. static int opencl_workers[STARPU_MAXOPENCLDEVS];
  263. #endif
  264. static int n_cpus = -1;
  265. #ifdef STARPU_USE_CUDA
  266. static int n_cudas = -1;
  267. #endif
  268. #ifdef STARPU_USE_OPENCL
  269. static int n_opencls = -1;
  270. #endif
  271. if (n_cpus == -1) /* First time here */
  272. {
  273. /* XXX Dont check them all at once. */
  274. /* XXX Error checking */
  275. n_cpus = starpu_worker_get_ids_by_type(STARPU_CPU_WORKER,
  276. cpu_workers,
  277. STARPU_MAXCPUS);
  278. #ifdef STARPU_USE_CUDA
  279. n_cudas = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
  280. cuda_workers,
  281. STARPU_MAXCUDADEVS);
  282. #endif
  283. #ifdef STARPU_USE_OPENCL
  284. n_opencls = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
  285. opencl_workers,
  286. STARPU_MAXOPENCLDEVS);
  287. #endif
  288. }
  289. int workerid=0;
  290. static struct starpu_codelet cl;
  291. cl.nbuffers = 1;
  292. cl.modes[0] = STARPU_RW;
  293. switch (type)
  294. {
  295. case STARPU_CPU_WORKER:
  296. if (id != -1)
  297. {
  298. if (id >= n_cpus)
  299. {
  300. FPRINTF(stderr, "Not enough CPU workers\n");
  301. return -ENODEV;
  302. }
  303. workerid = *(cpu_workers + id);
  304. }
  305. cl.where = STARPU_CPU;
  306. cl.cpu_funcs[0] = current_config->cpu_func;
  307. break;
  308. #ifdef STARPU_USE_CUDA
  309. case STARPU_CUDA_WORKER:
  310. if (id != -1)
  311. {
  312. if (id >= n_cudas)
  313. {
  314. FPRINTF(stderr, "Not enough CUDA workers\n");
  315. return -ENODEV;
  316. }
  317. workerid = cuda_workers[id];
  318. }
  319. cl.where = STARPU_CUDA;
  320. cl.cuda_funcs[0] = current_config->cuda_func;
  321. break;
  322. #endif /* !STARPU_USE_CUDA */
  323. #ifdef STARPU_USE_OPENCL
  324. case STARPU_OPENCL_WORKER:
  325. if (id != -1)
  326. {
  327. if (id >= n_opencls)
  328. {
  329. FPRINTF(stderr, "Not enough OpenCL workers\n");
  330. return -ENODEV;
  331. }
  332. workerid = *(opencl_workers + id);
  333. }
  334. cl.where = STARPU_OPENCL;
  335. cl.opencl_funcs[0] = current_config->opencl_func;
  336. break;
  337. #endif /* ! STARPU_USE_OPENCL */
  338. case STARPU_GORDON_WORKER: /* Not supported */
  339. default:
  340. return -ENODEV;
  341. }
  342. struct starpu_task *task = starpu_task_create();
  343. task->synchronous = 1;
  344. task->cl = &cl;
  345. task->handles[0] = *current_config->handle;
  346. task->destroy = 0;
  347. if (id != -1)
  348. {
  349. task->execute_on_a_specific_worker = 1;
  350. task->workerid = workerid;
  351. }
  352. factor = -factor;
  353. task->cl_arg = &factor;
  354. task->cl_arg_size = sizeof(&factor);
  355. *taskp = task;
  356. return 0;
  357. }
  358. /*
  359. * <device1>_to_<device2> functions.
  360. * They all create and submit a task that has to be executed on <device2>,
  361. * forcing a copy between <device1> and <device2>.
  362. * XXX : could we sometimes use starp_insert_task() ? It seems hars because we
  363. * need to set the execute_on_a_specific_worker field...
  364. */
  365. #ifdef STARPU_USE_CUDA
  366. static enum exit_code
  367. ram_to_cuda(void)
  368. {
  369. int err;
  370. struct starpu_task *task;
  371. err = create_task(&task, STARPU_CUDA_WORKER, 0);
  372. if (err != 0)
  373. return TASK_CREATION_FAILURE;
  374. err = starpu_task_submit(task);
  375. if (err != 0)
  376. return TASK_SUBMISSION_FAILURE;
  377. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  378. return current_config->copy_failed;
  379. }
  380. #ifdef HAVE_CUDA_MEMCPY_PEER
  381. static enum exit_code
  382. cuda_to_cuda(void)
  383. {
  384. int err;
  385. struct starpu_task *task;
  386. err = create_task(&task, STARPU_CUDA_WORKER, 1);
  387. if (err != 0)
  388. return TASK_CREATION_FAILURE;
  389. err = starpu_task_submit(task);
  390. if (err != 0)
  391. return TASK_SUBMISSION_FAILURE;
  392. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  393. return current_config->copy_failed;
  394. }
  395. #endif
  396. static enum exit_code
  397. cuda_to_ram(void)
  398. {
  399. int err;
  400. struct starpu_task *task;
  401. err = create_task(&task, STARPU_CPU_WORKER, -1);
  402. if (err != 0)
  403. return TASK_CREATION_FAILURE;
  404. err = starpu_task_submit(task);
  405. if (err != 0)
  406. return TASK_SUBMISSION_FAILURE;
  407. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  408. return current_config->copy_failed;
  409. }
  410. #endif /* !STARPU_USE_CUDA */
  411. #ifdef STARPU_USE_OPENCL
  412. static enum exit_code
  413. ram_to_opencl()
  414. {
  415. int err;
  416. struct starpu_task *task;
  417. err = create_task(&task, STARPU_OPENCL_WORKER, 0);
  418. if (err != 0)
  419. return TASK_CREATION_FAILURE;
  420. err = starpu_task_submit(task);
  421. if (err != 0)
  422. return TASK_SUBMISSION_FAILURE;
  423. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  424. return current_config->copy_failed;
  425. }
  426. static enum exit_code
  427. opencl_to_ram()
  428. {
  429. int err;
  430. struct starpu_task *task;
  431. err = create_task(&task, STARPU_CPU_WORKER, -1);
  432. if (err != 0)
  433. return TASK_CREATION_FAILURE;
  434. err = starpu_task_submit(task);
  435. if (err != 0)
  436. return TASK_SUBMISSION_FAILURE;
  437. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  438. return current_config->copy_failed;
  439. }
  440. #endif /* !STARPU_USE_OPENCL */
  441. /* End of the <device1>_to_<device2> functions. */
  442. #ifdef STARPU_USE_CUDA
  443. static void
  444. run_cuda(int async)
  445. {
  446. /* RAM -> CUDA (-> CUDA) -> RAM */
  447. int err;
  448. err = ram_to_cuda();
  449. set_field(&summary, async, CPU_TO_CUDA, err);
  450. /* If this failed, there is no point in continuing. */
  451. if (err != SUCCESS)
  452. return;
  453. #ifdef HAVE_CUDA_MEMCPY_PEER
  454. if (starpu_cuda_worker_get_count() >= 2)
  455. {
  456. err = cuda_to_cuda();
  457. set_field(&summary, async, CUDA_TO_CUDA, err);
  458. /* Even if cuda_to_cuda() failed, a valid copy is left on the first
  459. * cuda device, which means we can safely test cuda_to_ram() */
  460. }
  461. else
  462. {
  463. summary.cuda_to_cuda_async = UNTESTED;
  464. }
  465. #else
  466. summary.cuda_to_cuda_async = UNTESTED;
  467. #endif /* !HAVE_CUDA_MEMCPY_PEER */
  468. #ifdef STARPU_USE_CPU
  469. err = cuda_to_ram();
  470. set_field(&summary, async, CUDA_TO_CPU, err);
  471. #endif /* !STARPU_USE_CPU */
  472. }
  473. #endif /* !STARPU_USE_CUDA */
  474. #ifdef STARPU_USE_OPENCL
  475. static void
  476. run_opencl(int async)
  477. {
  478. /* RAM -> OpenCL -> RAM */
  479. int err;
  480. err = ram_to_opencl();
  481. set_field(&summary, async, CPU_TO_OPENCL, err);
  482. if (err != SUCCESS)
  483. return;
  484. #ifdef STARPU_USE_CPU
  485. err = opencl_to_ram();
  486. set_field(&summary, async, OPENCL_TO_CPU, err);
  487. #endif /*!STARPU_USE_CPU */
  488. }
  489. #endif /* !STARPU_USE_OPENCL */
  490. #ifdef STARPU_USE_CPU
  491. /* Valid data should be in RAM before calling this function */
  492. static void
  493. ram_to_ram(void)
  494. {
  495. int err;
  496. struct starpu_task *task;
  497. starpu_data_handle_t src, dst;
  498. void *src_interface, *dst_interface;
  499. src = *current_config->handle;
  500. dst = *current_config->dummy_handle;
  501. /* We do not care about the nodes */
  502. src_interface = starpu_data_get_interface_on_node(src, 0);
  503. dst_interface = starpu_data_get_interface_on_node(dst, 0);
  504. src->ops->copy_methods->ram_to_ram(src_interface, 0, dst_interface, 0);
  505. err = create_task(&task, STARPU_CPU_WORKER, -1);
  506. if (err != 0)
  507. goto out;
  508. task->handles[0] = dst;
  509. err = starpu_task_submit(task);
  510. starpu_task_destroy(task);
  511. if (err != 0)
  512. {
  513. err = TASK_SUBMISSION_FAILURE;
  514. goto out;
  515. }
  516. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  517. err = current_config->copy_failed;
  518. out:
  519. set_field(&summary, 0, CPU_TO_CPU, err);
  520. }
  521. #endif /* !STARPU_USE_CPU */
  522. static void
  523. run_async(void)
  524. {
  525. #ifdef STARPU_USE_CUDA
  526. run_cuda(1);
  527. #endif /* !STARPU_USE_CUDA */
  528. #ifdef STARPU_USE_OPENCL
  529. run_opencl(1);
  530. #endif /* !STARPU_USE_OPENCL */
  531. }
  532. static void
  533. run_sync(void)
  534. {
  535. starpu_data_handle_t handle = *current_config->handle;
  536. struct starpu_data_copy_methods new_copy_methods;
  537. struct starpu_data_copy_methods *old_copy_methods;
  538. old_copy_methods = (struct starpu_data_copy_methods *) handle->ops->copy_methods;
  539. memcpy(&new_copy_methods,
  540. old_copy_methods,
  541. sizeof(struct starpu_data_copy_methods));
  542. #ifdef STARPU_USE_CUDA
  543. new_copy_methods.ram_to_cuda_async = NULL;
  544. new_copy_methods.cuda_to_cuda_async = NULL;
  545. new_copy_methods.cuda_to_ram_async = NULL;
  546. #endif /* !STARPU_USE_CUDA */
  547. #ifdef STARPU_USE_OPENCL
  548. new_copy_methods.ram_to_opencl_async = NULL;
  549. new_copy_methods.opencl_to_ram_async = NULL;
  550. #endif /* !STARPU_USE_OPENCL */
  551. handle->ops->copy_methods = &new_copy_methods;
  552. #ifdef STARPU_USE_CUDA
  553. run_cuda(0);
  554. #endif /* !STARPU_USE_CUDA */
  555. #ifdef STARPU_USE_OPENCL
  556. run_opencl(0);
  557. #endif /* !STARPU_USE_OPENCL */
  558. handle->ops->copy_methods = old_copy_methods;
  559. }
  560. static void
  561. compare(void)
  562. {
  563. int err;
  564. void *interface_a, *interface_b;
  565. starpu_data_handle_t handle, dummy_handle;
  566. handle = *current_config->handle;
  567. dummy_handle = *current_config->dummy_handle;
  568. interface_a = starpu_data_get_interface_on_node(handle, 0);
  569. interface_b = starpu_data_get_interface_on_node(dummy_handle, 0);
  570. err = handle->ops->compare(interface_a, interface_b);
  571. if (err == 0)
  572. {
  573. summary.compare = FAILURE;
  574. summary.success = FAILURE;
  575. }
  576. else
  577. {
  578. summary.compare = SUCCESS;
  579. }
  580. }
  581. #ifdef STARPU_USE_CPU
  582. static void
  583. handle_to_pointer(void)
  584. {
  585. void *ptr;
  586. unsigned int node;
  587. unsigned int tests = 0;
  588. starpu_data_handle_t handle;
  589. handle = *current_config->handle;
  590. if (!handle->ops->handle_to_pointer)
  591. return;
  592. for (node = 0; node < STARPU_MAXNODES; node++)
  593. {
  594. if (starpu_node_get_kind(node) != STARPU_CPU_RAM)
  595. continue;
  596. ptr = handle->ops->handle_to_pointer(handle, node);
  597. if (starpu_data_lookup(ptr) != handle)
  598. {
  599. summary.handle_to_pointer = FAILURE;
  600. return;
  601. }
  602. tests++;
  603. }
  604. if (tests > 0)
  605. summary.handle_to_pointer = SUCCESS;
  606. }
  607. #endif /* !STARPU_USE_CPU */
  608. static int
  609. load_conf(struct test_config *config)
  610. {
  611. if (!config ||
  612. #ifdef STARPU_USE_CPU
  613. !config->cpu_func ||
  614. !config->dummy_handle ||
  615. #endif
  616. #ifdef STARPU_USE_CUDA
  617. !config->cuda_func ||
  618. #endif
  619. #ifdef STARPU_USE_OPENCL
  620. !config->opencl_func ||
  621. #endif
  622. !config->handle)
  623. {
  624. return 1;
  625. }
  626. current_config = config;
  627. return 0;
  628. }
  629. data_interface_test_summary*
  630. run_tests(struct test_config *conf)
  631. {
  632. if (load_conf(conf) == 1)
  633. {
  634. FPRINTF(stderr, "Failed to load conf.\n");
  635. return NULL;
  636. }
  637. run_async();
  638. run_sync();
  639. #ifdef STARPU_USE_CPU
  640. ram_to_ram();
  641. compare();
  642. handle_to_pointer();
  643. #endif
  644. return &summary;
  645. }