deprecated_func.c 3.4 KB

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