multiformat_conversion_codelets.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 Inria
  4. * Copyright (C) 2012-2013,2015,2017 CNRS
  5. * Copyright (C) 2014 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "multiformat_types.h"
  20. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  21. #ifdef STARPU_USE_CUDA
  22. void cuda_to_cpu(void *buffers[], void *arg)
  23. {
  24. (void)arg;
  25. struct struct_of_arrays *src = STARPU_MULTIFORMAT_GET_CUDA_PTR(buffers[0]);
  26. struct point *dst = STARPU_MULTIFORMAT_GET_CPU_PTR(buffers[0]);
  27. int n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  28. int i;
  29. for (i = 0; i < n; i++)
  30. {
  31. dst[i].x = src->x[i];
  32. dst[i].y = src->y[i];
  33. }
  34. }
  35. extern void cpu_to_cuda_cuda_func(void *buffers[], void *args);
  36. struct starpu_codelet cpu_to_cuda_cl =
  37. {
  38. .cuda_funcs = {cpu_to_cuda_cuda_func},
  39. .cuda_flags = {STARPU_CUDA_ASYNC},
  40. .nbuffers = 1,
  41. .name = "codelet_cpu_to_cuda"
  42. };
  43. struct starpu_codelet cuda_to_cpu_cl =
  44. {
  45. .cpu_funcs = {cuda_to_cpu},
  46. .nbuffers = 1,
  47. .name = "codelet_cude_to_cpu"
  48. };
  49. #endif
  50. #ifdef STARPU_USE_OPENCL
  51. void opencl_to_cpu(void *buffers[], void *arg)
  52. {
  53. (void)arg;
  54. FPRINTF(stderr, "User Entering %s\n", __starpu_func__);
  55. struct struct_of_arrays *src = STARPU_MULTIFORMAT_GET_OPENCL_PTR(buffers[0]);
  56. struct point *dst = STARPU_MULTIFORMAT_GET_CPU_PTR(buffers[0]);
  57. int n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  58. int i;
  59. for (i = 0; i < n; i++)
  60. {
  61. dst[i].x = src->x[i];
  62. dst[i].y = src->y[i];
  63. }
  64. }
  65. extern void cpu_to_opencl_opencl_func(void *buffers[], void *args);
  66. struct starpu_codelet cpu_to_opencl_cl =
  67. {
  68. .opencl_funcs = {cpu_to_opencl_opencl_func},
  69. .opencl_flags = {STARPU_OPENCL_ASYNC},
  70. .nbuffers = 1
  71. };
  72. struct starpu_codelet opencl_to_cpu_cl =
  73. {
  74. .cpu_funcs = {opencl_to_cpu},
  75. .nbuffers = 1
  76. };
  77. #endif