From patchwork Thu Aug 18 08:43:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Bin" X-Patchwork-Id: 37346 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp184667pzh; Thu, 18 Aug 2022 01:43:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR7qs/jssmni1pVXkrme7+vxs+WApDqFAmvNGar3oCj9jho70uAOSKQz6oahAIwAPEUs9Lcb X-Received: by 2002:a17:906:fd84:b0:730:acee:d067 with SMTP id xa4-20020a170906fd8400b00730aceed067mr1337358ejb.206.1660812202547; Thu, 18 Aug 2022 01:43:22 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cs1-20020a0564020c4100b0043d35059c65si842384edb.160.2022.08.18.01.43.21; Thu, 18 Aug 2022 01:43:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=alnG6aL0; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A964268B9B1; Thu, 18 Aug 2022 11:43:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4E0CF68B5B7 for ; Thu, 18 Aug 2022 11:43:11 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660812196; x=1692348196; h=from:to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version; bh=Dh3MJe2KyQfZHB+GztaFSzj/v4FeQr/gLc5xyhZA3BU=; b=alnG6aL0yQATg4zm2ZUUvSDV+Jx8CLiMjYd/arA+Balbkjso+ONEe8rK VrBKrSD6G7WVIbZaGYpjvrvWCpDYe/5xkJwSQxgPMc6i49VhxBPDCJhrb NI1xTLB6TvxSz5yBmglR20qRfz7Cdm01u3Lk7/qvuOoFpjgH6sufqZ52e gy7uUi9SboF0jTvhjTPacLL92kqfP7r3vwd+gpbdUWK1riJiRTzu/QwaI bmRxs/quYrEJ0zdUCpeMkQbLkdbuoLZ7SS66v4sEwNuMoVc1utN9iLIZc A/5euIFfHK2OgGrfcNjEII1PvQZQsPOf7KC3IzlEpHKRck1TQorkINBq1 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10442"; a="354443811" X-IronPort-AV: E=Sophos;i="5.93,246,1654585200"; d="scan'208";a="354443811" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2022 01:43:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,246,1654585200"; d="scan'208";a="935723959" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga005.fm.intel.com with ESMTP; 18 Aug 2022 01:43:08 -0700 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 18 Aug 2022 01:43:08 -0700 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 18 Aug 2022 01:43:08 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28 via Frontend Transport; Thu, 18 Aug 2022 01:43:08 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.101) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.28; Thu, 18 Aug 2022 01:43:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DHUJ02wNmRhqY9yMUKp/YKf72zpahoh/OA2izPbSTAPK+l4yiM6kH5EK+K0rNWzsA1X5jtsZL5kGbM4mLlPO3BV6J0yHD42VqXbEn8y02+DW2k7aei03XKr1OK8mKuZL/tK3MCy4nViUmY5Z4v1kNmzUphgdKrgH8F5/0oiMrXVGS9abYmNh8c5I1GzLf/wf9/5sReyYCIXViHxxPvQ0KVPwxOCxVL+91rliFYrUxYdzp8e3nlClibXPBkK++8veJ+0i47JP4Xull7jm7iwDrMpJfDrOsh2ADnwLYjjOjq/JU8NJRMpJzcRnBFhlC702HuyB+KBLv9ZKHwj5Ur4EgQ== 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=G8ZHZkE0x5Q1FmmvSYFSACy6QE/UhKma4ijwwbetbaE=; b=QY6fCt8FtvFp7Vcd/pmmXFBgt/+YuDzz3T8RfSJ9vNmJbLYEdVdGAlrVQx29+xfN6B+b1EWBfjjSY7lW2vGda8L6FUxnDUUE9u3eeUl7RzvVD9UYbSq2PL81dt1/5Inl1KdDb12vkPIp4BNRZwGomXX0637Bg868TDJQNkkxeXM/xGZWIyZ1riAfFFR6rlWQ4YQ9Jr0wlWulRWsY5O3aPKEdjsMedqo+PI3gkJxRCXRZKg4J+3Jk8J+TPcL0RxVrT5Ld2lsSDgB7L3y6w8OaOe3LnZPboHI+/jvf4pfLP0yzJcyklJ8E7X1dcxbvhe+83Rv8bkAT7oJAqp3u7k2Rpw== 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 BN6PR11MB1746.namprd11.prod.outlook.com (2603:10b6:404:fb::20) by CY8PR11MB6913.namprd11.prod.outlook.com (2603:10b6:930:5b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.10; Thu, 18 Aug 2022 08:43:06 +0000 Received: from BN6PR11MB1746.namprd11.prod.outlook.com ([fe80::7c83:a5cb:7ab7:cf8d]) by BN6PR11MB1746.namprd11.prod.outlook.com ([fe80::7c83:a5cb:7ab7:cf8d%12]) with mapi id 15.20.5525.019; Thu, 18 Aug 2022 08:43:06 +0000 From: "Wang, Bin" To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [FFmpeg-devel] [PATCH v2] libavfilter/x86/vf_convolution: add sobel filter optimization and unit test with intel AVX512 VNNI Thread-Index: AQHYsGwdUAU1CrHPzkm/p32zJhH7fq20W5rA Date: Thu, 18 Aug 2022 08:43:06 +0000 Message-ID: References: <20220815053844.30298-1-bin.wang@intel.com> In-Reply-To: <20220815053844.30298-1-bin.wang@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 473c8a41-abaa-4aa9-c29f-08da80f5abab x-ms-traffictypediagnostic: CY8PR11MB6913:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: b/2UIu3so1r3PKYjWPln+/yQXVf5NTflFM7BoeDknpGHzVKviECAw3KsmWjEEEFJALTjzAyvIqvv0bceeSqkU0sUooRXeDM+aNVmQdKd4aXw4R7gptPPHlJNa8utanldClD3mVhFBKWQUmq9fu45Z6+DvkQ9bRiYKOSR4j4Y4nObZadhDraCd7E9juArzmO3elm1zGCt2fWYPu7dO4wWhrIsbbtDyI41xyr/Ge1J/Vse5OraJnyJkrs9pUqHyRPgzTfDHZbbYQBvwif/FEmyFC6LyAGO8QKu9r22qwt0+lHNb4r8NAWOHCgKg0IJcuxtVu9q2bO4D7mDlWcYlBoyF2mlbe5YdNs9rfwSjmslb7oItZJg44xXVipurIQkeAyctCz5YR1+mI9lan1paxM9vhqokXoE1YfViSQldn7n8yx7/x3goQbiCTK5+KhJ6vInI6Jf2lTTc3SrRVP5nyxVjp5XNZ6Bt1xaltkHsHdm4w4opvAYoGoCLAF8lmFvMGeboCxeZZs8PJ84J3Jh5A0V4zb82kI4dEwMk5LSYge65IngmqcIgEVBuBj3vE1VLTLjekVWZ3UZSabUq9MaKaGlV/jVo3pV3GBUnm3woILdxFjbFxBCjUoeq0KRF/9jeB0/FDnWXyZQ7H3xg+pq0UEkAVIzT0Ms2MIqdv9CawciVFUe/+fLFaMtD/eP1sQVNTvGgZtGymgYQiGSJuCYnCB+ieIj1lChj3WRX5tZ6y1CoBgo8Om0aSMG2NauA4dWJGfOOPExtW0XCLFr/fEKs0FuIHYk8o2uRPGaIlp7nH/4Cok= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR11MB1746.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(136003)(346002)(396003)(376002)(39860400002)(366004)(38100700002)(316002)(122000001)(52536014)(8936002)(9686003)(66946007)(76116006)(8676002)(2906002)(64756008)(26005)(66476007)(66556008)(86362001)(478600001)(66446008)(82960400001)(38070700005)(71200400001)(33656002)(6506007)(7696005)(53546011)(41300700001)(30864003)(5660300002)(83380400001)(55016003)(6916009)(186003)(2004002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: HMwE3cwY3DJxwTng0Pj9sZtYLJ6MRIDe9Zkh3u6dSidm3ArINHfuD6q2z0aRGzZfqEJ7vzktvlhAx3RYMAw/t8YYtnMSmyRablfQzhQkV1jfoMrCtjEKGkT0ptZQ/Up0A8mSU1DyBU9IR+t4CJIgyRTmKIEw6r4TU8TRWcUoPMEBFMuIarU3nT/sRGGzpCSwQ7HVScJ+bXRSrQRzqSojoYSa+zASgTvp8iBQUI3OIXM4xctm5dOmz8wA4auokDZEYyzsz2mRuhaHZsmUkpJvtghebk2Nv3PlLPSQDIg11iMWZApkZgTvauoR4nxNWr+rD3a8eo4Utk/6IOQlDyejMrZ1AOVwkcqlWvmoMu6ECiDADBJH+G/NNufrTHWD3QkXBYDVPfVt47CaKtF82h14/qGb72AKl7bK85RTkL+5Ts4C68RupKm9Xz4IhiG5OwB1M+N3jvpZRlA6lUckdpWatm7N+tpAN/sLog0iTGMgJeP6CYkVyZjMQBvX0p3zYAQtodTflLlIbbVCtgc8kCzgUOYRpoF07afUYWQGfgU2cCyUJN4Ov5LG089svnRk6Ef5tbvYBCscUA5XzUjmEOi+awTH5IHGZ0AdMyHm+Oz3C35lqDlwK6EdZd+V8KyPighcgR2jBregBmOehDDrFtPfZGRBkzg70KLU3YtrRkC1vdlgp7BPSQz0MK4Zp3wbPxicw/QT17OL++G6zFFbtY1oGeP0nOkgOHdVBfKIdrcTfbGeMMzakDMnzMSqN7YS/WBpLtOdWwun2KYNfNOowsV0Wjj94ytrR7hfS5mXNeTuEf39GZdk1l/n8YbDK1Up6/HOxfYk85RMb5lnZ47XFscCR6A0nZzWsa0m84RlqhFyHqD2d/tp7FFuO3BZKXzjZ+r7+i2IohGcpoy+0V/31VM6m8fVwfL0YG+fu/JO5ltIEL4QdGouI88JnxY1T9j3gyVeq8PnfXDJup97ExSk4D1qKjRPB/4zVX0OuQTkudyE8UW3LwqkACxXR2UmTJM/2cbKHUaUl/aY6/VojqfjSqyIabOefTFJyDNiQhZ66jGXrtob1sCZQI3JPALWpkIm4lmxiuruLNtDnZRtwSViYZVOSMypmhryD3pYRm4ftU/DhsiRtNpjgGHGyfdClom5wHDcZJXQhTypyASP/jlEvteTInMH7gV9DhBDzJUi9lrf/5IBLEXf/UczRg2U3lzvwS6b9ZOKQTCIUuGfuNlbf213KJ4R90N2GhtIwE7UYRV/RsPATNKqc3tatH7OOgGylYati6l8Odm7dzA6m2o3i0kKjdQagPAwshtFp9i8IrGD2X8qkTlS1/2fMJcx1v/UvAZGTje04YSSqRl4+vCf/mHaI28Ppwxpn2H7JDrqdkGsZkV7Kpn4064E3MP5MqOuO9BRsTZFpR8wJRhLKYun23o3os56era8ZXH/ux4NCmRVy+VaYmxR+hilr50YHFED85fWyo0nyM2dIG4P88PE2QkRRuyWskn6OqA5kwyN7D5xbvDLrb9ltfjIZoAXJYo1JKuOAkfe51tJ69dVu/yZDOeV4EXHvlkmhZ+v05CHhgF48/Y8pPvzQSNvw6fBS1ify6kt MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN6PR11MB1746.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 473c8a41-abaa-4aa9-c29f-08da80f5abab X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Aug 2022 08:43:06.1224 (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: xnI4g05GKb63moJ1P/r+z+fSH2zE4bMTCAp5nuK5x7lc6xEKzTBb5WkydJ+aOAambU5FvjmhngL3qjvjJrSbpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB6913 X-OriginatorOrg: intel.com Subject: [FFmpeg-devel] [PATCH v2] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bqVwFU+OsOKW Any comments on this patch V2? -----Original Message----- From: Wang, Bin Sent: Monday, August 15, 2022 1:39 PM To: ffmpeg-devel@ffmpeg.org Cc: Wang, Bin Subject: [FFmpeg-devel] [PATCH v2] libavfilter/x86/vf_convolution: add sobel filter optimization and unit test with intel AVX512 VNNI From: bwang30 This commit enabled assembly code with intel AVX512 VNNI and added unit test for sobel filter sobel_c: 4537 sobel_avx512icl 2470 Signed-off-by: bwang30 --- libavfilter/convolution.h | 2 + libavfilter/vf_convolution.c | 23 ++++ libavfilter/x86/vf_convolution.asm | 162 ++++++++++++++++++++++++++ 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 | 103 ++++++++++++++++ 8 files changed, 313 insertions(+) create mode 100644 tests/checkasm/vf_convolution.c +/* + * 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; + + s.scale = scale; + s.delta = delta; + s.depth = 8; + s.nb_planes = 3; + ff_convolution_init(&s, "sobel"); + + 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); + + 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_convolution(void) +{ + check_sobel("sobel"); + report("convolution:sobel"); +} -- 2.27.0 diff --git a/libavfilter/convolution.h b/libavfilter/convolution.h index 88aabe9a20..4520ad13e0 100644 --- a/libavfilter/convolution.h +++ b/libavfilter/convolution.h @@ -61,4 +61,6 @@ typedef struct ConvolutionContext { } ConvolutionContext; void ff_convolution_init_x86(ConvolutionContext *s); +void ff_sobel_init_x86(ConvolutionContext *s); void +ff_convolution_init(ConvolutionContext *s, const char *filter_name); #endif diff --git a/libavfilter/vf_convolution.c b/libavfilter/vf_convolution.c index 9a9c099e6d..f27385a7fb 100644 --- a/libavfilter/vf_convolution.c +++ b/libavfilter/vf_convolution.c @@ -874,6 +874,9 @@ static int param_init(AVFilterContext *ctx) if (s->depth > 8) for (p = 0; p < s->nb_planes; p++) s->filter[p] = filter16_sobel; +#if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64 + ff_sobel_init_x86(s); +#endif } else if (!strcmp(ctx->filter->name, "kirsch")) { if (s->depth > 8) for (p = 0; p < s->nb_planes; p++) @@ -887,6 +890,26 @@ static int param_init(AVFilterContext *ctx) return 0; } +void ff_convolution_init(ConvolutionContext *s, const char +*filter_name) { + if (!strcmp(filter_name, "sobel")) { + 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 +CONFIG_CONVOLUTION_FILTER && ARCH_X86_64 + ff_sobel_init_x86(s); +#endif + } +} + static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; diff --git a/libavfilter/x86/vf_convolution.asm b/libavfilter/x86/vf_convolution.asm index 754d4d1064..59c807b218 100644 --- a/libavfilter/x86/vf_convolution.asm +++ b/libavfilter/x86/vf_convolution.asm @@ -22,6 +22,10 @@ SECTION_RODATA half: dd 0.5 +data_p1: dd 1 +data_n1: dd -1 +data_p2: dd 2 +data_n2: dd -2 SECTION .text @@ -154,3 +158,161 @@ 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_16 3 + movd xmm2, [%2] + VPBROADCASTD m2, xmm2 + movdqu xmm3, [c%1q + xq] + vpmovzxbd m3, xmm3 + vpdpbusd m%3, m3, m2 +%endmacro + +%macro SOBEL_ADD_16 2 + movdqu xmm3, [c%1q + xq] + vpmovzxbd m3, xmm3 + vpaddd m%2, m3 +%endmacro + + +%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 + +.loop1: + pxor m4, m4 + pxor m5, m5 + + ;Gx + SOBEL_MUL_16 0, data_n1, 4 + SOBEL_MUL_16 1, data_n2, 4 + SOBEL_MUL_16 2, data_n1, 4 + SOBEL_ADD_16 6, 4 + SOBEL_MUL_16 7, data_p2, 4 + SOBEL_ADD_16 8, 4 + + cvtdq2ps m4, m4 + mulps m4, m4 + + ;Gy + SOBEL_MUL_16 0, data_n1, 5 + SOBEL_ADD_16 2, 5 + SOBEL_MUL_16 3, data_n2, 5 + SOBEL_MUL_16 5, data_p2, 5 + SOBEL_MUL_16 6, data_n1, 5 + SOBEL_ADD_16 8, 5 + + cvtdq2ps m5, m5 + VFMADD231PS m4, m5, m5 + + sqrtps m4, m4 + mulps m4, m0 ; sum *= scale + addps m4, m1 ; sum += delta + cvttps2dq m4, m4 + vpmovusdb xmm4, m4 + movdqu [dstq + xq], xmm4 + + 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 + mulss xmm5, xmm5 ; b1 * b1 + addss xmm4, xmm5 + + sqrtps xmm4, xmm4 + mulss xmm4, xmm0 ; sum *= rdiv + addss xmm4, xmm1 ; sum += 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..52a3d28991 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) { #if ARCH_X86_64 + int cpu_flags = av_get_cpu_flags(); + for (int i = 0; i < s->nb_planes; i++) { + if (s->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 1ac170491b..4e91547fde 100644 --- a/tests/checkasm/Makefile +++ b/tests/checkasm/Makefile @@ -44,6 +44,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_CONVOLUTION_FILTER) += vf_convolution.o CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index e56fd3850e..ae5e9d1143 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -191,6 +191,9 @@ static const struct { #if CONFIG_THRESHOLD_FILTER { "vf_threshold", checkasm_check_vf_threshold }, #endif + #if CONFIG_CONVOLUTION_FILTER + { "vf_convolution", checkasm_check_vf_convolution }, + #endif #endif #if CONFIG_SWSCALE { "sw_gbrp", checkasm_check_sw_gbrp }, diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index d7645d3730..71c722cf77 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -85,6 +85,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_convolution(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..a10da8b45e --- /dev/null +++ b/tests/checkasm/vf_convolution.c @@ -0,0 +1,103 @@