complex_kernels_opencl.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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 "complex_interface.h"
  18. extern struct starpu_opencl_program opencl_program;
  19. void copy_complex_codelet_opencl(void *buffers[], void *_args)
  20. {
  21. (void) _args;
  22. int id, devid;
  23. cl_int err;
  24. cl_kernel kernel;
  25. cl_command_queue queue;
  26. /* length of the vector */
  27. unsigned n = STARPU_COMPLEX_GET_NX(buffers[0]);
  28. /* OpenCL copy of the vector pointer */
  29. cl_mem i_real = (cl_mem) STARPU_COMPLEX_GET_REAL(buffers[0]);
  30. cl_mem i_imaginary = (cl_mem) STARPU_COMPLEX_GET_IMAGINARY(buffers[0]);
  31. cl_mem o_real = (cl_mem) STARPU_COMPLEX_GET_REAL(buffers[1]);
  32. cl_mem o_imaginary = (cl_mem) STARPU_COMPLEX_GET_IMAGINARY(buffers[1]);
  33. id = starpu_worker_get_id_check();
  34. devid = starpu_worker_get_devid(id);
  35. err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_program, "complex_copy_opencl", devid);
  36. if (err != CL_SUCCESS)
  37. STARPU_OPENCL_REPORT_ERROR(err);
  38. err = clSetKernelArg(kernel, 0, sizeof(o_real), &o_real);
  39. err|= clSetKernelArg(kernel, 1, sizeof(o_imaginary), &o_imaginary);
  40. err|= clSetKernelArg(kernel, 2, sizeof(i_real), &i_real);
  41. err|= clSetKernelArg(kernel, 3, sizeof(i_imaginary), &i_imaginary);
  42. err|= clSetKernelArg(kernel, 4, sizeof(n), &n);
  43. if (err)
  44. STARPU_OPENCL_REPORT_ERROR(err);
  45. {
  46. size_t global=n;
  47. size_t local;
  48. size_t s;
  49. cl_device_id device;
  50. starpu_opencl_get_device(devid, &device);
  51. err = clGetKernelWorkGroupInfo (kernel, device, CL_KERNEL_WORK_GROUP_SIZE, sizeof(local), &local, &s);
  52. if (err != CL_SUCCESS)
  53. STARPU_OPENCL_REPORT_ERROR(err);
  54. if (local > global)
  55. local=global;
  56. else
  57. global = (global + local-1) / local * local;
  58. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);
  59. if (err != CL_SUCCESS)
  60. STARPU_OPENCL_REPORT_ERROR(err);
  61. }
  62. starpu_opencl_release_kernel(kernel);
  63. }