cache.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2014 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  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. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
  20. static void codelet(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  21. {
  22. FPRINTF(stderr, "%lx\n", (unsigned long) STARPU_VARIABLE_GET_PTR(descr[0]));
  23. FPRINTF(stderr, "codelet\n");
  24. }
  25. #endif
  26. #ifdef STARPU_USE_CUDA
  27. static struct starpu_codelet cuda_cl =
  28. {
  29. .cuda_funcs = {codelet},
  30. .nbuffers = 1,
  31. .modes = {STARPU_R}
  32. };
  33. #endif
  34. #ifdef STARPU_USE_OPENCL
  35. static struct starpu_codelet opencl_cl =
  36. {
  37. .opencl_funcs = {codelet},
  38. .nbuffers = 1,
  39. .modes = {STARPU_R}
  40. };
  41. #endif
  42. void dotest(struct starpu_codelet *cl)
  43. {
  44. int ret;
  45. int var = 42;
  46. starpu_data_handle_t handle;
  47. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  48. ret = starpu_task_insert(cl, STARPU_R, handle, 0);
  49. if (ret == -ENODEV) goto enodev;
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  51. starpu_task_wait_for_all();
  52. starpu_data_unregister(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. enodev:
  59. starpu_data_unregister(handle);
  60. }
  61. int main(int argc, char **argv)
  62. {
  63. int ret;
  64. ret = starpu_init(NULL);
  65. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  67. #ifdef STARPU_USE_CUDA
  68. dotest(&cuda_cl);
  69. #endif
  70. #ifdef STARPU_USE_OPENCL
  71. dotest(&opencl_cl);
  72. #endif
  73. starpu_shutdown();
  74. return 0;
  75. enodev:
  76. starpu_shutdown();
  77. /* yes, we do not perform the computation but we did detect that no one
  78. * could perform the kernel, so this is not an error from StarPU */
  79. fprintf(stderr, "WARNING: No one can execute this task\n");
  80. return STARPU_TEST_SKIPPED;
  81. }