unpartition.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
  5. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  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 <stdio.h>
  19. #include <unistd.h>
  20. #include <errno.h>
  21. #include <starpu.h>
  22. #include <stdlib.h>
  23. #include "../helper.h"
  24. #ifdef STARPU_QUICK_CHECK
  25. #define NITER 100
  26. #else
  27. #define NITER 1000
  28. #endif
  29. #define VECTORSIZE 1024
  30. float *buffer;
  31. starpu_data_handle_t v_handle;
  32. static
  33. void dummy_codelet(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  34. {
  35. }
  36. static struct starpu_codelet cl =
  37. {
  38. .modes = { STARPU_RW },
  39. .cpu_funcs = {dummy_codelet, NULL},
  40. #ifdef STARPU_USE_CUDA
  41. .cuda_funcs = {dummy_codelet, NULL},
  42. #endif
  43. #ifdef STARPU_USE_OPENCL
  44. .opencl_funcs = {dummy_codelet, NULL},
  45. #endif
  46. .cpu_funcs_name = {"dummy_codelet", NULL},
  47. .nbuffers = 1
  48. };
  49. static
  50. struct starpu_task* create_task(starpu_data_handle_t handle)
  51. {
  52. struct starpu_task *task;
  53. task = starpu_task_create();
  54. task->cl = &cl;
  55. task->handles[0] = handle;
  56. task->detach = 0;
  57. return task;
  58. }
  59. int main(int argc, char **argv)
  60. {
  61. int ret;
  62. ret = starpu_initialize(NULL, &argc, &argv);
  63. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  64. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  65. ret = starpu_malloc((void **)&buffer, VECTORSIZE);
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  67. starpu_vector_data_register(&v_handle, STARPU_MAIN_RAM, (uintptr_t)buffer, VECTORSIZE, sizeof(char));
  68. struct starpu_data_filter f =
  69. {
  70. .filter_func = starpu_vector_filter_divide_in_2,
  71. /* there are only 2 children */
  72. .nchildren = 2,
  73. /* the length of the first part */
  74. .filter_arg = VECTORSIZE/2
  75. };
  76. unsigned iter;
  77. for (iter = 0; iter < NITER; iter++)
  78. {
  79. struct starpu_task *tasks[3];
  80. starpu_data_map_filters(v_handle, 1, &f);
  81. tasks[0] = create_task(starpu_data_get_sub_data(v_handle, 1, 0));
  82. ret = starpu_task_submit(tasks[0]);
  83. if (ret == -ENODEV) goto enodev;
  84. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  85. tasks[1] = create_task(starpu_data_get_sub_data(v_handle, 1, 1));
  86. ret = starpu_task_submit(tasks[1]);
  87. if (ret == -ENODEV) goto enodev;
  88. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  89. ret = starpu_task_wait_for_all();
  90. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  91. starpu_data_unpartition(v_handle, STARPU_MAIN_RAM);
  92. tasks[2] = create_task(v_handle);
  93. ret = starpu_task_submit(tasks[2]);
  94. if (ret == -ENODEV) goto enodev;
  95. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  96. ret = starpu_task_wait_for_all();
  97. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  98. starpu_task_destroy(tasks[0]);
  99. starpu_task_destroy(tasks[1]);
  100. starpu_task_destroy(tasks[2]);
  101. }
  102. starpu_data_unregister(v_handle);
  103. starpu_free(buffer);
  104. starpu_shutdown();
  105. return EXIT_SUCCESS;
  106. enodev:
  107. starpu_data_unregister(v_handle);
  108. starpu_free(buffer);
  109. starpu_shutdown();
  110. fprintf(stderr, "WARNING: No one can execute this task\n");
  111. /* yes, we do not perform the computation but we did detect that no one
  112. * could perform the kernel, so this is not an error from StarPU */
  113. return STARPU_TEST_SKIPPED;
  114. }