complex.c 3.6 KB

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