copy.c 3.2 KB

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