sync_with_data_with_mem.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 <stdio.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #define NBUFFERS 64
  22. #define NITER 1000
  23. #define VECTORSIZE 1024
  24. float *buffer[NBUFFERS];
  25. starpu_data_handle v_handle[NBUFFERS];
  26. static void dummy_codelet(void *descr[], __attribute__ ((unused)) void *_args)
  27. {
  28. }
  29. static starpu_codelet cl = {
  30. .where = CORE|CUDA,
  31. .core_func = dummy_codelet,
  32. #ifdef USE_CUDA
  33. .cuda_func = dummy_codelet,
  34. #endif
  35. .nbuffers = 1
  36. };
  37. void use_handle(starpu_data_handle handle)
  38. {
  39. int ret;
  40. struct starpu_task *task;
  41. task = starpu_task_create();
  42. task->cl = &cl;
  43. task->buffers[0].handle = handle;
  44. task->buffers[0].mode = STARPU_RW;
  45. task->detach = 0;
  46. ret = starpu_submit_task(task);
  47. if (ret == -ENODEV)
  48. {
  49. /* No one can execute such a task, but that's not a failure
  50. * of the test either. */
  51. exit(0);
  52. }
  53. }
  54. int main(int argc, char **argv)
  55. {
  56. starpu_init(NULL);
  57. /* Allocate all buffers and register them to StarPU */
  58. unsigned b;
  59. for (b = 0; b < NBUFFERS; b++)
  60. {
  61. starpu_malloc_pinned_if_possible((void **)&buffer[b], VECTORSIZE);
  62. starpu_register_vector_data(&v_handle[b], 0,
  63. (uintptr_t)buffer[b], VECTORSIZE, sizeof(char));
  64. }
  65. unsigned iter;
  66. for (iter = 0; iter < NITER; iter++)
  67. {
  68. /* Use the buffers on the different workers so that it may not
  69. * be in main memory anymore */
  70. for (b = 0; b < NBUFFERS; b++)
  71. use_handle(v_handle[b]);
  72. starpu_wait_all_tasks();
  73. /* Grab the different pieces of data into main memory */
  74. for (b = 0; b < NBUFFERS; b++)
  75. starpu_sync_data_with_mem(v_handle[b], STARPU_RW);
  76. /* Release them */
  77. for (b = 0; b < NBUFFERS; b++)
  78. starpu_release_data_from_mem(v_handle[b]);
  79. }
  80. /* do some cleanup */
  81. for (b = 0; b < NBUFFERS; b++)
  82. starpu_delete_data(v_handle[b]);
  83. starpu_shutdown();
  84. return 0;
  85. }