unpartition.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2010-2014,2016 Université de Bordeaux
  5. * Copyright (C) 2010 Mehdi Juhoor
  6. * Copyright (C) 2010-2013,2015,2017 CNRS
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #include <stdio.h>
  20. #include <unistd.h>
  21. #include <errno.h>
  22. #include <starpu.h>
  23. #include <stdlib.h>
  24. #include "../helper.h"
  25. /*
  26. * Test running a task on a partitioned data, then on the unpartitioned
  27. * data, etc. in a loop
  28. */
  29. #ifdef STARPU_QUICK_CHECK
  30. #define NITER 100
  31. #else
  32. #define NITER 1000
  33. #endif
  34. #define VECTORSIZE 1024
  35. float *buffer;
  36. starpu_data_handle_t v_handle;
  37. void dummy_codelet(void *descr[], void *_args)
  38. {
  39. (void)descr;
  40. (void)_args;
  41. }
  42. static struct starpu_codelet cl =
  43. {
  44. .modes = { STARPU_RW },
  45. .cpu_funcs = {dummy_codelet},
  46. #ifdef STARPU_USE_CUDA
  47. .cuda_funcs = {dummy_codelet},
  48. #endif
  49. #ifdef STARPU_USE_OPENCL
  50. .opencl_funcs = {dummy_codelet},
  51. #endif
  52. .cpu_funcs_name = {"dummy_codelet"},
  53. .nbuffers = 1
  54. };
  55. static
  56. struct starpu_task* create_task(starpu_data_handle_t handle)
  57. {
  58. struct starpu_task *task;
  59. task = starpu_task_create();
  60. task->cl = &cl;
  61. task->handles[0] = handle;
  62. task->detach = 0;
  63. return task;
  64. }
  65. int main(int argc, char **argv)
  66. {
  67. int ret;
  68. ret = starpu_initialize(NULL, &argc, &argv);
  69. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  71. ret = starpu_malloc((void **)&buffer, VECTORSIZE);
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
  73. starpu_vector_data_register(&v_handle, STARPU_MAIN_RAM, (uintptr_t)buffer, VECTORSIZE, sizeof(char));
  74. struct starpu_data_filter f =
  75. {
  76. .filter_func = starpu_vector_filter_divide_in_2,
  77. /* there are only 2 children */
  78. .nchildren = 2,
  79. /* the length of the first part */
  80. .filter_arg = VECTORSIZE/2
  81. };
  82. unsigned iter;
  83. for (iter = 0; iter < NITER; iter++)
  84. {
  85. struct starpu_task *tasks[3];
  86. starpu_data_map_filters(v_handle, 1, &f);
  87. tasks[0] = create_task(starpu_data_get_sub_data(v_handle, 1, 0));
  88. ret = starpu_task_submit(tasks[0]);
  89. if (ret == -ENODEV) goto enodev;
  90. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  91. tasks[1] = create_task(starpu_data_get_sub_data(v_handle, 1, 1));
  92. ret = starpu_task_submit(tasks[1]);
  93. if (ret == -ENODEV) goto enodev;
  94. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  95. ret = starpu_task_wait_for_all();
  96. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  97. starpu_data_unpartition(v_handle, STARPU_MAIN_RAM);
  98. tasks[2] = create_task(v_handle);
  99. ret = starpu_task_submit(tasks[2]);
  100. if (ret == -ENODEV) goto enodev;
  101. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  102. ret = starpu_task_wait_for_all();
  103. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  104. starpu_task_destroy(tasks[0]);
  105. starpu_task_destroy(tasks[1]);
  106. starpu_task_destroy(tasks[2]);
  107. }
  108. starpu_data_unregister(v_handle);
  109. starpu_free(buffer);
  110. starpu_shutdown();
  111. return EXIT_SUCCESS;
  112. enodev:
  113. starpu_data_unregister(v_handle);
  114. starpu_free(buffer);
  115. starpu_shutdown();
  116. fprintf(stderr, "WARNING: No one can execute this task\n");
  117. /* yes, we do not perform the computation but we did detect that no one
  118. * could perform the kernel, so this is not an error from StarPU */
  119. return STARPU_TEST_SKIPPED;
  120. }