unpartition.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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,
  30. .cpu_func = dummy_codelet,
  31. #ifdef USE_CUDA
  32. .cuda_func = dummy_codelet,
  33. #endif
  34. .nbuffers = 1
  35. };
  36. int use_handle(starpu_data_handle handle)
  37. {
  38. int ret;
  39. struct starpu_task *task;
  40. task = starpu_task_create();
  41. task->cl = &cl;
  42. task->buffers[0].handle = handle;
  43. task->buffers[0].mode = STARPU_RW;
  44. task->detach = 0;
  45. ret = starpu_submit_task(task);
  46. return ret;
  47. }
  48. int main(int argc, char **argv)
  49. {
  50. int ret;
  51. starpu_init(NULL);
  52. starpu_malloc_pinned_if_possible((void **)&buffer, VECTORSIZE);
  53. starpu_register_vector_data(&v_handle, 0, (uintptr_t)buffer, VECTORSIZE, sizeof(char));
  54. starpu_filter f = {
  55. .filter_func = starpu_divide_in_2_filter_func_vector,
  56. .filter_arg = VECTORSIZE/2
  57. };
  58. unsigned iter;
  59. for (iter = 0; iter < NITER; iter++)
  60. {
  61. starpu_map_filters(v_handle, 1, &f);
  62. ret = use_handle(starpu_get_sub_data(v_handle, 1, 0));
  63. if (ret == -ENODEV)
  64. goto enodev;
  65. ret = use_handle(starpu_get_sub_data(v_handle, 1, 1));
  66. if (ret == -ENODEV)
  67. goto enodev;
  68. starpu_wait_all_tasks();
  69. starpu_unpartition_data(v_handle, 0);
  70. ret = use_handle(v_handle);
  71. if (ret == -ENODEV)
  72. goto enodev;
  73. starpu_wait_all_tasks();
  74. }
  75. starpu_delete_data(v_handle);
  76. starpu_shutdown();
  77. return 0;
  78. enodev:
  79. fprintf(stderr, "WARNING: No one can execute this task\n");
  80. /* yes, we do not perform the computation but we did detect that no one
  81. * could perform the kernel, so this is not an error from StarPU */
  82. return 0;
  83. }