vector_scal_opencl.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  4. * Copyright (C) 2010, 2011 Université de Bordeaux 1
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <starpu_opencl.h>
  19. extern struct starpu_opencl_program programs;
  20. void scal_opencl_func(void *buffers[], void *_args)
  21. {
  22. float *factor = _args;
  23. int id, devid, err;
  24. cl_kernel kernel;
  25. cl_command_queue queue;
  26. cl_event event;
  27. /* length of the vector */
  28. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  29. /* OpenCL copy of the vector pointer */
  30. cl_mem val = (cl_mem) STARPU_VECTOR_GET_PTR(buffers[0]);
  31. id = starpu_worker_get_id();
  32. devid = starpu_worker_get_devid(id);
  33. err = starpu_opencl_load_kernel(&kernel, &queue, &programs,
  34. "vector_mult_opencl", devid); /* Name of the codelet defined above */
  35. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  36. err = clSetKernelArg(kernel, 0, sizeof(val), &val);
  37. err |= clSetKernelArg(kernel, 1, sizeof(n), &n);
  38. err |= clSetKernelArg(kernel, 2, sizeof(*factor), factor);
  39. if (err) STARPU_OPENCL_REPORT_ERROR(err);
  40. {
  41. size_t global=1;
  42. size_t local=1;
  43. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, &event);
  44. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  45. }
  46. clFinish(queue);
  47. starpu_opencl_collect_stats(event);
  48. clReleaseEvent(event);
  49. starpu_opencl_release_kernel(kernel);
  50. }