deprecated.c 3.0 KB

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