deprecated_func.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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. /*
  19. * Test that we support the cpu_func and where deprecated field
  20. */
  21. void cpu_codelet(void *descr[], void *_args)
  22. {
  23. (void)_args;
  24. int *valin = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  25. int *valout = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  26. *valout = *valin;
  27. }
  28. void cpu2_codelet(void *descr[], void *_args)
  29. {
  30. (void)_args;
  31. int *valin = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  32. int *valout = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  33. *valout = *valin*2;
  34. }
  35. struct starpu_codelet cl_cpu_funcs =
  36. {
  37. .where = STARPU_CPU,
  38. .cpu_funcs = {cpu_codelet},
  39. .cpu_funcs_name = {"cpu_codelet"},
  40. .nbuffers = 2,
  41. .name = "cpu_funcs",
  42. };
  43. struct starpu_codelet cl_cpu_func =
  44. {
  45. .where = STARPU_CPU,
  46. .cpu_func = cpu_codelet,
  47. .cpu_funcs_name = {"cpu_codelet"},
  48. .nbuffers = 2,
  49. .name = "cpu_func",
  50. };
  51. struct starpu_codelet cl_cpu_multiple =
  52. {
  53. .where = STARPU_CPU,
  54. .cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS,
  55. .cpu_funcs = {cpu_codelet},
  56. .cpu_funcs_name = {"cpu_codelet"},
  57. .nbuffers = 2,
  58. .name = "cpu_multiple",
  59. };
  60. struct starpu_codelet cl_cpu_func_funcs =
  61. {
  62. .where = STARPU_CPU,
  63. .cpu_func = cpu2_codelet,
  64. .cpu_funcs = {cpu_codelet},
  65. .cpu_funcs_name = {"cpu_codelet"},
  66. .nbuffers = 2,
  67. .name = "cpu_func_funcs",
  68. };
  69. static
  70. int submit_codelet(struct starpu_codelet cl, int where)
  71. {
  72. int x=42, y=14;
  73. starpu_data_handle_t handles[2];
  74. int ret;
  75. starpu_variable_data_register(&handles[0], STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  76. starpu_variable_data_register(&handles[1], STARPU_MAIN_RAM, (uintptr_t)&y, sizeof(y));
  77. cl.where = where;
  78. ret = starpu_task_insert(&cl,
  79. STARPU_R, handles[0],
  80. STARPU_W, handles[1],
  81. 0);
  82. if (ret == -ENODEV)
  83. {
  84. FPRINTF(stderr, "cannot execute codelet <%s> with where=%d\n", cl.name, where);
  85. starpu_data_unregister(handles[0]);
  86. starpu_data_unregister(handles[1]);
  87. return ret;
  88. }
  89. starpu_task_wait_for_all();
  90. starpu_data_unregister(handles[0]);
  91. starpu_data_unregister(handles[1]);
  92. if (x != y)
  93. {
  94. FPRINTF(stderr, "error when executing codelet <%s> with where=%d\n", cl.name, where);
  95. }
  96. else
  97. {
  98. FPRINTF(stderr, "success when executing codelet <%s> with where=%d\n", cl.name, where);
  99. }
  100. return x != y;
  101. }
  102. int main(void)
  103. {
  104. int ret;
  105. unsigned where;
  106. ret = starpu_init(NULL);
  107. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  108. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  109. for(where=0 ; where<=STARPU_CPU ; where+=STARPU_CPU)
  110. {
  111. ret = submit_codelet(cl_cpu_func, where);
  112. if (ret == -ENODEV)
  113. {
  114. starpu_shutdown();
  115. fprintf(stderr, "WARNING: No one can execute this task\n");
  116. return STARPU_TEST_SKIPPED;
  117. }
  118. if (!ret)
  119. {
  120. ret = submit_codelet(cl_cpu_funcs, where);
  121. }
  122. if (!ret)
  123. {
  124. ret = submit_codelet(cl_cpu_multiple, where);
  125. }
  126. if (!ret)
  127. {
  128. ret = submit_codelet(cl_cpu_func_funcs, where);
  129. }
  130. }
  131. starpu_shutdown();
  132. STARPU_RETURN(ret);
  133. }