test_interfaces.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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. *taskp = task;
  345. return 0;
  346. }
  347. /*
  348. * <device1>_to_<device2> functions.
  349. * They all create and submit a task that has to be executed on <device2>,
  350. * forcing a copy between <device1> and <device2>.
  351. * XXX : could we sometimes use starp_insert_task() ? It seems hars because we
  352. * need to set the execute_on_a_specific_worker field...
  353. */
  354. #ifdef STARPU_USE_CUDA
  355. static enum exit_code
  356. ram_to_cuda(void)
  357. {
  358. int err;
  359. struct starpu_task *task;
  360. err = create_task(&task, STARPU_CUDA_WORKER, 0);
  361. if (err != 0)
  362. return TASK_CREATION_FAILURE;
  363. err = starpu_task_submit(task);
  364. if (err != 0)
  365. return TASK_SUBMISSION_FAILURE;
  366. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  367. return current_config->copy_failed;
  368. }
  369. #ifdef HAVE_CUDA_MEMCPY_PEER
  370. static enum exit_code
  371. cuda_to_cuda(void)
  372. {
  373. int err;
  374. struct starpu_task *task;
  375. err = create_task(&task, STARPU_CUDA_WORKER, 1);
  376. if (err != 0)
  377. return TASK_CREATION_FAILURE;
  378. err = starpu_task_submit(task);
  379. if (err != 0)
  380. return TASK_SUBMISSION_FAILURE;
  381. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  382. return current_config->copy_failed;
  383. }
  384. #endif
  385. static enum exit_code
  386. cuda_to_ram(void)
  387. {
  388. int err;
  389. struct starpu_task *task;
  390. err = create_task(&task, STARPU_CPU_WORKER, -1);
  391. if (err != 0)
  392. return TASK_CREATION_FAILURE;
  393. err = starpu_task_submit(task);
  394. if (err != 0)
  395. return TASK_SUBMISSION_FAILURE;
  396. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  397. return current_config->copy_failed;
  398. }
  399. #endif /* !STARPU_USE_CUDA */
  400. #ifdef STARPU_USE_OPENCL
  401. static enum exit_code
  402. ram_to_opencl(void)
  403. {
  404. int err;
  405. struct starpu_task *task;
  406. err = create_task(&task, STARPU_OPENCL_WORKER, 0);
  407. if (err != 0)
  408. return TASK_CREATION_FAILURE;
  409. err = starpu_task_submit(task);
  410. if (err != 0)
  411. return TASK_SUBMISSION_FAILURE;
  412. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  413. return current_config->copy_failed;
  414. }
  415. static enum exit_code
  416. opencl_to_ram(void)
  417. {
  418. int err;
  419. struct starpu_task *task;
  420. err = create_task(&task, STARPU_CPU_WORKER, -1);
  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. #endif /* !STARPU_USE_OPENCL */
  430. /* End of the <device1>_to_<device2> functions. */
  431. #ifdef STARPU_USE_CUDA
  432. static void
  433. run_cuda(int async)
  434. {
  435. /* RAM -> CUDA (-> CUDA) -> RAM */
  436. int err;
  437. err = ram_to_cuda();
  438. set_field(&summary, async, CPU_TO_CUDA, err);
  439. /* If this failed, there is no point in continuing. */
  440. if (err != SUCCESS)
  441. return;
  442. #ifdef HAVE_CUDA_MEMCPY_PEER
  443. if (starpu_cuda_worker_get_count() >= 2)
  444. {
  445. err = cuda_to_cuda();
  446. set_field(&summary, async, CUDA_TO_CUDA, err);
  447. /* Even if cuda_to_cuda() failed, a valid copy is left on the first
  448. * cuda device, which means we can safely test cuda_to_ram() */
  449. }
  450. else
  451. {
  452. summary.cuda_to_cuda_async = UNTESTED;
  453. }
  454. #else
  455. summary.cuda_to_cuda_async = UNTESTED;
  456. #endif /* !HAVE_CUDA_MEMCPY_PEER */
  457. #ifdef STARPU_USE_CPU
  458. err = cuda_to_ram();
  459. set_field(&summary, async, CUDA_TO_CPU, err);
  460. #endif /* !STARPU_USE_CPU */
  461. }
  462. #endif /* !STARPU_USE_CUDA */
  463. #ifdef STARPU_USE_OPENCL
  464. static void
  465. run_opencl(int async)
  466. {
  467. /* RAM -> OpenCL -> RAM */
  468. int err;
  469. err = ram_to_opencl();
  470. set_field(&summary, async, CPU_TO_OPENCL, err);
  471. if (err != SUCCESS)
  472. return;
  473. #ifdef STARPU_USE_CPU
  474. err = opencl_to_ram();
  475. set_field(&summary, async, OPENCL_TO_CPU, err);
  476. #endif /*!STARPU_USE_CPU */
  477. }
  478. #endif /* !STARPU_USE_OPENCL */
  479. #ifdef STARPU_USE_CPU
  480. /* Valid data should be in RAM before calling this function */
  481. static void
  482. ram_to_ram(void)
  483. {
  484. int err;
  485. struct starpu_task *task;
  486. starpu_data_handle_t src, dst;
  487. void *src_interface, *dst_interface;
  488. src = *current_config->handle;
  489. dst = *current_config->dummy_handle;
  490. /* We do not care about the nodes */
  491. src_interface = starpu_data_get_interface_on_node(src, 0);
  492. dst_interface = starpu_data_get_interface_on_node(dst, 0);
  493. src->ops->copy_methods->ram_to_ram(src_interface, 0, dst_interface, 0);
  494. err = create_task(&task, STARPU_CPU_WORKER, -1);
  495. if (err != 0)
  496. goto out;
  497. task->handles[0] = dst;
  498. err = starpu_task_submit(task);
  499. starpu_task_destroy(task);
  500. if (err != 0)
  501. {
  502. err = TASK_SUBMISSION_FAILURE;
  503. goto out;
  504. }
  505. FPRINTF(stderr, "[%s] : %d\n", __func__, current_config->copy_failed);
  506. err = current_config->copy_failed;
  507. out:
  508. set_field(&summary, 0, CPU_TO_CPU, err);
  509. }
  510. #endif /* !STARPU_USE_CPU */
  511. static void
  512. run_async(void)
  513. {
  514. int async = starpu_asynchronous_copy_disabled();
  515. if (async == 1) {
  516. FPRINTF(stderr, "Asynchronous copies have been disabled\n");
  517. return;
  518. }
  519. #ifdef STARPU_USE_CUDA
  520. run_cuda(1);
  521. #endif /* !STARPU_USE_CUDA */
  522. #ifdef STARPU_USE_OPENCL
  523. run_opencl(1);
  524. #endif /* !STARPU_USE_OPENCL */
  525. }
  526. static void
  527. run_sync(void)
  528. {
  529. starpu_data_handle_t handle = *current_config->handle;
  530. struct starpu_data_copy_methods new_copy_methods;
  531. struct starpu_data_copy_methods *old_copy_methods;
  532. old_copy_methods = (struct starpu_data_copy_methods *) handle->ops->copy_methods;
  533. memcpy(&new_copy_methods,
  534. old_copy_methods,
  535. sizeof(struct starpu_data_copy_methods));
  536. #ifdef STARPU_USE_CUDA
  537. new_copy_methods.ram_to_cuda_async = NULL;
  538. new_copy_methods.cuda_to_cuda_async = NULL;
  539. new_copy_methods.cuda_to_ram_async = NULL;
  540. #endif /* !STARPU_USE_CUDA */
  541. #ifdef STARPU_USE_OPENCL
  542. new_copy_methods.ram_to_opencl_async = NULL;
  543. new_copy_methods.opencl_to_ram_async = NULL;
  544. #endif /* !STARPU_USE_OPENCL */
  545. handle->ops->copy_methods = &new_copy_methods;
  546. #ifdef STARPU_USE_CUDA
  547. run_cuda(0);
  548. #endif /* !STARPU_USE_CUDA */
  549. #ifdef STARPU_USE_OPENCL
  550. run_opencl(0);
  551. #endif /* !STARPU_USE_OPENCL */
  552. handle->ops->copy_methods = old_copy_methods;
  553. }
  554. static void
  555. compare(void)
  556. {
  557. int err;
  558. void *interface_a, *interface_b;
  559. starpu_data_handle_t handle, dummy_handle;
  560. handle = *current_config->handle;
  561. dummy_handle = *current_config->dummy_handle;
  562. interface_a = starpu_data_get_interface_on_node(handle, 0);
  563. interface_b = starpu_data_get_interface_on_node(dummy_handle, 0);
  564. err = handle->ops->compare(interface_a, interface_b);
  565. if (err == 0)
  566. {
  567. summary.compare = FAILURE;
  568. summary.success = FAILURE;
  569. }
  570. else
  571. {
  572. summary.compare = SUCCESS;
  573. }
  574. }
  575. #ifdef STARPU_USE_CPU
  576. static void
  577. handle_to_pointer(void)
  578. {
  579. void *ptr;
  580. unsigned int node;
  581. unsigned int tests = 0;
  582. starpu_data_handle_t handle;
  583. handle = *current_config->handle;
  584. if (!handle->ops->handle_to_pointer)
  585. return;
  586. for (node = 0; node < STARPU_MAXNODES; node++)
  587. {
  588. if (starpu_node_get_kind(node) != STARPU_CPU_RAM)
  589. continue;
  590. ptr = handle->ops->handle_to_pointer(handle, node);
  591. if (starpu_data_lookup(ptr) != handle)
  592. {
  593. summary.handle_to_pointer = FAILURE;
  594. return;
  595. }
  596. tests++;
  597. }
  598. if (tests > 0)
  599. summary.handle_to_pointer = SUCCESS;
  600. }
  601. #endif /* !STARPU_USE_CPU */
  602. static int
  603. load_conf(struct test_config *config)
  604. {
  605. if (!config ||
  606. #ifdef STARPU_USE_CPU
  607. !config->cpu_func ||
  608. !config->dummy_handle ||
  609. #endif
  610. #ifdef STARPU_USE_CUDA
  611. !config->cuda_func ||
  612. #endif
  613. #ifdef STARPU_USE_OPENCL
  614. !config->opencl_func ||
  615. #endif
  616. !config->handle)
  617. {
  618. return 1;
  619. }
  620. current_config = config;
  621. return 0;
  622. }
  623. data_interface_test_summary*
  624. run_tests(struct test_config *conf)
  625. {
  626. if (load_conf(conf) == 1)
  627. {
  628. FPRINTF(stderr, "Failed to load conf.\n");
  629. return NULL;
  630. }
  631. run_async();
  632. run_sync();
  633. #ifdef STARPU_USE_CPU
  634. ram_to_ram();
  635. compare();
  636. handle_to_pointer();
  637. #endif
  638. return &summary;
  639. }