redundant_buffer.c 2.5 KB

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