redundant_buffer.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 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 "../helper.h"
  23. #define N 10000
  24. #define VECTORSIZE 1024
  25. starpu_data_handle_t 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 struct starpu_codelet cl =
  37. {
  38. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  39. .cpu_funcs = {cpu_codelet_null, NULL},
  40. .cuda_funcs = {cuda_codelet_null, NULL},
  41. .opencl_funcs = {opencl_codelet_null, NULL},
  42. .nbuffers = 2,
  43. .modes = {STARPU_R, STARPU_R}
  44. };
  45. int main(int argc, char **argv)
  46. {
  47. int ret;
  48. ret = starpu_init(NULL);
  49. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  51. starpu_malloc((void **)&v, VECTORSIZE*sizeof(unsigned));
  52. starpu_vector_data_register(&v_handle, 0, (uintptr_t)v, VECTORSIZE, sizeof(unsigned));
  53. unsigned iter;
  54. for (iter = 0; iter < N; iter++)
  55. {
  56. struct starpu_task *task = starpu_task_create();
  57. task->cl = &cl;
  58. task->handles[0] = v_handle;
  59. task->handles[1] = v_handle;
  60. ret = starpu_task_submit(task);
  61. if (ret == -ENODEV) goto enodev;
  62. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  63. }
  64. ret = starpu_task_wait_for_all();
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  66. starpu_data_unregister(v_handle);
  67. starpu_free(v);
  68. starpu_shutdown();
  69. return EXIT_SUCCESS;
  70. enodev:
  71. starpu_data_unregister(v_handle);
  72. starpu_free(v);
  73. fprintf(stderr, "WARNING: No one can execute this task\n");
  74. /* yes, we do not perform the computation but we did detect that no one
  75. * could perform the kernel, so this is not an error from StarPU */
  76. starpu_shutdown();
  77. return STARPU_TEST_SKIPPED;
  78. }