sync_with_data_with_mem.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <errno.h>
  20. #include <starpu.h>
  21. #include <stdlib.h>
  22. #define NBUFFERS 64
  23. #define NITER 128
  24. #define VECTORSIZE 1024
  25. float *buffer[NBUFFERS];
  26. starpu_data_handle v_handle[NBUFFERS];
  27. static void dummy_codelet(void *descr[], __attribute__ ((unused)) void *_args)
  28. {
  29. }
  30. static starpu_codelet cl = {
  31. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  32. .cpu_func = dummy_codelet,
  33. #ifdef STARPU_USE_CUDA
  34. .cuda_func = dummy_codelet,
  35. #endif
  36. #ifdef STARPU_USE_OPENCL
  37. .opencl_func = dummy_codelet,
  38. #endif
  39. .nbuffers = 1
  40. };
  41. void use_handle(starpu_data_handle handle)
  42. {
  43. int ret;
  44. struct starpu_task *task;
  45. task = starpu_task_create();
  46. task->cl = &cl;
  47. task->buffers[0].handle = handle;
  48. task->buffers[0].mode = STARPU_RW;
  49. task->detach = 0;
  50. ret = starpu_task_submit(task);
  51. if (ret == -ENODEV)
  52. {
  53. /* No one can execute such a task, but that's not a failure
  54. * of the test either. */
  55. exit(0);
  56. }
  57. }
  58. int main(int argc, char **argv)
  59. {
  60. starpu_init(NULL);
  61. /* Allocate all buffers and register them to StarPU */
  62. unsigned b;
  63. for (b = 0; b < NBUFFERS; b++)
  64. {
  65. starpu_malloc((void **)&buffer[b], VECTORSIZE);
  66. starpu_vector_data_register(&v_handle[b], 0,
  67. (uintptr_t)buffer[b], VECTORSIZE, sizeof(char));
  68. }
  69. unsigned iter;
  70. for (iter = 0; iter < NITER; iter++)
  71. {
  72. /* Use the buffers on the different workers so that it may not
  73. * be in main memory anymore */
  74. for (b = 0; b < NBUFFERS; b++)
  75. use_handle(v_handle[b]);
  76. starpu_task_wait_for_all();
  77. /* Grab the different pieces of data into main memory */
  78. for (b = 0; b < NBUFFERS; b++)
  79. starpu_data_acquire(v_handle[b], STARPU_RW);
  80. /* Release them */
  81. for (b = 0; b < NBUFFERS; b++)
  82. starpu_data_release(v_handle[b]);
  83. }
  84. /* do some cleanup */
  85. for (b = 0; b < NBUFFERS; b++) {
  86. starpu_data_unregister(v_handle[b]);
  87. starpu_free(buffer[b]);
  88. }
  89. starpu_shutdown();
  90. return 0;
  91. }