unpartition.c 2.7 KB

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