sync_and_notify_data_opencl.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <CL/cl.h>
  19. extern struct starpu_opencl_program opencl_code;
  20. void opencl_codelet_incA(void *descr[], __attribute__ ((unused)) void *_args)
  21. {
  22. unsigned *val = (unsigned *)STARPU_VECTOR_GET_PTR(descr[0]);
  23. cl_kernel kernel;
  24. cl_command_queue queue;
  25. int id, devid, err;
  26. id = starpu_worker_get_id();
  27. devid = starpu_worker_get_devid(id);
  28. err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_code, "incA", devid);
  29. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  30. err = 0;
  31. err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);
  32. if (err) STARPU_OPENCL_REPORT_ERROR(err);
  33. {
  34. size_t global=100;
  35. size_t local=100;
  36. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);
  37. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  38. }
  39. clFinish(queue);
  40. starpu_opencl_release_kernel(kernel);
  41. }
  42. void opencl_codelet_incC(void *descr[], __attribute__ ((unused)) void *_args)
  43. {
  44. unsigned *val = (unsigned *)STARPU_VECTOR_GET_PTR(descr[0]);
  45. cl_kernel kernel;
  46. cl_command_queue queue;
  47. int id, devid, err;
  48. id = starpu_worker_get_id();
  49. devid = starpu_worker_get_devid(id);
  50. err = starpu_opencl_load_kernel(&kernel, &queue, &opencl_code, "incC", devid);
  51. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  52. err = 0;
  53. err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);
  54. if (err) STARPU_OPENCL_REPORT_ERROR(err);
  55. {
  56. size_t global=100;
  57. size_t local=100;
  58. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);
  59. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  60. }
  61. clFinish(queue);
  62. starpu_opencl_release_kernel(kernel);
  63. }