deprecated_func.c 3.5 KB

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