redundant_buffer.c 2.6 KB

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