opencl_codelet_unsigned_inc.c 1.6 KB

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