cache.c 2.3 KB

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