copy.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013,2016,2017 Inria
  4. * Copyright (C) 2010-2013,2015,2017 CNRS
  5. * Copyright (C) 2010,2011,2013,2014,2016 Université de Bordeaux
  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 <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Trigger a lot of transfers of a single variable between CPUs and GPUs
  22. */
  23. #ifdef STARPU_QUICK_CHECK
  24. static unsigned nloops = 10;
  25. #else
  26. static unsigned nloops = 1000;
  27. #endif
  28. void dummy_func(void *descr[], void *arg)
  29. {
  30. (void)descr;
  31. (void)arg;
  32. }
  33. static struct starpu_codelet cpu_codelet =
  34. {
  35. .cpu_funcs = {dummy_func},
  36. .cpu_funcs_name = {"dummy_func"},
  37. .model = NULL,
  38. .nbuffers = 1,
  39. .modes = {STARPU_RW}
  40. };
  41. static struct starpu_codelet gpu_codelet =
  42. {
  43. .cuda_funcs = {dummy_func},
  44. .opencl_funcs = {dummy_func},
  45. .model = NULL,
  46. .nbuffers = 1,
  47. .modes = {STARPU_RW}
  48. };
  49. int main(int argc, char **argv)
  50. {
  51. float foo;
  52. starpu_data_handle_t float_array_handle;
  53. unsigned i;
  54. int ret;
  55. ret = starpu_initialize(NULL, &argc, &argv);
  56. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  58. if (starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) == 0 && starpu_worker_get_count_by_type(STARPU_OPENCL_WORKER) == 0 &&
  59. starpu_worker_get_count_by_type(STARPU_MIC_WORKER) == 0 && starpu_worker_get_count_by_type(STARPU_MPI_MS_WORKER) == 0)
  60. {
  61. FPRINTF(stderr, "This application requires a CUDA , OpenCL or MIC Worker\n");
  62. starpu_shutdown();
  63. return STARPU_TEST_SKIPPED;
  64. }
  65. foo = 0.0f;
  66. starpu_variable_data_register(&float_array_handle, STARPU_MAIN_RAM, (uintptr_t)&foo, sizeof(foo));
  67. for (i = 0; i < nloops; i++)
  68. {
  69. struct starpu_task *task_cpu, *task_gpu;
  70. task_cpu = starpu_task_create();
  71. task_gpu = starpu_task_create();
  72. task_cpu->cl = &cpu_codelet;
  73. task_cpu->callback_func = NULL;
  74. task_cpu->handles[0] = float_array_handle;
  75. task_gpu->cl = &gpu_codelet;
  76. task_gpu->callback_func = NULL;
  77. task_gpu->handles[0] = float_array_handle;
  78. ret = starpu_task_submit(task_cpu);
  79. if (ret == -ENODEV) goto enodev;
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  81. ret = starpu_task_submit(task_gpu);
  82. if (ret == -ENODEV) goto enodev;
  83. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  84. }
  85. ret = starpu_task_wait_for_all();
  86. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  87. starpu_data_unregister(float_array_handle);
  88. starpu_shutdown();
  89. return EXIT_SUCCESS;
  90. enodev:
  91. starpu_data_unregister(float_array_handle);
  92. fprintf(stderr, "WARNING: No one can execute this task\n");
  93. /* yes, we do not perform the computation but we did detect that no one
  94. * could perform the kernel, so this is not an error from StarPU */
  95. starpu_shutdown();
  96. return STARPU_TEST_SKIPPED;
  97. }