unpartition.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <stdio.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #define NITER 1000
  22. #define VECTORSIZE 1024
  23. float *buffer;
  24. starpu_data_handle v_handle;
  25. static void dummy_codelet(void *descr[], __attribute__ ((unused)) void *_args)
  26. {
  27. }
  28. static starpu_codelet cl = {
  29. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  30. .cpu_func = dummy_codelet,
  31. #ifdef STARPU_USE_CUDA
  32. .cuda_func = dummy_codelet,
  33. #endif
  34. #ifdef STARPU_USE_OPENCL
  35. .opencl_func = dummy_codelet,
  36. #endif
  37. .nbuffers = 1
  38. };
  39. int use_handle(starpu_data_handle handle)
  40. {
  41. int ret;
  42. struct starpu_task *task;
  43. task = starpu_task_create();
  44. task->cl = &cl;
  45. task->buffers[0].handle = handle;
  46. task->buffers[0].mode = STARPU_RW;
  47. task->detach = 0;
  48. ret = starpu_task_submit(task);
  49. return ret;
  50. }
  51. int main(int argc, char **argv)
  52. {
  53. int ret;
  54. starpu_init(NULL);
  55. starpu_data_malloc_pinned_if_possible((void **)&buffer, VECTORSIZE);
  56. starpu_vector_data_register(&v_handle, 0, (uintptr_t)buffer, VECTORSIZE, sizeof(char));
  57. starpu_filter f = {
  58. .filter_func = starpu_vector_divide_in_2_filter_func,
  59. .filter_arg = VECTORSIZE/2
  60. };
  61. unsigned iter;
  62. for (iter = 0; iter < NITER; iter++)
  63. {
  64. starpu_map_filters(v_handle, 1, &f);
  65. ret = use_handle(starpu_data_get_sub_data(v_handle, 1, 0));
  66. if (ret == -ENODEV)
  67. goto enodev;
  68. ret = use_handle(starpu_data_get_sub_data(v_handle, 1, 1));
  69. if (ret == -ENODEV)
  70. goto enodev;
  71. starpu_task_wait_for_all();
  72. starpu_data_unpartition(v_handle, 0);
  73. ret = use_handle(v_handle);
  74. if (ret == -ENODEV)
  75. goto enodev;
  76. starpu_task_wait_for_all();
  77. }
  78. starpu_data_unregister(v_handle);
  79. starpu_shutdown();
  80. return 0;
  81. enodev:
  82. fprintf(stderr, "WARNING: No one can execute this task\n");
  83. /* yes, we do not perform the computation but we did detect that no one
  84. * could perform the kernel, so this is not an error from StarPU */
  85. return 0;
  86. }