redundant_buffer.c 2.5 KB

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