deprecated_func.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012,2013 Inria
  4. * Copyright (C) 2010-2013,2015,2017 CNRS
  5. * Copyright (C) 2013-2016 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Test that we support the cpu_func and where deprecated field
  22. */
  23. void cpu_codelet(void *descr[], void *_args)
  24. {
  25. (void)_args;
  26. int *valin = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  27. int *valout = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  28. *valout = *valin;
  29. }
  30. void cpu2_codelet(void *descr[], void *_args)
  31. {
  32. (void)_args;
  33. int *valin = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  34. int *valout = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  35. *valout = *valin*2;
  36. }
  37. struct starpu_codelet cl_cpu_funcs =
  38. {
  39. .where = STARPU_CPU,
  40. .cpu_funcs = {cpu_codelet},
  41. .cpu_funcs_name = {"cpu_codelet"},
  42. .nbuffers = 2,
  43. .name = "cpu_funcs",
  44. };
  45. struct starpu_codelet cl_cpu_func =
  46. {
  47. .where = STARPU_CPU,
  48. .cpu_func = cpu_codelet,
  49. .cpu_funcs_name = {"cpu_codelet"},
  50. .nbuffers = 2,
  51. .name = "cpu_func",
  52. };
  53. struct starpu_codelet cl_cpu_multiple =
  54. {
  55. .where = STARPU_CPU,
  56. .cpu_func = STARPU_MULTIPLE_CPU_IMPLEMENTATIONS,
  57. .cpu_funcs = {cpu_codelet},
  58. .cpu_funcs_name = {"cpu_codelet"},
  59. .nbuffers = 2,
  60. .name = "cpu_multiple",
  61. };
  62. struct starpu_codelet cl_cpu_func_funcs =
  63. {
  64. .where = STARPU_CPU,
  65. .cpu_func = cpu2_codelet,
  66. .cpu_funcs = {cpu_codelet},
  67. .cpu_funcs_name = {"cpu_codelet"},
  68. .nbuffers = 2,
  69. .name = "cpu_func_funcs",
  70. };
  71. static
  72. int submit_codelet(struct starpu_codelet cl, int where)
  73. {
  74. int x=42, y=14;
  75. starpu_data_handle_t handles[2];
  76. int ret;
  77. starpu_variable_data_register(&handles[0], STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  78. starpu_variable_data_register(&handles[1], STARPU_MAIN_RAM, (uintptr_t)&y, sizeof(y));
  79. cl.where = where;
  80. ret = starpu_task_insert(&cl,
  81. STARPU_R, handles[0],
  82. STARPU_W, handles[1],
  83. 0);
  84. if (ret == -ENODEV)
  85. {
  86. FPRINTF(stderr, "cannot execute codelet <%s> with where=%d\n", cl.name, where);
  87. starpu_data_unregister(handles[0]);
  88. starpu_data_unregister(handles[1]);
  89. return ret;
  90. }
  91. starpu_task_wait_for_all();
  92. starpu_data_unregister(handles[0]);
  93. starpu_data_unregister(handles[1]);
  94. if (x != y)
  95. {
  96. FPRINTF(stderr, "error when executing codelet <%s> with where=%d\n", cl.name, where);
  97. }
  98. else
  99. {
  100. FPRINTF(stderr, "success when executing codelet <%s> with where=%d\n", cl.name, where);
  101. }
  102. return x != y;
  103. }
  104. int main(void)
  105. {
  106. int ret;
  107. unsigned where;
  108. ret = starpu_init(NULL);
  109. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  110. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  111. for(where=0 ; where<=STARPU_CPU ; where+=STARPU_CPU)
  112. {
  113. ret = submit_codelet(cl_cpu_func, where);
  114. if (ret == -ENODEV)
  115. {
  116. starpu_shutdown();
  117. fprintf(stderr, "WARNING: No one can execute this task\n");
  118. return STARPU_TEST_SKIPPED;
  119. }
  120. if (!ret)
  121. {
  122. ret = submit_codelet(cl_cpu_funcs, where);
  123. }
  124. if (!ret)
  125. {
  126. ret = submit_codelet(cl_cpu_multiple, where);
  127. }
  128. if (!ret)
  129. {
  130. ret = submit_codelet(cl_cpu_func_funcs, where);
  131. }
  132. }
  133. starpu_shutdown();
  134. STARPU_RETURN(ret);
  135. }