opencl_codelet_unsigned_inc.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Inria
  4. * Copyright (C) 2012,2015-2017 CNRS
  5. * Copyright (C) 2014,2016 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. /*
  20. * Queue an OpenCL kernel which just increments a variable
  21. */
  22. extern struct starpu_opencl_program opencl_program;
  23. void opencl_codelet_unsigned_inc(void *buffers[], void *args)
  24. {
  25. (void) args;
  26. int id, devid;
  27. cl_int err;
  28. cl_kernel kernel;
  29. cl_command_queue queue;
  30. cl_mem val = (cl_mem) STARPU_VARIABLE_GET_PTR(buffers[0]);
  31. id = starpu_worker_get_id_check();
  32. devid = starpu_worker_get_devid(id);
  33. err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_program, "_opencl_unsigned_inc", devid);
  34. if (err != CL_SUCCESS)
  35. STARPU_OPENCL_REPORT_ERROR(err);
  36. err = clSetKernelArg(kernel, 0, sizeof(val), &val);
  37. if (err)
  38. STARPU_OPENCL_REPORT_ERROR(err);
  39. {
  40. size_t global=1;
  41. size_t local=1;
  42. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);
  43. if (err != CL_SUCCESS)
  44. STARPU_OPENCL_REPORT_ERROR(err);
  45. }
  46. starpu_opencl_release_kernel(kernel);
  47. }