unpartition.c 3.2 KB

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