redundant_buffer.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 N 10000
  22. #define VECTORSIZE 1024
  23. starpu_data_handle v_handle;
  24. static unsigned *v;
  25. static void opencl_codelet_null(void *descr[], __attribute__ ((unused)) void *_args)
  26. {
  27. }
  28. static void cuda_codelet_null(void *descr[], __attribute__ ((unused)) void *_args)
  29. {
  30. }
  31. static void cpu_codelet_null(void *descr[], __attribute__ ((unused)) void *_args)
  32. {
  33. }
  34. static starpu_codelet cl = {
  35. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  36. .cpu_func = cpu_codelet_null,
  37. .cuda_func = cuda_codelet_null,
  38. .opencl_func = opencl_codelet_null,
  39. .nbuffers = 2
  40. };
  41. int main(int argc, char **argv)
  42. {
  43. starpu_init(NULL);
  44. starpu_data_malloc_pinned_if_possible((void **)&v, VECTORSIZE*sizeof(unsigned));
  45. starpu_vector_data_register(&v_handle, 0, (uintptr_t)v, VECTORSIZE, sizeof(unsigned));
  46. unsigned iter;
  47. for (iter = 0; iter < N; iter++)
  48. {
  49. struct starpu_task *task = starpu_task_create();
  50. task->cl = &cl;
  51. task->buffers[0].handle = v_handle;
  52. task->buffers[0].mode = STARPU_R;
  53. task->buffers[1].handle = v_handle;
  54. task->buffers[1].mode = STARPU_R;
  55. int ret = starpu_task_submit(task);
  56. if (ret == -ENODEV)
  57. goto enodev;
  58. }
  59. starpu_task_wait_for_all();
  60. starpu_shutdown();
  61. return 0;
  62. enodev:
  63. fprintf(stderr, "WARNING: No one can execute this task\n");
  64. /* yes, we do not perform the computation but we did detect that no one
  65. * could perform the kernel, so this is not an error from StarPU */
  66. return 0;
  67. }