complex.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #ifdef STARPU_USE_OPENCL
  20. #include <starpu_opencl.h>
  21. #endif
  22. #ifdef STARPU_USE_CUDA
  23. extern void copy_complex_codelet_cuda(void *descr[], __attribute__ ((unused)) void *_args);
  24. #endif
  25. #ifdef STARPU_USE_OPENCL
  26. extern void copy_complex_codelet_opencl(void *buffers[], void *args);
  27. #endif
  28. struct starpu_codelet cl_copy =
  29. {
  30. #ifdef STARPU_USE_CUDA
  31. .cuda_funcs = {copy_complex_codelet_cuda, NULL},
  32. #endif
  33. #ifdef STARPU_USE_OPENCL
  34. .opencl_funcs = {copy_complex_codelet_opencl, NULL},
  35. #endif
  36. .nbuffers = 2,
  37. .modes = {STARPU_R, STARPU_W}
  38. };
  39. #ifdef STARPU_USE_OPENCL
  40. struct starpu_opencl_program opencl_program;
  41. #endif
  42. int main(int argc, char **argv)
  43. {
  44. int ret = 0;
  45. starpu_data_handle_t handle1;
  46. starpu_data_handle_t handle2;
  47. double real = 45.0;
  48. double imaginary = 12.0;
  49. double copy_real = 78.0;
  50. double copy_imaginary = 78.0;
  51. ret = starpu_init(NULL);
  52. if (ret == -ENODEV) return 77;
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  54. #ifdef STARPU_USE_OPENCL
  55. ret = starpu_opencl_load_opencl_from_file("examples/interface/complex_kernels.cl",
  56. &opencl_program, NULL);
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  58. #endif
  59. starpu_complex_data_register(&handle1, 0, &real, &imaginary, 1);
  60. starpu_complex_data_register(&handle2, 0, &copy_real, &copy_imaginary, 1);
  61. ret = starpu_insert_task(&cl_display, STARPU_R, handle1, 0);
  62. if (ret == -ENODEV) goto enodev;
  63. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  64. ret = starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
  65. if (ret == -ENODEV) goto enodev;
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  67. ret = starpu_insert_task(&cl_compare,
  68. STARPU_R, handle1,
  69. STARPU_R, handle2,
  70. 0);
  71. if (ret == -ENODEV) goto enodev;
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  73. ret = starpu_insert_task(&cl_copy,
  74. STARPU_R, handle1,
  75. STARPU_W, handle2,
  76. 0);
  77. if (ret == -ENODEV) goto enodev;
  78. STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");
  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. starpu_task_wait_for_all();
  92. #ifdef STARPU_USE_OPENCL
  93. ret = starpu_opencl_unload_opencl(&opencl_program);
  94. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
  95. #endif
  96. starpu_shutdown();
  97. return 0;
  98. enodev:
  99. #ifdef STARPU_USE_OPENCL
  100. ret = starpu_opencl_unload_opencl(&opencl_program);
  101. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
  102. #endif
  103. starpu_data_unregister(handle1);
  104. starpu_data_unregister(handle2);
  105. starpu_shutdown();
  106. return 77;
  107. }