insert_task_where.c 2.4 KB

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