redundant_buffer.c 2.2 KB

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