unpartition.c 3.7 KB

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