variable_kernels_opencl.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  4. * Copyright (C) 2011 Université de Bordeaux 1
  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. #include <starpu_opencl.h>
  19. extern struct starpu_opencl_program opencl_program;
  20. void opencl_codelet(void *descr[], void *_args)
  21. {
  22. float *val = (float *)STARPU_VARIABLE_GET_PTR(descr[0]);
  23. cl_kernel kernel;
  24. cl_command_queue queue;
  25. cl_event event;
  26. int id, devid, err;
  27. id = starpu_worker_get_id();
  28. devid = starpu_worker_get_devid(id);
  29. err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_program, "variable", devid);
  30. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  31. err = 0;
  32. err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);
  33. if (err) STARPU_OPENCL_REPORT_ERROR(err);
  34. {
  35. size_t global=1;
  36. size_t local=1;
  37. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, &event);
  38. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  39. }
  40. clFinish(queue);
  41. starpu_opencl_collect_stats(event);
  42. clReleaseEvent(event);
  43. starpu_opencl_release_kernel(kernel);
  44. }