opencl_codelet_unsigned_inc.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 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 <starpu_opencl.h>
  18. extern struct starpu_opencl_program opencl_program;
  19. void opencl_codelet_unsigned_inc(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. cl_event event;
  27. cl_mem val = (cl_mem) STARPU_VARIABLE_GET_PTR(buffers[0]);
  28. id = starpu_worker_get_id();
  29. devid = starpu_worker_get_devid(id);
  30. err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_program, "_opencl_unsigned_inc", devid);
  31. if (err != CL_SUCCESS)
  32. STARPU_OPENCL_REPORT_ERROR(err);
  33. err = clSetKernelArg(kernel, 0, sizeof(val), &val);
  34. if (err)
  35. STARPU_OPENCL_REPORT_ERROR(err);
  36. {
  37. size_t global=1;
  38. size_t local;
  39. size_t s;
  40. cl_device_id device;
  41. starpu_opencl_get_device(devid, &device);
  42. err = clGetKernelWorkGroupInfo (kernel, device, CL_KERNEL_WORK_GROUP_SIZE, sizeof(local), &local, &s);
  43. if (err != CL_SUCCESS)
  44. STARPU_OPENCL_REPORT_ERROR(err);
  45. if (local > global)
  46. local=global;
  47. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, &event);
  48. if (err != CL_SUCCESS)
  49. STARPU_OPENCL_REPORT_ERROR(err);
  50. }
  51. clFinish(queue);
  52. starpu_opencl_collect_stats(event);
  53. clReleaseEvent(event);
  54. starpu_opencl_release_kernel(kernel);
  55. }