test_interfaces.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. static char *
  30. enum_to_string(int exit_code)
  31. {
  32. switch (exit_code)
  33. {
  34. case SUCCESS:
  35. return "Success";
  36. case FAILURE:
  37. return "Failure";
  38. case UNTESTED:
  39. return "Untested";
  40. case TASK_CREATION_FAILURE:
  41. return "Task creation failed";
  42. case TASK_SUBMISSION_FAILURE:
  43. return "Task submission failed";
  44. default:
  45. assert(0);
  46. }
  47. }
  48. struct data_interface_test_summary
  49. {
  50. int success;
  51. /* Copy methods */
  52. #ifdef STARPU_USE_CPU
  53. int cpu_to_cpu;
  54. #endif
  55. #ifdef STARPU_USE_CUDA
  56. int cpu_to_cuda;
  57. int cuda_to_cuda;
  58. int cuda_to_cpu;
  59. int cpu_to_cuda_async;
  60. int cuda_to_cpu_async;
  61. int cuda_to_cuda_async;
  62. #endif
  63. #ifdef STARPU_USE_OPENCL
  64. int cpu_to_opencl;
  65. int opencl_to_cpu;
  66. int cpu_to_opencl_async;
  67. int opencl_to_cpu_async;
  68. #endif
  69. /* Other stuff */
  70. int compare;
  71. #ifdef STARPU_USE_CPU
  72. int handle_to_pointer;
  73. #endif
  74. };
  75. void data_interface_test_summary_print(FILE *f,
  76. struct data_interface_test_summary *s)
  77. {
  78. if (!f)
  79. f = stderr;
  80. FPRINTF(f, "%s : %s\n",
  81. current_config->name, enum_to_string(s->success));
  82. FPRINTF(f, "Asynchronous :\n");
  83. #ifdef STARPU_USE_CUDA
  84. FPRINTF(f, "\tCPU -> CUDA : %s\n",
  85. enum_to_string(s->cpu_to_cuda_async));
  86. FPRINTF(f, "\tCUDA -> CUDA : %s\n",
  87. enum_to_string(s->cuda_to_cuda_async));
  88. FPRINTF(f, "\tCUDA -> CPU : %s\n",
  89. enum_to_string(s->cuda_to_cpu_async));
  90. #endif /* !STARPU_USE_CUDA */
  91. #ifdef STARPU_USE_OPENCL
  92. FPRINTF(f, "\tCPU -> OpenCl : %s\n",
  93. enum_to_string(s->cpu_to_opencl_async));
  94. FPRINTF(f, "\tOpenCl -> CPU : %s\n",
  95. enum_to_string(s->opencl_to_cpu_async));
  96. #endif /* !STARPU_USE_OPENCL */
  97. FPRINTF(f, "Synchronous :\n");
  98. #ifdef STARPU_USE_CUDA
  99. FPRINTF(f, "\tCPU -> CUDA ; %s\n",
  100. enum_to_string(s->cpu_to_cuda));
  101. FPRINTF(f, "\tCUDA -> CUDA : %s\n",
  102. enum_to_string(s->cuda_to_cuda));
  103. FPRINTF(f, "\tCUDA -> CPU : %s\n",
  104. enum_to_string(s->cuda_to_cpu));
  105. #endif /* !STARPU_USE_CUDA */
  106. #ifdef STARPU_USE_OPENCL
  107. FPRINTF(f, "\tCPU -> OpenCl : %s\n",
  108. enum_to_string(s->cpu_to_opencl));
  109. FPRINTF(f, "\tOpenCl -> CPU : %s\n",
  110. enum_to_string(s->opencl_to_cpu));
  111. #endif /* !STARPU_USE_OPENCL */
  112. #ifdef STARPU_USE_CPU
  113. FPRINTF(f, "CPU -> CPU : %s\n",
  114. enum_to_string(s->cpu_to_cpu));
  115. FPRINTF(f, "handle_to_pointer() : %s\n",
  116. enum_to_string(s->handle_to_pointer));
  117. #endif /* !STARPU_USE_CPU */
  118. FPRINTF(f, "compare() : %s\n",
  119. enum_to_string(s->compare));
  120. }
  121. int
  122. data_interface_test_summary_success(data_interface_test_summary *s)
  123. {
  124. return s->success;
  125. }
  126. enum operation
  127. {
  128. CPU_TO_CPU
  129. #ifdef STARPU_USE_CUDA
  130. ,
  131. CPU_TO_CUDA,
  132. CUDA_TO_CUDA,
  133. CUDA_TO_CPU
  134. #endif /* !STARPU_USE_CUDA */
  135. #ifdef STARPU_USE_OPENCL
  136. ,
  137. CPU_TO_OPENCL,
  138. OPENCL_TO_CPU
  139. #endif /* !STARPU_USE_OPENCL */
  140. };
  141. static int*
  142. get_field(struct data_interface_test_summary *s, int async, enum operation op)
  143. {
  144. switch (op)
  145. {
  146. #ifdef STARPU_USE_CPU
  147. case CPU_TO_CPU:
  148. return &s->cpu_to_cpu;
  149. #endif
  150. #ifdef STARPU_USE_CUDA
  151. case CPU_TO_CUDA:
  152. return async?&s->cpu_to_cuda_async:&s->cpu_to_cuda;
  153. case CUDA_TO_CUDA:
  154. return async?&s->cuda_to_cuda_async:&s->cuda_to_cuda;
  155. case CUDA_TO_CPU:
  156. return async?&s->cuda_to_cpu_async:&s->cuda_to_cpu;
  157. #endif /* !STARPU_USE_CUDA */
  158. #ifdef STARPU_USE_OPENCL
  159. case CPU_TO_OPENCL:
  160. return async?&s->cpu_to_opencl_async:&s->cpu_to_opencl;
  161. case OPENCL_TO_CPU:
  162. return async?&s->opencl_to_cpu_async:&s->opencl_to_cpu;
  163. #endif /* !STARPU_USE_OPENCL */
  164. default:
  165. STARPU_ABORT();
  166. }
  167. /* that instruction should never be reached */
  168. return NULL;
  169. }
  170. static void
  171. set_field(struct data_interface_test_summary *s, int async,
  172. enum operation op, int ret)
  173. {
  174. int *field = get_field(s, async, op);
  175. switch (ret)
  176. {
  177. case SUCCESS:
  178. *field = SUCCESS;
  179. break;
  180. case FAILURE:
  181. *field = FAILURE;
  182. s->success = FAILURE;
  183. break;
  184. case UNTESTED:
  185. *field = UNTESTED;
  186. break;
  187. case TASK_CREATION_FAILURE:
  188. *field = TASK_CREATION_FAILURE;
  189. break;
  190. case TASK_SUBMISSION_FAILURE:
  191. *field = TASK_SUBMISSION_FAILURE;
  192. break;
  193. default:
  194. STARPU_ABORT();
  195. }
  196. }
  197. static struct data_interface_test_summary summary =
  198. {
  199. #ifdef STARPU_USE_CPU
  200. .cpu_to_cpu = UNTESTED,
  201. .compare = UNTESTED,
  202. #endif
  203. #ifdef STARPU_USE_CUDA
  204. .cpu_to_cuda = UNTESTED,
  205. .cuda_to_cuda = UNTESTED,
  206. .cuda_to_cpu = UNTESTED,
  207. .cpu_to_cuda_async = UNTESTED,
  208. .cuda_to_cpu_async = UNTESTED,
  209. .cuda_to_cuda_async = UNTESTED,
  210. #endif
  211. #ifdef STARPU_USE_OPENCL
  212. .cpu_to_opencl = UNTESTED,
  213. .opencl_to_cpu = UNTESTED,
  214. .cpu_to_opencl_async = UNTESTED,
  215. .opencl_to_cpu_async = UNTESTED,
  216. #endif
  217. #ifdef STARPU_USE_CPU
  218. .handle_to_pointer = UNTESTED,
  219. #endif
  220. .success = SUCCESS
  221. };
  222. /*
  223. * This variable has to be either -1 or 1.
  224. * The kernels should check that the ith value stored in the data interface is
  225. * equal to i, if factor == 1, or -i, if factor == -1.
  226. */
  227. static int factor = -1;
  228. /*
  229. * Creates a complete task, only knowing on what device it should be executed.
  230. * Note that the global variable <current_config> is heavily used here.
  231. * Arguments :
  232. * - taskp : a pointer to a valid task
  233. * - type : STARPU_{CPU,CUDA,OPENCL}_WORKER. Gordon is not supported.
  234. * - id : -1 if you dont care about the device where the task will be
  235. * executed, as long as it has the right type.
  236. * >= 0 if you want to make sure the task will be executed on the
  237. * idth device that has the specified type.
  238. * Return values :
  239. * -ENODEV
  240. * 0 : success.
  241. */
  242. static int
  243. create_task(struct starpu_task **taskp, enum starpu_archtype type, int id)
  244. {
  245. static int cpu_workers[STARPU_MAXCPUS];
  246. #ifdef STARPU_USE_CUDA
  247. static int cuda_workers[STARPU_MAXCUDADEVS];
  248. #endif
  249. #ifdef STARPU_USE_OPENCL
  250. static int opencl_workers[STARPU_MAXOPENCLDEVS];
  251. #endif
  252. static int n_cpus = -1;
  253. #ifdef STARPU_USE_CUDA
  254. static int n_cudas = -1;
  255. #endif
  256. #ifdef STARPU_USE_OPENCL
  257. static int n_opencls = -1;
  258. #endif
  259. if (n_cpus == -1) /* First time here */
  260. {
  261. /* We do not check the return values of the calls to
  262. * starpu_worker_get_ids_by_type now, because it is simpler to
  263. * detect a problem in the switch that comes right after this
  264. * block of code. */
  265. n_cpus = starpu_worker_get_ids_by_type(STARPU_CPU_WORKER,
  266. cpu_workers,
  267. STARPU_MAXCPUS);
  268. #ifdef STARPU_USE_CUDA
  269. n_cudas = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
  270. cuda_workers,
  271. STARPU_MAXCUDADEVS);
  272. #endif
  273. #ifdef STARPU_USE_OPENCL
  274. n_opencls = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
  275. opencl_workers,
  276. STARPU_MAXOPENCLDEVS);
  277. #endif
  278. }
  279. int workerid=0;
  280. static struct starpu_codelet cl;
  281. cl.nbuffers = 1;
  282. cl.modes[0] = STARPU_RW;
  283. switch (type)
  284. {
  285. case STARPU_CPU_WORKER:
  286. if (id != -1)
  287. {
  288. if (id >= n_cpus)
  289. {
  290. FPRINTF(stderr, "Not enough CPU workers\n");
  291. return -ENODEV;
  292. }
  293. workerid = *(cpu_workers + id);
  294. }
  295. cl.where = STARPU_CPU;
  296. cl.cpu_funcs[0] = current_config->cpu_func;
  297. break;
  298. #ifdef STARPU_USE_CUDA
  299. case STARPU_CUDA_WORKER:
  300. if (id != -1)
  301. {
  302. if (id >= n_cudas)
  303. {
  304. FPRINTF(stderr, "Not enough CUDA workers\n");
  305. return -ENODEV;
  306. }
  307. workerid = cuda_workers[id];
  308. }
  309. cl.where = STARPU_CUDA;
  310. cl.cuda_funcs[0] = current_config->cuda_func;
  311. break;
  312. #endif /* !STARPU_USE_CUDA */
  313. #ifdef STARPU_USE_OPENCL
  314. case STARPU_OPENCL_WORKER:
  315. if (id != -1)
  316. {
  317. if (id >= n_opencls)
  318. {
  319. FPRINTF(stderr, "Not enough OpenCL workers\n");
  320. return -ENODEV;
  321. }
  322. workerid = *(opencl_workers + id);
  323. }
  324. cl.where = STARPU_OPENCL;
  325. cl.opencl_funcs[0] = current_config->opencl_func;
  326. break;
  327. #endif /* ! STARPU_USE_OPENCL */
  328. case STARPU_GORDON_WORKER: /* Not supported */
  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. src->ops->copy_methods->ram_to_ram(src_interface, 0, dst_interface, 0);
  495. err = create_task(&task, STARPU_CPU_WORKER, -1);
  496. if (err != 0)
  497. goto out;
  498. task->handles[0] = dst;
  499. err = starpu_task_submit(task);
  500. starpu_task_destroy(task);
  501. if (err != 0)
  502. {
  503. err = TASK_SUBMISSION_FAILURE;
  504. goto out;
  505. }
  506. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  507. err = current_config->copy_failed;
  508. out:
  509. set_field(&summary, 0, CPU_TO_CPU, err);
  510. }
  511. #endif /* !STARPU_USE_CPU */
  512. static void
  513. run_async(void)
  514. {
  515. int async = starpu_asynchronous_copy_disabled();
  516. if (async == 1) {
  517. FPRINTF(stderr, "Asynchronous copies have been disabled\n");
  518. return;
  519. }
  520. #ifdef STARPU_USE_CUDA
  521. run_cuda(1);
  522. #endif /* !STARPU_USE_CUDA */
  523. #ifdef STARPU_USE_OPENCL
  524. run_opencl(1);
  525. #endif /* !STARPU_USE_OPENCL */
  526. }
  527. static void
  528. run_sync(void)
  529. {
  530. starpu_data_handle_t handle = *current_config->handle;
  531. struct starpu_data_copy_methods new_copy_methods;
  532. struct starpu_data_copy_methods *old_copy_methods;
  533. old_copy_methods = (struct starpu_data_copy_methods *) handle->ops->copy_methods;
  534. memcpy(&new_copy_methods,
  535. old_copy_methods,
  536. sizeof(struct starpu_data_copy_methods));
  537. #ifdef STARPU_USE_CUDA
  538. new_copy_methods.ram_to_cuda_async = NULL;
  539. new_copy_methods.cuda_to_cuda_async = NULL;
  540. new_copy_methods.cuda_to_ram_async = NULL;
  541. #endif /* !STARPU_USE_CUDA */
  542. #ifdef STARPU_USE_OPENCL
  543. new_copy_methods.ram_to_opencl_async = NULL;
  544. new_copy_methods.opencl_to_ram_async = NULL;
  545. #endif /* !STARPU_USE_OPENCL */
  546. handle->ops->copy_methods = &new_copy_methods;
  547. #ifdef STARPU_USE_CUDA
  548. run_cuda(0);
  549. #endif /* !STARPU_USE_CUDA */
  550. #ifdef STARPU_USE_OPENCL
  551. run_opencl(0);
  552. #endif /* !STARPU_USE_OPENCL */
  553. handle->ops->copy_methods = old_copy_methods;
  554. }
  555. static void
  556. compare(void)
  557. {
  558. int err;
  559. void *interface_a, *interface_b;
  560. starpu_data_handle_t handle, dummy_handle;
  561. handle = *current_config->handle;
  562. dummy_handle = *current_config->dummy_handle;
  563. interface_a = starpu_data_get_interface_on_node(handle, 0);
  564. interface_b = starpu_data_get_interface_on_node(dummy_handle, 0);
  565. err = handle->ops->compare(interface_a, interface_b);
  566. if (err == 0)
  567. {
  568. summary.compare = FAILURE;
  569. summary.success = FAILURE;
  570. }
  571. else
  572. {
  573. summary.compare = SUCCESS;
  574. }
  575. }
  576. #ifdef STARPU_USE_CPU
  577. static void
  578. handle_to_pointer(void)
  579. {
  580. void *ptr;
  581. unsigned int node;
  582. unsigned int tests = 0;
  583. starpu_data_handle_t handle;
  584. handle = *current_config->handle;
  585. if (!handle->ops->handle_to_pointer)
  586. return;
  587. for (node = 0; node < STARPU_MAXNODES; node++)
  588. {
  589. if (starpu_node_get_kind(node) != STARPU_CPU_RAM)
  590. continue;
  591. ptr = handle->ops->handle_to_pointer(handle, node);
  592. if (starpu_data_lookup(ptr) != handle)
  593. {
  594. summary.handle_to_pointer = FAILURE;
  595. return;
  596. }
  597. tests++;
  598. }
  599. if (tests > 0)
  600. summary.handle_to_pointer = SUCCESS;
  601. }
  602. #endif /* !STARPU_USE_CPU */
  603. static int
  604. load_conf(struct test_config *config)
  605. {
  606. if (!config ||
  607. #ifdef STARPU_USE_CPU
  608. !config->cpu_func ||
  609. !config->dummy_handle ||
  610. #endif
  611. #ifdef STARPU_USE_CUDA
  612. !config->cuda_func ||
  613. #endif
  614. #ifdef STARPU_USE_OPENCL
  615. !config->opencl_func ||
  616. #endif
  617. !config->handle)
  618. {
  619. return 1;
  620. }
  621. current_config = config;
  622. return 0;
  623. }
  624. data_interface_test_summary*
  625. run_tests(struct test_config *conf)
  626. {
  627. if (load_conf(conf) == 1)
  628. {
  629. FPRINTF(stderr, "Failed to load conf.\n");
  630. return NULL;
  631. }
  632. run_async();
  633. run_sync();
  634. #ifdef STARPU_USE_CPU
  635. ram_to_ram();
  636. compare();
  637. handle_to_pointer();
  638. #endif
  639. return &summary;
  640. }