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/convolution.h (1 of 9 files). Show all

Unified · Split

libavfilter/convolution.h+74−0
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #ifndef AVFILTER_CONVOLUTION_H
2222 #define AVFILTER_CONVOLUTION_H
2323 #include "avfilter.h"
24+#include "libavutil/intreadwrite.h"
2425
2526 enum MatrixMode {
2627 MATRIX_SQUARE,
@@ -61,4 +62,77 @@ typedef struct ConvolutionContext { · 34 unmodified lines
6162 } ConvolutionContext;
6263
6364 void ff_convolution_init_x86(ConvolutionContext *s);
65+void ff_sobel_init_x86(ConvolutionContext *s, int depth, int nb_planes);
66+
67+static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, int stride,
68+ int x, int w, int y, int h, int bpc)
69+{
70+ int i;
71+
72+ for (i = 0; i < 9; i++) {
73+ int xoff = FFABS(x + ((i % 3) - 1));
74+ int yoff = FFABS(y + (i / 3) - 1);
75+
76+ xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
77+ yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
78+
79+ c[i] = src + xoff * bpc + yoff * stride;
80+ }
81+}
82+
83+static void filter_sobel(uint8_t *dst, int width,
84+ float scale, float delta, const int *const matrix,
85+ const uint8_t *c[], int peak, int radius,
86+ int dstride, int stride, int size)
87+{
88+ const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
89+ const uint8_t *c3 = c[3], *c5 = c[5];
90+ const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
91+ int x;
92+
93+ for (x = 0; x < width; x++) {
94+ float suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 +
95+ c6[x] * 1 + c7[x] * 2 + c8[x] * 1;
96+ float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 +
97+ c5[x] * 2 + c6[x] * -1 + c8[x] * 1;
98+
99+ dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
100+ }
101+}
102+
103+static void filter16_sobel(uint8_t *dstp, int width,
104+ float scale, float delta, const int *const matrix,
105+ const uint8_t *c[], int peak, int radius,
106+ int dstride, int stride, int size)
107+{
108+ uint16_t *dst = (uint16_t *)dstp;
109+ int x;
110+
111+ for (x = 0; x < width; x++) {
112+ float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -2 + AV_RN16A(&c[2][2 * x]) * -1 +
113+ AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 2 + AV_RN16A(&c[8][2 * x]) * 1;
114+ float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -2 +
115+ AV_RN16A(&c[5][2 * x]) * 2 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
116+
117+ dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
118+ }
119+}
120+
121+static av_unused void ff_sobel_init(ConvolutionContext *s, int depth, int nb_planes)
122+{
123+ for (int i = 0; i < 4; i++) {
124+ s->filter[i] = filter_sobel;
125+ s->copy[i] = !((1 << i) & s->planes);
126+ s->size[i] = 3;
127+ s->setup[i] = setup_3x3;
128+ s->rdiv[i] = s->scale;
129+ s->bias[i] = s->delta;
130+ }
131+ if (s->depth > 8)
132+ for (int i = 0; i < 4; i++)
133+ s->filter[i] = filter16_sobel;
134+#if ARCH_X86_64
135+ ff_sobel_init_x86(s, depth, nb_planes);
136+#endif
137+}
64138 #endif

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