variable_kernels_opencl.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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_code;
  19. void opencl_codelet(void *descr[], void *_args)
  20. {
  21. float *val = (float *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. cl_kernel kernel;
  23. cl_command_queue queue;
  24. int id, devid, err;
  25. id = starpu_worker_get_id();
  26. devid = starpu_worker_get_devid(id);
  27. err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_code, "variable", devid);
  28. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  29. err = 0;
  30. err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);
  31. if (err) STARPU_OPENCL_REPORT_ERROR(err);
  32. {
  33. size_t global=1;
  34. size_t local=1;
  35. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);
  36. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  37. }
  38. clFinish(queue);
  39. starpu_opencl_release_kernel(kernel);
  40. }