sync_with_data_with_mem.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (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 128
  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 = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  31. .cpu_func = dummy_codelet,
  32. #ifdef STARPU_USE_CUDA
  33. .cuda_func = dummy_codelet,
  34. #endif
  35. #ifdef STARPU_USE_OPENCL
  36. .opencl_func = dummy_codelet,
  37. #endif
  38. .nbuffers = 1
  39. };
  40. void use_handle(starpu_data_handle handle)
  41. {
  42. int ret;
  43. struct starpu_task *task;
  44. task = starpu_task_create();
  45. task->cl = &cl;
  46. task->buffers[0].handle = handle;
  47. task->buffers[0].mode = STARPU_RW;
  48. task->detach = 0;
  49. ret = starpu_task_submit(task);
  50. if (ret == -ENODEV)
  51. {
  52. /* No one can execute such a task, but that's not a failure
  53. * of the test either. */
  54. exit(0);
  55. }
  56. }
  57. int main(int argc, char **argv)
  58. {
  59. starpu_init(NULL);
  60. /* Allocate all buffers and register them to StarPU */
  61. unsigned b;
  62. for (b = 0; b < NBUFFERS; b++)
  63. {
  64. starpu_data_malloc_pinned_if_possible((void **)&buffer[b], VECTORSIZE);
  65. starpu_vector_data_register(&v_handle[b], 0,
  66. (uintptr_t)buffer[b], VECTORSIZE, sizeof(char));
  67. }
  68. unsigned iter;
  69. for (iter = 0; iter < NITER; iter++)
  70. {
  71. /* Use the buffers on the different workers so that it may not
  72. * be in main memory anymore */
  73. for (b = 0; b < NBUFFERS; b++)
  74. use_handle(v_handle[b]);
  75. starpu_task_wait_for_all();
  76. /* Grab the different pieces of data into main memory */
  77. for (b = 0; b < NBUFFERS; b++)
  78. starpu_data_acquire(v_handle[b], STARPU_RW);
  79. /* Release them */
  80. for (b = 0; b < NBUFFERS; b++)
  81. starpu_data_release(v_handle[b]);
  82. }
  83. /* do some cleanup */
  84. for (b = 0; b < NBUFFERS; b++)
  85. starpu_data_unregister(v_handle[b]);
  86. starpu_shutdown();
  87. return 0;
  88. }