copy.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include "../common/helper.h"
  19. static unsigned nloops = 1000;
  20. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  21. {
  22. }
  23. static starpu_codelet cpu_codelet =
  24. {
  25. .where = STARPU_CPU,
  26. .cpu_func = dummy_func,
  27. .model = NULL,
  28. .nbuffers = 1
  29. };
  30. static starpu_codelet gpu_codelet =
  31. {
  32. .where = STARPU_CUDA|STARPU_OPENCL,
  33. .cuda_func = dummy_func,
  34. .opencl_func = dummy_func,
  35. .model = NULL,
  36. .nbuffers = 1
  37. };
  38. int main(int argc, char **argv)
  39. {
  40. float foo;
  41. starpu_data_handle float_array_handle;
  42. int i, ret;
  43. ret = starpu_init(NULL);
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  45. if (starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) == 0 && starpu_worker_get_count_by_type(STARPU_OPENCL_WORKER) == 0)
  46. {
  47. FPRINTF(stderr, "This application requires a CUDA or OpenCL Worker\n");
  48. starpu_shutdown();
  49. return 77;
  50. }
  51. foo = 0.0f;
  52. starpu_variable_data_register(&float_array_handle, 0, (uintptr_t)&foo, sizeof(foo));
  53. for (i = 0; i < nloops; i++)
  54. {
  55. struct starpu_task *task_cpu, *task_gpu;
  56. int ret;
  57. task_cpu = starpu_task_create();
  58. task_gpu = starpu_task_create();
  59. task_cpu->cl = &cpu_codelet;
  60. task_cpu->callback_func = NULL;
  61. task_cpu->buffers[0].handle = float_array_handle;
  62. task_cpu->buffers[0].mode = STARPU_RW;
  63. task_gpu->cl = &gpu_codelet;
  64. task_gpu->callback_func = NULL;
  65. task_gpu->buffers[0].handle = float_array_handle;
  66. task_gpu->buffers[0].mode = STARPU_RW;
  67. ret = starpu_task_submit(task_cpu);
  68. if (ret == -ENODEV) goto enodev;
  69. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  70. ret = starpu_task_submit(task_gpu);
  71. if (ret == -ENODEV) goto enodev;
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  73. }
  74. ret = starpu_task_wait_for_all();
  75. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  76. starpu_data_unregister(float_array_handle);
  77. starpu_shutdown();
  78. return 0;
  79. enodev:
  80. starpu_data_unregister(float_array_handle);
  81. fprintf(stderr, "WARNING: No one can execute this task\n");
  82. /* yes, we do not perform the computation but we did detect that no one
  83. * could perform the kernel, so this is not an error from StarPU */
  84. starpu_shutdown();
  85. return 77;
  86. }