cache.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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 <starpu.h>
  17. #include "../helper.h"
  18. /*
  19. * Trigger re-using a buffer allocation on GPUs
  20. */
  21. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
  22. static void codelet(void *descr[], void *arg)
  23. {
  24. (void)descr;
  25. (void)arg;
  26. FPRINTF(stderr, "%lx\n", (unsigned long) STARPU_VARIABLE_GET_PTR(descr[0]));
  27. FPRINTF(stderr, "codelet\n");
  28. }
  29. #endif
  30. #ifdef STARPU_USE_CUDA
  31. static struct starpu_codelet cuda_cl =
  32. {
  33. .cuda_funcs = {codelet},
  34. .nbuffers = 1,
  35. .modes = {STARPU_R}
  36. };
  37. #endif
  38. #ifdef STARPU_USE_OPENCL
  39. static struct starpu_codelet opencl_cl =
  40. {
  41. .opencl_funcs = {codelet},
  42. .nbuffers = 1,
  43. .modes = {STARPU_R}
  44. };
  45. #endif
  46. void dotest(struct starpu_codelet *cl)
  47. {
  48. int ret;
  49. int var = 42;
  50. starpu_data_handle_t handle;
  51. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  52. ret = starpu_task_insert(cl, STARPU_R, handle, 0);
  53. if (ret == -ENODEV) goto enodev;
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  55. starpu_task_wait_for_all();
  56. starpu_data_unregister(handle);
  57. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  58. ret = starpu_task_insert(cl, STARPU_R, handle, 0);
  59. if (ret == -ENODEV) goto enodev;
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  61. starpu_task_wait_for_all();
  62. enodev:
  63. starpu_data_unregister(handle);
  64. }
  65. int main()
  66. {
  67. int ret;
  68. ret = starpu_init(NULL);
  69. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  71. #ifdef STARPU_USE_CUDA
  72. dotest(&cuda_cl);
  73. #endif
  74. #ifdef STARPU_USE_OPENCL
  75. dotest(&opencl_cl);
  76. #endif
  77. starpu_shutdown();
  78. return 0;
  79. }