Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
d3cd33ab
Commit
d3cd33ab
authored
Aug 08, 2019
by
Jarek Samic
Committed by
Mark Thompson
Aug 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lavfi: add utilities to reduce OpenCL boilerplate code
parent
3a09dbdb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
6 deletions
+146
-6
opencl.c
libavfilter/opencl.c
+10
-0
opencl.h
libavfilter/opencl.h
+136
-6
No files found.
libavfilter/opencl.c
View file @
d3cd33ab
...
@@ -350,3 +350,13 @@ void ff_opencl_print_const_matrix_3x3(AVBPrint *buf, const char *name_str,
...
@@ -350,3 +350,13 @@ void ff_opencl_print_const_matrix_3x3(AVBPrint *buf, const char *name_str,
}
}
av_bprintf
(
buf
,
"};
\n
"
);
av_bprintf
(
buf
,
"};
\n
"
);
}
}
cl_ulong
ff_opencl_get_event_time
(
cl_event
event
)
{
cl_ulong
time_start
;
cl_ulong
time_end
;
clGetEventProfilingInfo
(
event
,
CL_PROFILING_COMMAND_START
,
sizeof
(
time_start
),
&
time_start
,
NULL
);
clGetEventProfilingInfo
(
event
,
CL_PROFILING_COMMAND_END
,
sizeof
(
time_end
),
&
time_end
,
NULL
);
return
time_end
-
time_start
;
}
libavfilter/opencl.h
View file @
d3cd33ab
...
@@ -47,6 +47,11 @@ typedef struct OpenCLFilterContext {
...
@@ -47,6 +47,11 @@ typedef struct OpenCLFilterContext {
int
output_height
;
int
output_height
;
}
OpenCLFilterContext
;
}
OpenCLFilterContext
;
// Groups together information about a kernel argument
typedef
struct
OpenCLKernelArg
{
size_t
arg_size
;
const
void
*
arg_val
;
}
OpenCLKernelArg
;
/**
/**
* set argument to specific Kernel.
* set argument to specific Kernel.
...
@@ -73,9 +78,26 @@ typedef struct OpenCLFilterContext {
...
@@ -73,9 +78,26 @@ typedef struct OpenCLFilterContext {
goto fail; \
goto fail; \
} \
} \
} while(0)
} while(0)
/**
* Create a kernel with the given name.
*
* The kernel variable in the context structure must have a name of the form
* kernel_<kernel_name>.
*
* The OpenCLFilterContext variable in the context structure must be named ocf.
*
* Requires the presence of a local cl_int variable named cle and a fail label for error
* handling.
*/
#define CL_CREATE_KERNEL(ctx, kernel_name) do { \
ctx->kernel_ ## kernel_name = clCreateKernel(ctx->ocf.program, #kernel_name, &cle); \
CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to create %s kernel: %d.\n", #kernel_name, cle); \
} while(0)
/**
/**
* release an OpenCL Kernel
* release an OpenCL Kernel
*/
*/
#define CL_RELEASE_KERNEL(k) \
#define CL_RELEASE_KERNEL(k) \
do { \
do { \
if (k) { \
if (k) { \
...
@@ -87,8 +109,8 @@ do { \
...
@@ -87,8 +109,8 @@ do { \
} while(0)
} while(0)
/**
/**
* release an OpenCL Memory Object
* release an OpenCL Memory Object
*/
*/
#define CL_RELEASE_MEMORY(m) \
#define CL_RELEASE_MEMORY(m) \
do { \
do { \
if (m) { \
if (m) { \
...
@@ -100,8 +122,8 @@ do { \
...
@@ -100,8 +122,8 @@ do { \
} while(0)
} while(0)
/**
/**
* release an OpenCL Command Queue
* release an OpenCL Command Queue
*/
*/
#define CL_RELEASE_QUEUE(q) \
#define CL_RELEASE_QUEUE(q) \
do { \
do { \
if (q) { \
if (q) { \
...
@@ -112,6 +134,108 @@ do { \
...
@@ -112,6 +134,108 @@ do { \
} \
} \
} while(0)
} while(0)
/**
* Enqueue a kernel with the given information.
*
* Kernel arguments are provided as KernelArg structures and are set in the order
* that they are passed.
*
* Requires the presence of a local cl_int variable named cle and a fail label for error
* handling.
*/
#define CL_ENQUEUE_KERNEL_WITH_ARGS(queue, kernel, global_work_size, local_work_size, event, ...) \
do { \
OpenCLKernelArg args[] = {__VA_ARGS__}; \
for (int i = 0; i < FF_ARRAY_ELEMS(args); i++) { \
cle = clSetKernelArg(kernel, i, args[i].arg_size, args[i].arg_val); \
if (cle != CL_SUCCESS) { \
av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " \
"argument %d: error %d.\n", i, cle); \
err = AVERROR(EIO); \
goto fail; \
} \
} \
\
cle = clEnqueueNDRangeKernel( \
queue, \
kernel, \
FF_ARRAY_ELEMS(global_work_size), \
NULL, \
global_work_size, \
local_work_size, \
0, \
NULL, \
event \
); \
CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to enqueue kernel: %d.\n", cle); \
} while (0)
/**
* Uses the above macro to enqueue the given kernel and then additionally runs it to
* completion via clFinish.
*
* Requires the presence of a local cl_int variable named cle and a fail label for error
* handling.
*/
#define CL_RUN_KERNEL_WITH_ARGS(queue, kernel, global_work_size, local_work_size, event, ...) do { \
CL_ENQUEUE_KERNEL_WITH_ARGS( \
queue, kernel, global_work_size, local_work_size, event, __VA_ARGS__ \
); \
\
cle = clFinish(queue); \
CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to finish command queue: %d.\n", cle); \
} while (0)
/**
* Create a buffer with the given information.
*
* The buffer variable in the context structure must be named <buffer_name>.
*
* Requires the presence of a local cl_int variable named cle and a fail label for error
* handling.
*/
#define CL_CREATE_BUFFER_FLAGS(ctx, buffer_name, flags, size, host_ptr) do { \
ctx->buffer_name = clCreateBuffer( \
ctx->ocf.hwctx->context, \
flags, \
size, \
host_ptr, \
&cle \
); \
CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to create buffer %s: %d.\n", #buffer_name, cle); \
} while(0)
/**
* Perform a blocking write to a buffer.
*
* Requires the presence of a local cl_int variable named cle and a fail label for error
* handling.
*/
#define CL_BLOCKING_WRITE_BUFFER(queue, buffer, size, host_ptr, event) do { \
cle = clEnqueueWriteBuffer( \
queue, \
buffer, \
CL_TRUE, \
0, \
size, \
host_ptr, \
0, \
NULL, \
event \
); \
CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to write buffer to device: %d.\n", cle); \
} while(0)
/**
* Create a buffer with the given information.
*
* The buffer variable in the context structure must be named <buffer_name>.
*
* Requires the presence of a local cl_int variable named cle and a fail label for error
* handling.
*/
#define CL_CREATE_BUFFER(ctx, buffer_name, size) CL_CREATE_BUFFER_FLAGS(ctx, buffer_name, 0, size, NULL)
/**
/**
* Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
* Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
*/
*/
...
@@ -171,4 +295,10 @@ int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx,
...
@@ -171,4 +295,10 @@ int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx,
void
ff_opencl_print_const_matrix_3x3
(
AVBPrint
*
buf
,
const
char
*
name_str
,
void
ff_opencl_print_const_matrix_3x3
(
AVBPrint
*
buf
,
const
char
*
name_str
,
double
mat
[
3
][
3
]);
double
mat
[
3
][
3
]);
/**
* Gets the command start and end times for the given event and returns the
* difference (the time that the event took).
*/
cl_ulong
ff_opencl_get_event_time
(
cl_event
event
);
#endif
/* AVFILTER_OPENCL_H */
#endif
/* AVFILTER_OPENCL_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment