vector_scal_opencl.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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. extern struct starpu_opencl_program programs;
  18. void vector_scal_opencl(void *buffers[], void *_args)
  19. {
  20. float *factor = _args;
  21. int id, devid, err;
  22. cl_kernel kernel;
  23. cl_command_queue queue;
  24. cl_event event;
  25. /* length of the vector */
  26. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  27. /* OpenCL copy of the vector pointer */
  28. cl_mem val = (cl_mem) STARPU_VECTOR_GET_DEV_HANDLE(buffers[0]);
  29. id = starpu_worker_get_id();
  30. devid = starpu_worker_get_devid(id);
  31. err = starpu_opencl_load_kernel(&kernel, &queue, &programs,
  32. "vector_mult_opencl", devid); /* Name of the codelet defined above */
  33. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  34. err = clSetKernelArg(kernel, 0, sizeof(val), &val);
  35. err |= clSetKernelArg(kernel, 1, sizeof(n), &n);
  36. err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);
  37. if (err) STARPU_OPENCL_REPORT_ERROR(err);
  38. {
  39. size_t global=1;
  40. size_t local=1;
  41. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, &event);
  42. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  43. }
  44. clFinish(queue);
  45. starpu_opencl_collect_stats(event);
  46. clReleaseEvent(event);
  47. starpu_opencl_release_kernel(kernel);
  48. }