opencl_internal.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2012 Peng Gao <peng@multicorewareinc.com>
  3. * Copyright (C) 2012 Li Cao <li@multicorewareinc.com>
  4. * Copyright (C) 2012 Wei Gao <weigao@multicorewareinc.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "opencl_internal.h"
  23. #include "libavutil/log.h"
  24. int avpriv_opencl_set_parameter(FFOpenclParam *opencl_param, ...)
  25. {
  26. int ret = 0;
  27. va_list arg_ptr;
  28. void *param;
  29. size_t param_size;
  30. cl_int status;
  31. if (!opencl_param->kernel) {
  32. av_log(opencl_param->ctx, AV_LOG_ERROR, "OpenCL kernel must be set\n");
  33. return AVERROR(EINVAL);
  34. }
  35. va_start(arg_ptr, opencl_param);
  36. do {
  37. param = va_arg(arg_ptr, void *);
  38. if (!param)
  39. break;
  40. param_size = va_arg(arg_ptr, size_t);
  41. if (!param_size) {
  42. av_log(opencl_param->ctx, AV_LOG_ERROR, "Parameter size must not be 0\n");
  43. ret = AVERROR(EINVAL);
  44. goto end;
  45. }
  46. status = clSetKernelArg(opencl_param->kernel, opencl_param->param_num, param_size, param);
  47. if (status != CL_SUCCESS) {
  48. av_log(opencl_param->ctx, AV_LOG_ERROR, "Cannot set kernel argument: %s\n", av_opencl_errstr(status));
  49. ret = AVERROR_EXTERNAL;
  50. goto end;
  51. }
  52. opencl_param->param_num++;
  53. } while (param && param_size);
  54. end:
  55. va_end(arg_ptr);
  56. return ret;
  57. }