History

libavfilter/x86/vf_convolution: add sobel filter optimization and unit test with intel AVX512 VNNI

This commit enabled assembly code with intel AVX512 VNNI and added unit test for sobel filter sobel_c: 4537 sobel_avx512icl 2136

bwang30 committed 4 years ago

Commit 3ab11dc1 parent 2d25f339 files · +362 −78Browse files

Showing the changes to libavfilter/vf_convolution.c (1 of 9 files). Show all

Unified · Split

libavfilter/vf_convolution.c+13−78
@@ -139,24 +139,6 @@ static void filter16_roberts(uint8_t *dstp, int width, · 138 unmodified lines
139139 }
140140 }
141141
142−static void filter16_sobel(uint8_t *dstp, int width,
143− float scale, float delta, const int *const matrix,
144− const uint8_t *c[], int peak, int radius,
145− int dstride, int stride, int size)
146−{
147− uint16_t *dst = (uint16_t *)dstp;
148− int x;
149−
150− for (x = 0; x < width; x++) {
151− float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -2 + AV_RN16A(&c[2][2 * x]) * -1 +
152− AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 2 + AV_RN16A(&c[8][2 * x]) * 1;
153− float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -2 +
154− AV_RN16A(&c[5][2 * x]) * 2 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
155−
156− dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
157− }
158−}
159−
160142 static void filter16_scharr(uint8_t *dstp, int width,
161143 float scale, float delta, const int *const matrix,
162144 const uint8_t *c[], int peak, int radius,
@@ -261,26 +243,6 @@ static void filter_roberts(uint8_t *dst, int width, · 98 unmodified lines
261243 }
262244 }
263245
264−static void filter_sobel(uint8_t *dst, int width,
265− float scale, float delta, const int *const matrix,
266− const uint8_t *c[], int peak, int radius,
267− int dstride, int stride, int size)
268−{
269− const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
270− const uint8_t *c3 = c[3], *c5 = c[5];
271− const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
272− int x;
273−
274− for (x = 0; x < width; x++) {
275− float suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 +
276− c6[x] * 1 + c7[x] * 2 + c8[x] * 1;
277− float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 +
278− c5[x] * 2 + c6[x] * -1 + c8[x] * 1;
279−
280− dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
281− }
282−}
283−
284246 static void filter_scharr(uint8_t *dst, int width,
285247 float scale, float delta, const int *const matrix,
286248 const uint8_t *c[], int peak, int radius,
@@ -552,22 +514,6 @@ static void filter_column(uint8_t *dst, int height, · 265 unmodified lines
552514 }
553515 }
554516
555−static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, int stride,
556− int x, int w, int y, int h, int bpc)
557−{
558− int i;
559−
560− for (i = 0; i < 9; i++) {
561− int xoff = FFABS(x + ((i % 3) - 1));
562− int yoff = FFABS(y + (i / 3) - 1);
563−
564− xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
565− yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
566−
567− c[i] = src + xoff * bpc + yoff * stride;
568− }
569−}
570−
571517 static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, int stride,
572518 int x, int w, int y, int h, int bpc)
573519 {
@@ -708,6 +654,18 @@ static int param_init(AVFilterContext *ctx) · 134 unmodified lines
708654 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
709655 int p, i;
710656
657+ s->depth = desc->comp[0].depth;
658+ s->max = (1 << s->depth) - 1;
659+
660+ s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
661+ s->planewidth[0] = s->planewidth[3] = inlink->w;
662+ s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
663+ s->planeheight[0] = s->planeheight[3] = inlink->h;
664+
665+ s->nb_planes = av_pix_fmt_count_planes(inlink->format);
666+ s->nb_threads = ff_filter_get_nb_threads(ctx);
667+ s->bpc = (s->depth + 7) / 8;
668+
711669 if (!strcmp(ctx->filter->name, "convolution")) {
712670 for (i = 0; i < 4; i++) {
713671 int *matrix = (int *)s->matrix[i];
@@ -804,14 +762,7 @@ static int param_init(AVFilterContext *ctx) · 90 unmodified lines
804762 s->bias[i] = s->delta;
805763 }
806764 } else if (!strcmp(ctx->filter->name, "sobel")) {
807− for (i = 0; i < 4; i++) {
808− s->filter[i] = filter_sobel;
809− s->copy[i] = !((1 << i) & s->planes);
810− s->size[i] = 3;
811− s->setup[i] = setup_3x3;
812− s->rdiv[i] = s->scale;
813− s->bias[i] = s->delta;
814− }
765+ ff_sobel_init(s, s->depth, s->nb_planes);
815766 } else if (!strcmp(ctx->filter->name, "kirsch")) {
816767 for (i = 0; i < 4; i++) {
817768 s->filter[i] = filter_kirsch;
@@ -832,18 +783,6 @@ static int param_init(AVFilterContext *ctx) · 14 unmodified lines
832783 }
833784 }
834785
835− s->depth = desc->comp[0].depth;
836− s->max = (1 << s->depth) - 1;
837−
838− s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
839− s->planewidth[0] = s->planewidth[3] = inlink->w;
840− s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
841− s->planeheight[0] = s->planeheight[3] = inlink->h;
842−
843− s->nb_planes = av_pix_fmt_count_planes(inlink->format);
844− s->nb_threads = ff_filter_get_nb_threads(ctx);
845− s->bpc = (s->depth + 7) / 8;
846−
847786 if (!strcmp(ctx->filter->name, "convolution")) {
848787 if (s->depth > 8) {
849788 for (p = 0; p < s->nb_planes; p++) {
@@ -870,10 +809,6 @@ static int param_init(AVFilterContext *ctx) · 20 unmodified lines
870809 if (s->depth > 8)
871810 for (p = 0; p < s->nb_planes; p++)
872811 s->filter[p] = filter16_roberts;
873− } else if (!strcmp(ctx->filter->name, "sobel")) {
874− if (s->depth > 8)
875− for (p = 0; p < s->nb_planes; p++)
876− s->filter[p] = filter16_sobel;
877812 } else if (!strcmp(ctx->filter->name, "kirsch")) {
878813 if (s->depth > 8)
879814 for (p = 0; p < s->nb_planes; p++)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t