cache.c 2.4 KB

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