sync_and_notify_data_opencl.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 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. void opencl_codelet_incA(void *descr[], __attribute__ ((unused)) void *_args)
  20. {
  21. unsigned *val = (unsigned *)STARPU_GET_VECTOR_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, "tests/datawizard/sync_and_notify_data_opencl_codelet.cl", "incA", 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=100;
  34. size_t local=100;
  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);
  40. }
  41. void opencl_codelet_incC(void *descr[], __attribute__ ((unused)) void *_args)
  42. {
  43. unsigned *val = (unsigned *)STARPU_GET_VECTOR_PTR(descr[0]);
  44. cl_kernel kernel;
  45. cl_command_queue queue;
  46. int id, devid, err;
  47. id = starpu_worker_get_id();
  48. devid = starpu_worker_get_devid(id);
  49. err = starpu_opencl_load_kernel(&kernel, &queue, "tests/datawizard/sync_and_notify_data_opencl_codelet.cl", "incC", devid);
  50. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  51. err = 0;
  52. err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &val);
  53. if (err) STARPU_OPENCL_REPORT_ERROR(err);
  54. {
  55. size_t global=100;
  56. size_t local=100;
  57. err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 0, NULL, NULL);
  58. if (err != CL_SUCCESS) STARPU_OPENCL_REPORT_ERROR(err);
  59. }
  60. clFinish(queue);
  61. starpu_opencl_release(kernel);
  62. }