unpartition.c 3.3 KB

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