opencl_codelet_unsigned_inc.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 INRIA
  4. * Copyright (C) 2016 CNRS
  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. /*
  19. * Queue an OpenCL kernel which just increments a variable
  20. */
  21. extern struct starpu_opencl_program opencl_program;
  22. void opencl_codelet_unsigned_inc(void *buffers[], void *args)
  23. {
  24. (void) args;
  25. int id, devid;
  26. cl_int err;
  27. cl_kernel kernel;
  28. cl_command_queue queue;
  29. cl_mem val = (cl_mem) STARPU_VARIABLE_GET_PTR(buffers[0]);
  30. id = starpu_worker_get_id_check();
  31. devid = starpu_worker_get_devid(id);
  32. err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_program, "_opencl_unsigned_inc", devid);
  33. if (err != CL_SUCCESS)
  34. STARPU_OPENCL_REPORT_ERROR(err);
  35. err = clSetKernelArg(kernel, 0, sizeof(val), &val);
  36. if (err)
  37. 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, NULL);
  42. if (err != CL_SUCCESS)
  43. STARPU_OPENCL_REPORT_ERROR(err);
  44. }
  45. starpu_opencl_release_kernel(kernel);
  46. }