68 "command queue: %d.\n", cle);
87 clReleaseKernel(ctx->
kernel);
102 char *p, *
arg, *saveptr =
NULL;
103 float input_matrix[4][49];
105 for (i = 0; i < 4; i++) {
109 for (i = 0; i < 4; i++) {
117 sscanf_err = sscanf(arg,
"%f", &input_matrix[i][ctx->
matrix_sizes[i]]);
118 if (sscanf_err != 1) {
137 for (j = 0; j < 4; j++) {
146 matrix[i] = input_matrix[j][i];
150 CL_MEM_COPY_HOST_PTR |
151 CL_MEM_HOST_NO_ACCESS,
152 matrix_bytes, matrix, &cle);
173 size_t global_work[2];
201 src = (cl_mem) input->
data[p];
202 dst = (cl_mem)output->
data[p];
207 cle = clSetKernelArg(ctx->
kernel, 0,
sizeof(cl_mem), &dst);
208 if (cle != CL_SUCCESS) {
210 "destination image argument: %d.\n", cle);
213 cle = clSetKernelArg(ctx->
kernel, 1,
sizeof(cl_mem), &src);
214 if (cle != CL_SUCCESS) {
216 "source image argument: %d.\n", cle);
219 cle = clSetKernelArg(ctx->
kernel, 2,
sizeof(cl_int), &ctx->
dims[p]);
220 if (cle != CL_SUCCESS) {
222 "matrix size argument: %d.\n", cle);
225 cle = clSetKernelArg(ctx->
kernel, 3,
sizeof(cl_mem), &ctx->
matrix[p]);
226 if (cle != CL_SUCCESS) {
228 "matrix argument: %d.\n", cle);
231 cle = clSetKernelArg(ctx->
kernel, 4,
sizeof(cl_float), &ctx->
rdivs[p]);
232 if (cle != CL_SUCCESS) {
234 "rdiv argument: %d.\n", cle);
237 cle = clSetKernelArg(ctx->
kernel, 5,
sizeof(cl_float), &ctx->
biases[p]);
238 if (cle != CL_SUCCESS) {
240 "bias argument: %d.\n", cle);
251 p, global_work[0], global_work[1]);
256 if (cle != CL_SUCCESS) {
265 if (cle != CL_SUCCESS) {
297 for (i = 0; i < 4; i++) {
298 clReleaseMemObject(ctx->
matrix[i]);
302 cle = clReleaseKernel(ctx->
kernel);
303 if (cle != CL_SUCCESS)
305 "kernel: %d.\n", cle);
310 if (cle != CL_SUCCESS)
312 "command queue: %d.\n", cle);
318 #define OFFSET(x) offsetof(ConvolutionOpenCLContext, x)
319 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
358 .
name =
"convolution_opencl",
361 .priv_class = &convolution_opencl_class,
365 .
inputs = convolution_opencl_inputs,
366 .
outputs = convolution_opencl_outputs,
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
This structure describes decoded (raw) audio or video data.
int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx, size_t *work_size, AVFrame *frame, int plane, int block_alignment)
Find the work size needed needed for a given plane of an image.
int ff_opencl_filter_config_input(AVFilterLink *inlink)
Check that the input link contains a suitable hardware frames context and extract the device from it...
int ff_opencl_filter_query_formats(AVFilterContext *avctx)
Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
Main libavfilter public API header.
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
int h
agreed upon image height
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
static int convolution_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
AVOpenCLDeviceContext * hwctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static av_cold int uninit(AVCodecContext *avctx)
cl_device_id device_id
The primary device ID of the device.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
A filter pad used for either input or output.
A link between two filters.
AVFilter ff_vf_convolution_opencl
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
AVFILTER_DEFINE_CLASS(convolution_opencl)
int w
agreed upon image width
static int convolution_opencl_make_filter_params(AVFilterContext *avctx)
static av_cold void convolution_opencl_uninit(AVFilterContext *avctx)
static const AVFilterPad convolution_opencl_outputs[]
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
#define FF_ARRAY_ELEMS(a)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
static int query_formats(AVFilterContext *ctx)
common internal and external API header
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
static int convolution_opencl_init(AVFilterContext *avctx)
static const AVFilterPad convolution_opencl_inputs[]
AVFilterContext * dst
dest filter
cl_context context
The OpenCL context which will contain all operations and frames on this device.
static const AVOption convolution_opencl_options[]
cl_command_queue command_queue
const char * ff_opencl_source_convolution
int ff_opencl_filter_load_program(AVFilterContext *avctx, const char **program_source_array, int nb_strings)
Load a new OpenCL program from strings in memory.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.