insert_task_where.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-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. extern void cuda_host_increment(void *descr[], void *_args);
  19. void cpu_increment(void *descr[], void *arg)
  20. {
  21. (void)arg;
  22. unsigned *var = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[0]);
  23. (*var) += 2;
  24. }
  25. static struct starpu_codelet my_codelet =
  26. {
  27. .cpu_funcs = {cpu_increment},
  28. .cpu_funcs_name = {"cpu_increment"},
  29. #ifdef STARPU_USE_CUDA
  30. .cuda_funcs = {cuda_host_increment},
  31. .cuda_flags = {STARPU_CUDA_ASYNC},
  32. #endif
  33. .modes = { STARPU_RW },
  34. .nbuffers = 1
  35. };
  36. int main(void)
  37. {
  38. starpu_data_handle_t data_handles[2];
  39. int x = 12;
  40. int y = 12;
  41. int ret, ret1, ret2;
  42. ret = starpu_init(NULL);
  43. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  45. starpu_variable_data_register(&data_handles[0], STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  46. starpu_variable_data_register(&data_handles[1], STARPU_MAIN_RAM, (uintptr_t)&y, sizeof(y));
  47. ret1 = starpu_task_insert(&my_codelet,
  48. STARPU_EXECUTE_WHERE, STARPU_CPU,
  49. STARPU_RW, data_handles[0],
  50. 0);
  51. if (ret1 != -ENODEV) STARPU_CHECK_RETURN_VALUE(ret1, "starpu_task_insert");
  52. ret2 = starpu_task_insert(&my_codelet,
  53. STARPU_EXECUTE_WHERE, STARPU_CUDA,
  54. STARPU_RW, data_handles[1],
  55. 0);
  56. if (ret2 != -ENODEV) STARPU_CHECK_RETURN_VALUE(ret2, "starpu_task_insert");
  57. starpu_data_unregister(data_handles[0]);
  58. starpu_data_unregister(data_handles[1]);
  59. starpu_shutdown();
  60. if (ret1 != -ENODEV)
  61. {
  62. if (x != 14)
  63. ret = 1;
  64. FPRINTF(stderr, "Value x = %d (expected 14)\n", x);
  65. }
  66. if (ret2 != -ENODEV)
  67. {
  68. if (y != 13)
  69. ret = 1;
  70. FPRINTF(stderr, "Value y = %d (expected 13)\n", y);
  71. }
  72. STARPU_RETURN(ret);
  73. }