From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7266C43B15 for ; Fri, 11 Nov 2022 03:00:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AB13768BBC6; Fri, 11 Nov 2022 05:00:51 +0200 (EET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D37868B79A for ; Fri, 11 Nov 2022 05:00:43 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668135649; x=1699671649; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=fHUcKTYnl6ApPDK9EzZUZPbuaLm9lk3N8m0Pzn4y7g8=; b=gstOh+E4Iu4yR6i/m87QI3PC0jBAqfO/yJt1O/DiwBiN6AI880a7aYiU rfhrBf9ETl0cZuo0jtwztVe/oHbyt9u2PGlxGmPbedAD4cL7gtw4deY+e gwTPAhgfNbpw1rGrSPRJ+pcmY44q0hnPYVulQUvoKdlZt8dllquJXE+mu 61V96j3DW9xyYLpDZa/2ENHmgt2o569t2nyyArHlb/jNzJtgz8xLIIEYj Qj2PIWo1pwn2wBRIq9d+cX1w+jlE1az3JqfOEJ6kSD1Aygv6jRZg2ujF6 BjAHfbg0Fwq+qTd+F3Ms5hJbUFt8z2tJ61GvR/Z8zjKVlYoiywWzNJSfL A==; X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="309133680" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="309133680" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:00:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="701060996" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="701060996" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by fmsmga008.fm.intel.com with ESMTP; 10 Nov 2022 19:00:33 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 10 Nov 2022 19:00:33 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 10 Nov 2022 19:00:33 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Thu, 10 Nov 2022 19:00:33 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.105) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Thu, 10 Nov 2022 19:00:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T9mGSZznyf+ZkhsGflVWDNerBep1/KqXlQIc8DH3DGpZKhEf2H5OGaZnLu73KdmCyMQ1+sRCyrm4yd/PZawBsNzrn6Wdb7IuDapbZlMZHQQFLEWeSUWMD2ogcCTzRiOcoL6jlzfDkdbVyw3FlBgQD7v5PPezRuA5u0r1SyOx3jDfu6+XPOs/9DwN8w9L0hk/hyB2ZqARozqeBARJleidrYvWZjaQT80H/mDIQULn2BcJLB0DFfCwU50ft52NeKIHTnM4gvIfIDR5dIWo+iSW0RhiMK0NvKxhtOHx5vMpDUDt46ng/AVa/YvLEK7usZtQCXBEjvRj2DDKg/Som0EnFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fHUcKTYnl6ApPDK9EzZUZPbuaLm9lk3N8m0Pzn4y7g8=; b=aU7jJGKIpo80scD5YUNsWg7gYwBXMQgSSI3WLwNWtiqaNvVfVrXiuxbT1XUluKslrVk6oLRUPMBQMavPYK2EBLY1Edtwxw9/xSyN0YQhUASokeDHGTnAao6BYy1+kmyqxMBwqT0PCAMFi/Hv+N/G8Ya1dYBUqLgitjwa3AqMQI+TH+6b26xb6ArzHog0L33d37TUSHDfv7mlh0oEqbOc/q6IpgrMpSOUmJM5i9eQkbMKK3SNAX5zg8vwcWN2mHqIkHuxi7RFGBRaxegN3P32pfrJKsMlDUN3L7KVnvpg2lgm38+Q/NASQilHI5SZRn16FYSgTHY1yTBN3J2FfZFRGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from BN9PR11MB5515.namprd11.prod.outlook.com (2603:10b6:408:104::8) by DM4PR11MB5440.namprd11.prod.outlook.com (2603:10b6:5:39c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 03:00:30 +0000 Received: from BN9PR11MB5515.namprd11.prod.outlook.com ([fe80::ca2a:c3a1:b0cb:c003]) by BN9PR11MB5515.namprd11.prod.outlook.com ([fe80::ca2a:c3a1:b0cb:c003%9]) with mapi id 15.20.5813.012; Fri, 11 Nov 2022 03:00:30 +0000 From: "Xiang, Haihao" To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [FFmpeg-devel] [PATCH v7] libavfilter/x86/vf_convolution: add sobel filter optimization and unit test with intel AVX512 VNNI Thread-Index: AQHY8CrL0KI1InozpkmR3D2PqCovQ64y8iIAgAYhCQA= Date: Fri, 11 Nov 2022 03:00:30 +0000 Message-ID: <1ed11e661437c1e64b36763803949a73544bffc8.camel@intel.com> References: <20221104082925.25598-1-bin.wang@intel.com> <1aef874ff5e61735e448276b9cfcb08a8b476be8.camel@intel.com> In-Reply-To: <1aef874ff5e61735e448276b9cfcb08a8b476be8.camel@intel.com> Accept-Language: en-AS, zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Evolution 3.36.5-0ubuntu1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BN9PR11MB5515:EE_|DM4PR11MB5440:EE_ x-ms-office365-filtering-correlation-id: f5cea8ab-4e93-488e-1622-08dac390e4aa x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: okZ89Xsv2KYJasHLA/sFyQP8qYDhTnska8KCHDoIJtvoWcZsRxCtfU2VhRNYO5OhPrzI6SmCa3DNJoWi0RjFZ2FPOTT/cwYSqOKiToP3opExrtNJ0AmDdJiIXgVHv8voX2CPZTXtYj52MWXC6OPq7UXO6Z7rFhsvGusVnEn0CyS9oVS5NnlyxkANIU4PuwrqBwF5iAg8GlJvVt2pc6+GE/GTq8NynyMypc7OokAWfueqd36pd01XS2HvxmxLCplsR4WHpDZcz0A8rX7mvFUPRUEmj7sKZoxz35d7su2ofuy40mv3+q8tl6Du2jIUSjZJ0vVIMtkBnVILoKpQavzZXmH65nd0iLOB/7zeYoqzzRLPYn7ILufVjiMfk+oNqKpx7Vsyub3e7gJaJMC1aWOCLtOt0BiwNPNett13Oc4/BbXZvzSApK9+8QuVybckLHs2/AGXz1ZmuuBJugneLZDJD967/CFnWG+xwht26KG62S7RWU/PDMctN39xRuFdb/CN/FDR/6Vytmz+c9rjlQUvjH45KQ1Q5995nNp4tZUeTEvcMr40/d9eDsc++JiumEnG1XcjIgIP/AXMGM/XZ0Ia+6U+qBAQ+aKaSwPBQLrQj+GxGXq4wN0ewqK3/PMeeUVocPIci7q7ilKwhaw8A2ymriawt5UTDM5MhWZix/MDq7QtCIqH2qLtvGORvlBGuzbMV4XMHrF8CBMCKhu/PjWp9BBKUDDeiOyutW38wmbGBjGgyjaCZGnl8S5wSWmShLY2K5LvGqUuMr8uZ59kag5345nVjTevxGbgTt7soePZlAU= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN9PR11MB5515.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(39860400002)(366004)(376002)(396003)(136003)(346002)(451199015)(186003)(66556008)(76116006)(66946007)(8936002)(5660300002)(38070700005)(30864003)(41300700001)(38100700002)(82960400001)(66476007)(64756008)(66446008)(4326008)(2906002)(8676002)(122000001)(91956017)(71200400001)(86362001)(6512007)(26005)(6916009)(316002)(36756003)(83380400001)(6506007)(478600001)(2616005)(6486002)(107886003)(2004002)(579004)(559001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?eFFGdU9lR0FiNjBoenhUMzhwTTRlRzFLSXNTMDdzV2s4K0NJSG5pd25oeTZB?= =?utf-8?B?NzZldkd3eVlzdUY2YlUrbHVSdmZ1UTR0K2xJT0R6UHQ2R3R2K0lkOG9KUUl4?= =?utf-8?B?MXFtSFBPeVNsOENaeEhqT0JLUHVHNHdEblFvU2FoVUlUQXNBcXVycnllWHVk?= =?utf-8?B?TTUvWENZc1ZDTmZ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=?utf-8?B?a0cwenJKNy9qQnluUXk5OTBPS1pXNWRwOVZiS0p4NkU4WktISE9hemtRTC90?= =?utf-8?B?c0JXSjdzUDFLRGg2M2xXR0ZEVXhUeFZVcTRwV0hCTXFFSUlTVG1zbzZyVTli?= =?utf-8?B?UHMwRk55N3FsRWtBQWhxMHdKZzNEUnA3UmRlVXpuZ1dvVGZzRXgyRDVuQmE1?= =?utf-8?B?Mnc9PQ==?= Content-ID: <1A8C8A37CF7F1D4187C416F2EFF86F22@namprd11.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5515.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5cea8ab-4e93-488e-1622-08dac390e4aa X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Nov 2022 03:00:30.5249 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 3uJ8OKRF65UO7wlceDck03q6lpdsoub/yTCEaOwlXjE6/f1mP2YyWkZHoI1XjkeKDvppliUA9j9lwvNpZZFkOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5440 X-OriginatorOrg: intel.com Subject: Re: [FFmpeg-devel] [PATCH v7] libavfilter/x86/vf_convolution: add sobel filter optimization and unit test with intel AVX512 VNNI X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: "Wang, Bin" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Mon, 2022-11-07 at 05:24 +0000, Xiang, Haihao wrote: > On Fri, 2022-11-04 at 16:29 +0800, bin.wang-at-intel.com@ffmpeg.org wrote: > > From: bwang30 > > > > This commit enabled assembly code with intel AVX512 VNNI and added unit test > > for sobel filter > > > > sobel_c: 4537 > > sobel_avx512icl 2136 > > > > Signed-off-by: bwang30 > > --- > > libavfilter/convolution.h | 74 +++++++++++++ > > libavfilter/vf_convolution.c | 91 +++------------- > > libavfilter/x86/vf_convolution.asm | 147 ++++++++++++++++++++++++++ > > libavfilter/x86/vf_convolution_init.c | 18 ++++ > > tests/checkasm/Makefile | 1 + > > tests/checkasm/checkasm.c | 3 + > > tests/checkasm/checkasm.h | 1 + > > tests/checkasm/vf_convolution.c | 104 ++++++++++++++++++ > > tests/fate/checkasm.mak | 1 + > > 9 files changed, 362 insertions(+), 78 deletions(-) > > create mode 100644 tests/checkasm/vf_convolution.c > > > > diff --git a/libavfilter/convolution.h b/libavfilter/convolution.h > > index 88aabe9a20..e44bfb5da8 100644 > > --- a/libavfilter/convolution.h > > +++ b/libavfilter/convolution.h > > @@ -21,6 +21,7 @@ > > #ifndef AVFILTER_CONVOLUTION_H > > #define AVFILTER_CONVOLUTION_H > > #include "avfilter.h" > > +#include "libavutil/intreadwrite.h" > > > > enum MatrixMode { > > MATRIX_SQUARE, > > @@ -61,4 +62,77 @@ typedef struct ConvolutionContext { > > } ConvolutionContext; > > > > void ff_convolution_init_x86(ConvolutionContext *s); > > +void ff_sobel_init_x86(ConvolutionContext *s, int depth, int nb_planes); > > + > > +static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, > > int > > stride, > > + int x, int w, int y, int h, int bpc) > > +{ > > + int i; > > + > > + for (i = 0; i < 9; i++) { > > + int xoff = FFABS(x + ((i % 3) - 1)); > > + int yoff = FFABS(y + (i / 3) - 1); > > + > > + xoff = xoff >= w ? 2 * w - 1 - xoff : xoff; > > + yoff = yoff >= h ? 2 * h - 1 - yoff : yoff; > > + > > + c[i] = src + xoff * bpc + yoff * stride; > > + } > > +} > > + > > +static void filter_sobel(uint8_t *dst, int width, > > + float scale, float delta, const int *const matrix, > > + const uint8_t *c[], int peak, int radius, > > + int dstride, int stride, int size) > > +{ > > + const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2]; > > + const uint8_t *c3 = c[3], *c5 = c[5]; > > + const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8]; > > + int x; > > + > > + for (x = 0; x < width; x++) { > > + float suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 + > > + c6[x] * 1 + c7[x] * 2 + c8[x] * 1; > > + float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 + > > + c5[x] * 2 + c6[x] * -1 + c8[x] * 1; > > + > > + dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + > > delta); > > + } > > +} > > + > > +static void filter16_sobel(uint8_t *dstp, int width, > > + float scale, float delta, const int *const > > matrix, > > + const uint8_t *c[], int peak, int radius, > > + int dstride, int stride, int size) > > +{ > > + uint16_t *dst = (uint16_t *)dstp; > > + int x; > > + > > + for (x = 0; x < width; x++) { > > + float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * > > -2 + AV_RN16A(&c[2][2 * x]) * -1 + > > + AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) > > * 2 + AV_RN16A(&c[8][2 * x]) * 1; > > + float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) > > * 1 + AV_RN16A(&c[3][2 * x]) * -2 + > > + AV_RN16A(&c[5][2 * x]) * 2 + AV_RN16A(&c[6][2 * x]) * > > -1 + AV_RN16A(&c[8][2 * x]) * 1; > > + > > + dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, > > peak); > > + } > > +} > > + > > +static av_unused void ff_sobel_init(ConvolutionContext *s, int depth, int > > nb_planes) > > +{ > > + for (int i = 0; i < 4; i++) { > > + s->filter[i] = filter_sobel; > > + s->copy[i] = !((1 << i) & s->planes); > > + s->size[i] = 3; > > + s->setup[i] = setup_3x3; > > + s->rdiv[i] = s->scale; > > + s->bias[i] = s->delta; > > + } > > + if (s->depth > 8) > > + for (int i = 0; i < 4; i++) > > + s->filter[i] = filter16_sobel; > > +#if ARCH_X86_64 > > + ff_sobel_init_x86(s, depth, nb_planes); > > +#endif > > +} > > #endif > > diff --git a/libavfilter/vf_convolution.c b/libavfilter/vf_convolution.c > > index 9a9c099e6d..7762fa2a05 100644 > > --- a/libavfilter/vf_convolution.c > > +++ b/libavfilter/vf_convolution.c > > @@ -139,24 +139,6 @@ static void filter16_roberts(uint8_t *dstp, int width, > > } > > } > > > > -static void filter16_sobel(uint8_t *dstp, int width, > > - float scale, float delta, const int *const > > matrix, > > - const uint8_t *c[], int peak, int radius, > > - int dstride, int stride, int size) > > -{ > > - uint16_t *dst = (uint16_t *)dstp; > > - int x; > > - > > - for (x = 0; x < width; x++) { > > - float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * > > -2 + AV_RN16A(&c[2][2 * x]) * -1 + > > - AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) > > * 2 + AV_RN16A(&c[8][2 * x]) * 1; > > - float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) > > * 1 + AV_RN16A(&c[3][2 * x]) * -2 + > > - AV_RN16A(&c[5][2 * x]) * 2 + AV_RN16A(&c[6][2 * x]) * > > -1 + AV_RN16A(&c[8][2 * x]) * 1; > > - > > - dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, > > peak); > > - } > > -} > > - > > static void filter16_scharr(uint8_t *dstp, int width, > > float scale, float delta, const int *const > > matrix, > > const uint8_t *c[], int peak, int radius, > > @@ -261,26 +243,6 @@ static void filter_roberts(uint8_t *dst, int width, > > } > > } > > > > -static void filter_sobel(uint8_t *dst, int width, > > - float scale, float delta, const int *const matrix, > > - const uint8_t *c[], int peak, int radius, > > - int dstride, int stride, int size) > > -{ > > - const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2]; > > - const uint8_t *c3 = c[3], *c5 = c[5]; > > - const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8]; > > - int x; > > - > > - for (x = 0; x < width; x++) { > > - float suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 + > > - c6[x] * 1 + c7[x] * 2 + c8[x] * 1; > > - float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 + > > - c5[x] * 2 + c6[x] * -1 + c8[x] * 1; > > - > > - dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + > > delta); > > - } > > -} > > - > > static void filter_scharr(uint8_t *dst, int width, > > float scale, float delta, const int *const > > matrix, > > const uint8_t *c[], int peak, int radius, > > @@ -552,22 +514,6 @@ static void filter_column(uint8_t *dst, int height, > > } > > } > > > > -static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, > > int > > stride, > > - int x, int w, int y, int h, int bpc) > > -{ > > - int i; > > - > > - for (i = 0; i < 9; i++) { > > - int xoff = FFABS(x + ((i % 3) - 1)); > > - int yoff = FFABS(y + (i / 3) - 1); > > - > > - xoff = xoff >= w ? 2 * w - 1 - xoff : xoff; > > - yoff = yoff >= h ? 2 * h - 1 - yoff : yoff; > > - > > - c[i] = src + xoff * bpc + yoff * stride; > > - } > > -} > > - > > static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, > > int > > stride, > > int x, int w, int y, int h, int bpc) > > { > > @@ -708,6 +654,18 @@ static int param_init(AVFilterContext *ctx) > > const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); > > int p, i; > > > > + s->depth = desc->comp[0].depth; > > + s->max = (1 << s->depth) - 1; > > + > > + s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc- > > > log2_chroma_w); > > + s->planewidth[0] = s->planewidth[3] = inlink->w; > > + s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc- > > > log2_chroma_h); > > + s->planeheight[0] = s->planeheight[3] = inlink->h; > > + > > + s->nb_planes = av_pix_fmt_count_planes(inlink->format); > > + s->nb_threads = ff_filter_get_nb_threads(ctx); > > + s->bpc = (s->depth + 7) / 8; > > + > > if (!strcmp(ctx->filter->name, "convolution")) { > > for (i = 0; i < 4; i++) { > > int *matrix = (int *)s->matrix[i]; > > @@ -804,14 +762,7 @@ static int param_init(AVFilterContext *ctx) > > s->bias[i] = s->delta; > > } > > } else if (!strcmp(ctx->filter->name, "sobel")) { > > - for (i = 0; i < 4; i++) { > > - s->filter[i] = filter_sobel; > > - s->copy[i] = !((1 << i) & s->planes); > > - s->size[i] = 3; > > - s->setup[i] = setup_3x3; > > - s->rdiv[i] = s->scale; > > - s->bias[i] = s->delta; > > - } > > + ff_sobel_init(s, s->depth, s->nb_planes); > > } else if (!strcmp(ctx->filter->name, "kirsch")) { > > for (i = 0; i < 4; i++) { > > s->filter[i] = filter_kirsch; > > @@ -832,18 +783,6 @@ static int param_init(AVFilterContext *ctx) > > } > > } > > > > - s->depth = desc->comp[0].depth; > > - s->max = (1 << s->depth) - 1; > > - > > - s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc- > > > log2_chroma_w); > > - s->planewidth[0] = s->planewidth[3] = inlink->w; > > - s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc- > > > log2_chroma_h); > > - s->planeheight[0] = s->planeheight[3] = inlink->h; > > - > > - s->nb_planes = av_pix_fmt_count_planes(inlink->format); > > - s->nb_threads = ff_filter_get_nb_threads(ctx); > > - s->bpc = (s->depth + 7) / 8; > > - > > if (!strcmp(ctx->filter->name, "convolution")) { > > if (s->depth > 8) { > > for (p = 0; p < s->nb_planes; p++) { > > @@ -870,10 +809,6 @@ static int param_init(AVFilterContext *ctx) > > if (s->depth > 8) > > for (p = 0; p < s->nb_planes; p++) > > s->filter[p] = filter16_roberts; > > - } else if (!strcmp(ctx->filter->name, "sobel")) { > > - if (s->depth > 8) > > - for (p = 0; p < s->nb_planes; p++) > > - s->filter[p] = filter16_sobel; > > } else if (!strcmp(ctx->filter->name, "kirsch")) { > > if (s->depth > 8) > > for (p = 0; p < s->nb_planes; p++) > > diff --git a/libavfilter/x86/vf_convolution.asm > > b/libavfilter/x86/vf_convolution.asm > > index 754d4d1064..c912d56752 100644 > > --- a/libavfilter/x86/vf_convolution.asm > > +++ b/libavfilter/x86/vf_convolution.asm > > @@ -22,6 +22,18 @@ > > > > SECTION_RODATA > > half: dd 0.5 > > +data_p1: dd 1 > > +data_n1: dd -1 > > +data_p2: dd 2 > > +data_n2: dd -2 > > + > > +ALIGN 64 > > +sobel_perm: db 0, 16, 32, 48, 1, 17, 33, 49, 2, 18, 34, 50, 3, 19, 35, > > 51 > > + db 4, 20, 36, 52, 5, 21, 37, 53, 6, 22, 38, 54, 7, 23, 39, > > 55 > > + db 8, 24, 40, 56, 9, 25, 41, 57, 10, 26, 42, 58, 11, 27, 43, > > 59 > > + db 12, 28, 44, 60, 13, 29, 45, 61, 14, 30, 46, 62, 15, 31, 47, > > 63 > > +sobel_mulA: db -1, 1, -2, 2 > > +sobel_mulB: db 1, -1, 2, -2 > > > > SECTION .text > > > > @@ -154,3 +166,138 @@ cglobal filter_3x3, 4, 15, 7, dst, width, rdiv, bias, > > matrix, ptr, c0, c1, c2, c > > INIT_XMM sse4 > > FILTER_3X3 > > %endif > > + > > +%macro SOBEL_MUL 2 > > + movzx ptrd, byte [c%1q + xq] > > + imul ptrd, [%2] > > + add rd, ptrd > > +%endmacro > > + > > +%macro SOBEL_ADD 1 > > + movzx ptrd, byte [c%1q + xq] > > + add rd, ptrd > > +%endmacro > > + > > +; void filter_sobel_avx512(uint8_t *dst, int width, > > +; float scale, float delta, const int *const matrix, > > +; const uint8_t *c[], int peak, int radius, > > +; int dstride, int stride) > > +%macro FILTER_SOBEL 0 > > +%if UNIX64 > > +cglobal filter_sobel, 4, 15, 7, dst, width, matrix, ptr, c0, c1, c2, c3, > > c4, > > c5, c6, c7, c8, r, x > > +%else > > +cglobal filter_sobel, 4, 15, 7, dst, width, rdiv, bias, matrix, ptr, c0, > > c1, > > c2, c3, c4, c5, c6, c7, c8, r, x > > +%endif > > +%if WIN64 > > + SWAP xmm0, xmm2 > > + SWAP xmm1, xmm3 > > + mov r2q, matrixmp > > + mov r3q, ptrmp > > + DEFINE_ARGS dst, width, matrix, ptr, c0, c1, c2, c3, c4, c5, c6, c7, > > c8, > > r, x > > +%endif > > + movsxdifnidn widthq, widthd > > + VBROADCASTSS m0, xmm0 > > + VBROADCASTSS m1, xmm1 > > + pxor m6, m6 > > + mov c0q, [ptrq + 0*gprsize] > > + mov c1q, [ptrq + 1*gprsize] > > + mov c2q, [ptrq + 2*gprsize] > > + mov c3q, [ptrq + 3*gprsize] > > + mov c4q, [ptrq + 4*gprsize] > > + mov c5q, [ptrq + 5*gprsize] > > + mov c6q, [ptrq + 6*gprsize] > > + mov c7q, [ptrq + 7*gprsize] > > + mov c8q, [ptrq + 8*gprsize] > > + > > + xor xq, xq > > + cmp widthq, mmsize/4 > > + jl .loop2 > > + > > + mov rq, widthq > > + and rq, mmsize/4-1 > > + sub widthq, rq > > + > > + mova m6, [sobel_perm] > > +.loop1: > > + movu xm3, [c2q + xq] > > + pmovzxbd m5, [c0q + xq] > > + vinserti32x4 ym3, [c6q + xq], 1 > > + pmovzxbd m4, [c8q + xq] > > + vinserti32x4 m2, m3, [c1q + xq], 2 > > + vinserti32x4 m3, [c5q + xq], 2 > > + vinserti32x4 m2, [c7q + xq], 3 > > + vinserti32x4 m3, [c3q + xq], 3 > > + vpermb m2, m6, m2 > > + psubd m4, m5 > > + vpermb m3, m6, m3 > > + mova m5, m4 > > + vpdpbusd m4, m2, [sobel_mulA] {1to16} > > + vpdpbusd m5, m3, [sobel_mulB] {1to16} > > + > > + cvtdq2ps m4, m4 > > + mulps m4, m4 > > + > > + cvtdq2ps m5, m5 > > + VFMADD231PS m4, m5, m5 > > + > > + sqrtps m4, m4 > > + fmaddps m4, m4, m0, m1 > > + cvttps2dq m4, m4 > > + vpmovusdb [dstq + xq], m4 > > + > > + add xq, mmsize/4 > > + cmp xq, widthq > > + jl .loop1 > > + > > + add widthq, rq > > + cmp xq, widthq > > + jge .end > > + > > +.loop2: > > + xor rd, rd > > + pxor m4, m4 > > + > > + ;Gx > > + SOBEL_MUL 0, data_n1 > > + SOBEL_MUL 1, data_n2 > > + SOBEL_MUL 2, data_n1 > > + SOBEL_ADD 6 > > + SOBEL_MUL 7, data_p2 > > + SOBEL_ADD 8 > > + > > + cvtsi2ss xmm4, rd > > + mulss xmm4, xmm4 > > + > > + xor rd, rd > > + ;Gy > > + SOBEL_MUL 0, data_n1 > > + SOBEL_ADD 2 > > + SOBEL_MUL 3, data_n2 > > + SOBEL_MUL 5, data_p2 > > + SOBEL_MUL 6, data_n1 > > + SOBEL_ADD 8 > > + > > + cvtsi2ss xmm5, rd > > + fmaddss xmm4, xmm5, xmm5, xmm4 > > + > > + sqrtps xmm4, xmm4 > > + fmaddss xmm4, xmm4, xmm0, xmm1 ;sum = sum * rdiv + bias > > + cvttps2dq xmm4, xmm4 ; trunc to integer > > + packssdw xmm4, xmm4 > > + packuswb xmm4, xmm4 > > + movd rd, xmm4 > > + mov [dstq + xq], rb > > + > > + add xq, 1 > > + cmp xq, widthq > > + jl .loop2 > > +.end: > > + RET > > +%endmacro > > + > > +%if ARCH_X86_64 > > +%if HAVE_AVX512ICL_EXTERNAL > > +INIT_ZMM avx512icl > > +FILTER_SOBEL > > +%endif > > +%endif > > diff --git a/libavfilter/x86/vf_convolution_init.c > > b/libavfilter/x86/vf_convolution_init.c > > index b78a47d02b..bff10ca1a4 100644 > > --- a/libavfilter/x86/vf_convolution_init.c > > +++ b/libavfilter/x86/vf_convolution_init.c > > @@ -29,6 +29,11 @@ void ff_filter_3x3_sse4(uint8_t *dst, int width, > > const uint8_t *c[], int peak, int radius, > > int dstride, int stride, int size); > > > > +void ff_filter_sobel_avx512icl(uint8_t *dst, int width, > > + float scale, float delta, const int *const matrix, > > + const uint8_t *c[], int peak, int radius, > > + int dstride, int stride, int size); > > + > > av_cold void ff_convolution_init_x86(ConvolutionContext *s) > > { > > #if ARCH_X86_64 > > @@ -44,3 +49,16 @@ av_cold void ff_convolution_init_x86(ConvolutionContext > > *s) > > } > > #endif > > } > > + > > +av_cold void ff_sobel_init_x86(ConvolutionContext *s, int depth, int > > nb_planes) > > +{ > > +#if ARCH_X86_64 > > + int cpu_flags = av_get_cpu_flags(); > > + for (int i = 0; i < nb_planes; i++) { > > + if (depth == 8) { > > + if (EXTERNAL_AVX512ICL(cpu_flags)) > > + s->filter[i] = ff_filter_sobel_avx512icl; > > + } > > + } > > +#endif > > +} > > diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile > > index 62d6616faf..a6f06c7007 100644 > > --- a/tests/checkasm/Makefile > > +++ b/tests/checkasm/Makefile > > @@ -46,6 +46,7 @@ AVFILTEROBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o > > AVFILTEROBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o > > AVFILTEROBJS-$(CONFIG_THRESHOLD_FILTER) += vf_threshold.o > > AVFILTEROBJS-$(CONFIG_NLMEANS_FILTER) += vf_nlmeans.o > > +AVFILTEROBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o > > > > CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes) > > > > diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c > > index 421bd096c5..3eb4780a64 100644 > > --- a/tests/checkasm/checkasm.c > > +++ b/tests/checkasm/checkasm.c > > @@ -197,6 +197,9 @@ static const struct { > > #if CONFIG_THRESHOLD_FILTER > > { "vf_threshold", checkasm_check_vf_threshold }, > > #endif > > + #if CONFIG_SOBEL_FILTER > > + { "vf_sobel", checkasm_check_vf_sobel }, > > + #endif > > #endif > > #if CONFIG_SWSCALE > > { "sw_gbrp", checkasm_check_sw_gbrp }, > > diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h > > index ee9151410e..214918e7ea 100644 > > --- a/tests/checkasm/checkasm.h > > +++ b/tests/checkasm/checkasm.h > > @@ -86,6 +86,7 @@ void checkasm_check_vf_eq(void); > > void checkasm_check_vf_gblur(void); > > void checkasm_check_vf_hflip(void); > > void checkasm_check_vf_threshold(void); > > +void checkasm_check_vf_sobel(void); > > void checkasm_check_vp8dsp(void); > > void checkasm_check_vp9dsp(void); > > void checkasm_check_videodsp(void); > > diff --git a/tests/checkasm/vf_convolution.c > > b/tests/checkasm/vf_convolution.c > > new file mode 100644 > > index 0000000000..007865863e > > --- /dev/null > > +++ b/tests/checkasm/vf_convolution.c > > @@ -0,0 +1,104 @@ > > +/* > > + * This file is part of FFmpeg. > > + * > > + * FFmpeg is free software; you can redistribute it and/or modify > > + * it under the terms of the GNU General Public License as published by > > + * the Free Software Foundation; either version 2 of the License, or > > + * (at your option) any later version. > > + * > > + * FFmpeg is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > + * GNU General Public License for more details. > > + * > > + * You should have received a copy of the GNU General Public License along > > + * with FFmpeg; if not, write to the Free Software Foundation, Inc., > > + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > > + */ > > + > > +#include > > +#include "checkasm.h" > > +#include "libavfilter/avfilter.h" > > +#include "libavfilter/convolution.h" > > +#include "libavutil/intreadwrite.h" > > +#include "libavutil/mem_internal.h" > > + > > +#define WIDTH 512 > > +#define HEIGHT 512 > > +#define SRC_STRIDE 512 > > +#define PIXELS (WIDTH * HEIGHT) > > + > > +#define randomize_buffers(buf, size) \ > > + do { \ > > + int j; \ > > + uint8_t *tmp_buf = (uint8_t *)buf;\ > > + for (j = 0; j< size; j++) \ > > + tmp_buf[j] = rnd() & 0xFF; \ > > + } while (0) > > + > > +static void check_sobel(const char * report_name) > > +{ > > + LOCAL_ALIGNED_32(uint8_t, src, [PIXELS]); > > + LOCAL_ALIGNED_32(uint8_t, dst_ref, [PIXELS]); > > + LOCAL_ALIGNED_32(uint8_t, dst_new, [PIXELS]); > > + const int height = WIDTH; > > + const int width = HEIGHT; > > + const int stride = SRC_STRIDE; > > + const int dstride = SRC_STRIDE; > > + int mode = 0; > > + const uint8_t *c[49]; > > + const int radius = 1; > > + const int bpc = 1; > > + const int step = mode == MATRIX_COLUMN ? 16 : 1; > > + const int slice_start = 0; > > + const int slice_end = height; > > + int y; > > + const int sizew = mode == MATRIX_COLUMN ? height : width; > > + float scale = 2; > > + float delta = 10; > > + > > + ConvolutionContext s; > > + > > + declare_func(void, uint8_t *dst, int width, float scale, float delta, > > const int *const matrix, > > + const uint8_t *c[], int peak, int radius, int dstride, int > > stride, int size); > > + > > + s.scale = scale; > > + s.delta = delta; > > + s.depth = 8; > > + s.nb_planes = 3; > > + s.planes = 15; > > + ff_sobel_init(&s, s.depth, s.nb_planes); > > + > > + memset(dst_ref, 0, PIXELS); > > + memset(dst_new, 0, PIXELS); > > + randomize_buffers(src, PIXELS); > > + > > + if (check_func(s.filter[0], "%s", report_name)) { > > + for (y = slice_start; y < slice_end; y += step) { > > + const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * > > bpc > > : radius * bpc; > > + const int yoff = mode == MATRIX_COLUMN ? radius * dstride : 0; > > + > > + s.setup[0](radius, c, src, stride, radius, width, y, height, > > bpc); > > + call_ref(dst_ref + yoff + xoff, sizew - 2 * radius, > > + scale, delta, NULL, c, 0, radius, > > + dstride, stride, slice_end - step); > > + call_new(dst_new + yoff + xoff, sizew - 2 * radius, > > + scale, delta, NULL, c, 0, radius, > > + dstride, stride, slice_end - step); > > + if (memcmp(dst_ref + yoff + xoff, dst_new + yoff + xoff, > > slice_end - step)) > > + fail(); > > + bench_new(dst_new + yoff + xoff, sizew - 2 * radius, > > + scale, delta, NULL, c, 0, radius, > > + dstride, stride, slice_end - step); > > + if (mode != MATRIX_COLUMN) > > + dst_ref += dstride; > > + } > > + } > > + > > +} > > + > > +void checkasm_check_vf_sobel(void) > > +{ > > + check_sobel("sobel"); > > + report("convolution:sobel"); > > +} > > diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak > > index aa9b288e12..a4e95541f5 100644 > > --- a/tests/fate/checkasm.mak > > +++ b/tests/fate/checkasm.mak > > @@ -43,6 +43,7 @@ FATE_CHECKASM = fate-checkasm- > > aacpsdsp \ > > fate-checkasm-vf_hflip \ > > fate-checkasm-vf_nlmeans \ > > fate-checkasm-vf_threshold \ > > + fate-checkasm-vf_sobel \ > > fate-checkasm-videodsp \ > > fate-checkasm-vorbisdsp \ > > fate-checkasm-vp8dsp \ > > LGTM and it works well for me, I saw a significant FPS improvement when > running > the command below. > > $ ffmpeg -i 1920x1080.mp4 -vf "sobel" -f null - > Does anyone else have any thought on this patch? I will merge it if there are no more comments. Thanks Haihao _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".