copy.c 3.2 KB

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