cache.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 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[], STARPU_ATTRIBUTE_UNUSED void *_args)
  24. {
  25. FPRINTF(stderr, "%lx\n", (unsigned long) STARPU_VARIABLE_GET_PTR(descr[0]));
  26. FPRINTF(stderr, "codelet\n");
  27. }
  28. #endif
  29. #ifdef STARPU_USE_CUDA
  30. static struct starpu_codelet cuda_cl =
  31. {
  32. .cuda_funcs = {codelet},
  33. .nbuffers = 1,
  34. .modes = {STARPU_R}
  35. };
  36. #endif
  37. #ifdef STARPU_USE_OPENCL
  38. static struct starpu_codelet opencl_cl =
  39. {
  40. .opencl_funcs = {codelet},
  41. .nbuffers = 1,
  42. .modes = {STARPU_R}
  43. };
  44. #endif
  45. void dotest(struct starpu_codelet *cl)
  46. {
  47. int ret;
  48. int var = 42;
  49. starpu_data_handle_t handle;
  50. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  51. ret = starpu_task_insert(cl, STARPU_R, handle, 0);
  52. if (ret == -ENODEV) goto enodev;
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  54. starpu_task_wait_for_all();
  55. starpu_data_unregister(handle);
  56. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  57. ret = starpu_task_insert(cl, STARPU_R, handle, 0);
  58. if (ret == -ENODEV) goto enodev;
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  60. starpu_task_wait_for_all();
  61. enodev:
  62. starpu_data_unregister(handle);
  63. }
  64. int main(int argc, char **argv)
  65. {
  66. int ret;
  67. ret = starpu_init(NULL);
  68. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  69. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  70. #ifdef STARPU_USE_CUDA
  71. dotest(&cuda_cl);
  72. #endif
  73. #ifdef STARPU_USE_OPENCL
  74. dotest(&opencl_cl);
  75. #endif
  76. starpu_shutdown();
  77. return 0;
  78. }