same_handle.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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 "generic.h"
  18. #include "../../../../helper.h"
  19. /*
  20. * A single handle can be given twice to a given kernel. In this case, it
  21. * should only be converted once.
  22. */
  23. extern struct stats global_stats;
  24. static int vector[NX]; static starpu_data_handle_t handle;
  25. static struct starpu_codelet cl =
  26. {
  27. .modes = { STARPU_RW, STARPU_RW },
  28. #ifdef STARPU_USE_CUDA
  29. .cuda_funcs = { cuda_func, NULL },
  30. #endif
  31. #ifdef STARPU_USE_OPENCL
  32. .opencl_funcs = { opencl_func, NULL },
  33. #endif
  34. .nbuffers = 2,
  35. };
  36. static void
  37. register_handle(void)
  38. {
  39. int i;
  40. for (i = 0; i < NX; i++)
  41. vector[i] = i;
  42. starpu_multiformat_data_register(&handle, 0, vector, NX, &ops);
  43. }
  44. static void
  45. unregister_handle(void)
  46. {
  47. starpu_data_unregister(handle);
  48. }
  49. static int
  50. create_and_submit_tasks(void)
  51. {
  52. int ret;
  53. struct starpu_task *task;
  54. cl.where = 0;
  55. #ifdef STARPU_USE_CUDA
  56. cl.where |= STARPU_CUDA;
  57. #endif
  58. #ifdef STARPU_USE_OPENCL
  59. cl.where |= STARPU_OPENCL;
  60. #endif
  61. task = starpu_task_create();
  62. task->cl = &cl;
  63. task->handles[0] = handle;
  64. task->handles[1] = handle;
  65. ret = starpu_task_submit(task);
  66. if (ret == -ENODEV)
  67. return -ENODEV;
  68. return 0;
  69. }
  70. int
  71. main(void)
  72. {
  73. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
  74. int err;
  75. err = starpu_init(NULL);
  76. if (err == -ENODEV)
  77. goto enodev;
  78. reset_stats(&global_stats);
  79. register_handle();
  80. err = create_and_submit_tasks();
  81. unregister_handle();
  82. starpu_shutdown();
  83. if (err == -ENODEV)
  84. goto enodev;
  85. #if defined(STARPU_USE_CUDA)
  86. if (global_stats.cuda == 1)
  87. {
  88. if (global_stats.cpu_to_cuda == 1 &&
  89. global_stats.cuda_to_cpu == 1)
  90. return EXIT_SUCCESS;
  91. else
  92. return EXIT_FAILURE;
  93. }
  94. else
  95. #endif
  96. #if defined(STARPU_USE_OPENCL)
  97. if (global_stats.opencl == 1)
  98. {
  99. if (global_stats.cpu_to_opencl == 1 &&
  100. global_stats.opencl_to_cpu == 1)
  101. return EXIT_SUCCESS;
  102. else
  103. return EXIT_FAILURE;
  104. }
  105. else
  106. #endif
  107. {
  108. /* We should not get here */
  109. return EXIT_FAILURE;
  110. }
  111. enodev:
  112. #endif
  113. return STARPU_TEST_SKIPPED;
  114. }