redundant_buffer.c 2.6 KB

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