redundant_buffer.c 1.9 KB

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