redundant_buffer.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011,2013,2014,2016 Université de Bordeaux
  4. * Copyright (C) 2013 Inria
  5. * Copyright (C) 2010-2013,2015,2017 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <errno.h>
  21. #include <starpu.h>
  22. #include <stdlib.h>
  23. #include "../helper.h"
  24. /*
  25. * Try passing the same buffer twice to the same task
  26. */
  27. #define N 10000
  28. #define VECTORSIZE 1024
  29. starpu_data_handle_t v_handle;
  30. static unsigned *v;
  31. void func_codelet_null(void *descr[], void *_args)
  32. {
  33. (void)descr;
  34. (void)_args;
  35. }
  36. static
  37. struct starpu_codelet cl =
  38. {
  39. .cpu_funcs = {func_codelet_null},
  40. .cuda_funcs = {func_codelet_null},
  41. .opencl_funcs = {func_codelet_null},
  42. .cpu_funcs_name = {"func_codelet_null"},
  43. .nbuffers = 2,
  44. .modes = {STARPU_R, STARPU_R}
  45. };
  46. int main(int argc, char **argv)
  47. {
  48. int ret;
  49. ret = starpu_initialize(NULL, &argc, &argv);
  50. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  51. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  52. starpu_malloc((void **)&v, VECTORSIZE*sizeof(unsigned));
  53. starpu_vector_data_register(&v_handle, STARPU_MAIN_RAM, (uintptr_t)v, VECTORSIZE, sizeof(unsigned));
  54. unsigned iter;
  55. for (iter = 0; iter < N; iter++)
  56. {
  57. struct starpu_task *task = starpu_task_create();
  58. task->cl = &cl;
  59. task->handles[0] = v_handle;
  60. task->handles[1] = v_handle;
  61. ret = starpu_task_submit(task);
  62. if (ret == -ENODEV) goto enodev;
  63. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  64. }
  65. ret = starpu_task_wait_for_all();
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  67. starpu_data_unregister(v_handle);
  68. starpu_free(v);
  69. starpu_shutdown();
  70. return EXIT_SUCCESS;
  71. enodev:
  72. starpu_data_unregister(v_handle);
  73. starpu_free(v);
  74. fprintf(stderr, "WARNING: No one can execute this task\n");
  75. /* yes, we do not perform the computation but we did detect that no one
  76. * could perform the kernel, so this is not an error from StarPU */
  77. starpu_shutdown();
  78. return STARPU_TEST_SKIPPED;
  79. }