complex.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Centre National de la Recherche Scientifique
  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 "complex_interface.h"
  18. #include "complex_codelet.h"
  19. static int can_execute(unsigned workerid, struct starpu_task *task, unsigned nimpl)
  20. {
  21. if (starpu_worker_get_type(workerid) == STARPU_OPENCL_WORKER)
  22. return 1;
  23. #ifdef STARPU_USE_CUDA
  24. /* Cuda device */
  25. const struct cudaDeviceProp *props;
  26. props = starpu_cuda_get_device_properties(workerid);
  27. if (props->major >= 2 || props->minor >= 3)
  28. {
  29. /* At least compute capability 1.3, supports doubles */
  30. return 1;
  31. }
  32. else
  33. {
  34. /* Old card does not support doubles */
  35. return 0;
  36. }
  37. #endif
  38. }
  39. #ifdef STARPU_USE_CUDA
  40. extern void copy_complex_codelet_cuda(void *descr[], __attribute__ ((unused)) void *_args);
  41. #endif
  42. #ifdef STARPU_USE_OPENCL
  43. extern void copy_complex_codelet_opencl(void *buffers[], void *args);
  44. #endif
  45. struct starpu_codelet cl_copy =
  46. {
  47. #ifdef STARPU_USE_CUDA
  48. .cuda_funcs = {copy_complex_codelet_cuda, NULL},
  49. #endif
  50. #ifdef STARPU_USE_OPENCL
  51. .opencl_funcs = {copy_complex_codelet_opencl, NULL},
  52. #endif
  53. .nbuffers = 2,
  54. .modes = {STARPU_R, STARPU_W},
  55. .can_execute = can_execute
  56. };
  57. #ifdef STARPU_USE_OPENCL
  58. struct starpu_opencl_program opencl_program;
  59. #endif
  60. int main(int argc, char **argv)
  61. {
  62. int ret = 0;
  63. starpu_data_handle_t handle1;
  64. starpu_data_handle_t handle2;
  65. double real = 45.0;
  66. double imaginary = 12.0;
  67. double copy_real = 78.0;
  68. double copy_imaginary = 78.0;
  69. ret = starpu_init(NULL);
  70. if (ret == -ENODEV) return 77;
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  72. #ifdef STARPU_USE_OPENCL
  73. ret = starpu_opencl_load_opencl_from_file("examples/interface/complex_kernels.cl",
  74. &opencl_program, NULL);
  75. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  76. #endif
  77. starpu_complex_data_register(&handle1, 0, &real, &imaginary, 1);
  78. starpu_complex_data_register(&handle2, 0, &copy_real, &copy_imaginary, 1);
  79. ret = starpu_insert_task(&cl_display, STARPU_R, handle1, 0);
  80. if (ret == -ENODEV) goto enodev;
  81. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  82. ret = starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
  83. if (ret == -ENODEV) goto enodev;
  84. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  85. ret = starpu_insert_task(&cl_compare,
  86. STARPU_R, handle1,
  87. STARPU_R, handle2,
  88. 0);
  89. if (ret == -ENODEV) goto enodev;
  90. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  91. ret = starpu_insert_task(&cl_copy,
  92. STARPU_R, handle1,
  93. STARPU_W, handle2,
  94. 0);
  95. if (ret == -ENODEV) goto enodev;
  96. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  97. ret = starpu_insert_task(&cl_display, STARPU_R, handle1, 0);
  98. if (ret == -ENODEV) goto enodev;
  99. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  100. ret = starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
  101. if (ret == -ENODEV) goto enodev;
  102. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  103. ret = starpu_insert_task(&cl_compare,
  104. STARPU_R, handle1,
  105. STARPU_R, handle2,
  106. 0);
  107. if (ret == -ENODEV) goto enodev;
  108. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  109. #warning get the comparison result and return it as the application return code
  110. starpu_task_wait_for_all();
  111. #ifdef STARPU_USE_OPENCL
  112. ret = starpu_opencl_unload_opencl(&opencl_program);
  113. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
  114. #endif
  115. starpu_shutdown();
  116. return 0;
  117. enodev:
  118. #ifdef STARPU_USE_OPENCL
  119. ret = starpu_opencl_unload_opencl(&opencl_program);
  120. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
  121. #endif
  122. starpu_data_unregister(handle1);
  123. starpu_data_unregister(handle2);
  124. starpu_shutdown();
  125. return 77;
  126. }