Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcqW4-002TGI-Uc for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Feb 2024 17:36:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rcqW3-005lRU-EW for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Feb 2024 17:36:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcqW2-005lRM-JS for pgsql-hackers@lists.postgresql.org; Wed, 21 Feb 2024 17:36:19 +0000 Received: from mgamail.intel.com ([198.175.65.15]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcqVx-000CoS-Bw for pgsql-hackers@lists.postgresql.org; Wed, 21 Feb 2024 17:36:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708536973; x=1740072973; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=c064pfHJ3fFaewSON+QADz3qJQsSsAhi4y+jejlA0To=; b=leCVTtmbzR9/miqhiu2ShGXFJ+4oeQUUCoT593IHlS9PS6Xp0dCyv7Ya g+vtaaRQONXDI3GGKed87G0jvXLbwFlsVqn+3ODGUP6kGKbzCzD39COkI RiDnUrlbFGTcW7e7xPYXB+Cz6SabxNhdgddJRS0fqoKrAiPUk6dXf9yO7 Ctu9nkQn06xcIoh0f1ZJ7eVFcNSnbh2EyqTp5Vs/3ho2XkTOMSIWDXe4F QnR105mEF1j5Ore5nIpWJJQIdACLC0rSC8Ymy3sJxDa32ikXJX1ksgSbZ 8kWQCHzsYv7LODDsorAvZR6wdSgZvZ9MARAwcQUKG89eU7swlVrK/ndym g==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="6542924" X-IronPort-AV: E=Sophos;i="6.06,176,1705392000"; d="scan'208";a="6542924" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 09:36:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,176,1705392000"; d="scan'208";a="9794806" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmviesa004.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 21 Feb 2024 09:36:06 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 21 Feb 2024 09:36:05 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) 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.2507.35 via Frontend Transport; Wed, 21 Feb 2024 09:36:05 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.41) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 21 Feb 2024 09:36:05 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RCoVFNC1Aa3g8Fn3MI59Q6GbMDeJzZiLgnr4rqa6VDUuIG/lyLHxAT39MVIIN1Kw6TS/+QfMXnQOw8h0PLK2v8Y9vsd543375sI4RSjawevX+jrwphDuM3Lgx/kw0SzpsmznAu6oHuMkU7MBvEfBBqHsN8SXUUCxhXGof5P5tIjdmnC2eY/Z6ZmuxoGEAfedxUrnkK9FMRzZ9IrR9zfIvweMHJYUgHeU4Vlx0ROr57ClduM9ParuW2V9Vk6Ju6wBHdGuCZHx6hhUIrFEpwzg8k+mvYKa3k85mYTHIb78VsB0ZCqxNNM54vliDMSu5886/k6ig3obsZcl67kXCq2qLg== 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=obiYObYLD9cNg9N9l0wizdjfuvguxKvam4Fz6glxnDk=; b=HwROeVfYkFYNWRfYeccETLCCtDiEXnBsrN6p565qRToIYtCIBLFKQxR6YD8LQ+peqfoYgTkNvNyq/RVTo+h1qtRF4TN4fs/59pqXMZ2btSkH4tWvEhkZo8neCSu3Tw8Hsj0Oduc/PSv/RC6JiBfSgWU7opVDPdTh9gugTIFmHmYmtZacZsfsmFvW3RPN8tU53fC5jCBqOaALzzK80se62/tgPIYTkiImkfrp817DUJigXMmKUj9KJwT93ye96D7uIFDGtnNW1J8lEi8n9P1zX5kBDpv73h6dF9xgrdm9kPPp04VZSRstt61clGwkGki41Xyc5SzpZl/HY5p3HFJ1gw== 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 BL1PR11MB5304.namprd11.prod.outlook.com (2603:10b6:208:316::20) by IA1PR11MB7891.namprd11.prod.outlook.com (2603:10b6:208:3fa::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.39; Wed, 21 Feb 2024 17:35:58 +0000 Received: from BL1PR11MB5304.namprd11.prod.outlook.com ([fe80::8d3b:ce2a:a9e1:f03b]) by BL1PR11MB5304.namprd11.prod.outlook.com ([fe80::8d3b:ce2a:a9e1:f03b%4]) with mapi id 15.20.7292.036; Wed, 21 Feb 2024 17:35:57 +0000 From: "Amonson, Paul D" To: Andres Freund CC: Alvaro Herrera , "Shankaran, Akash" , Nathan Bossart , "Noah Misch" , Tom Lane , "Matthias van de Meent" , "pgsql-hackers@lists.postgresql.org" Subject: RE: Popcount optimization using AVX512 Thread-Topic: Popcount optimization using AVX512 Thread-Index: AdoNliAXaie8RHrzTICrAiLVKKiYCgAsQKyAALaJTAAAAQ7nAAAAxSWAAAGNHgAAA/mZgAAeFdGAAZKQbBAAAw6egA3NuLcAAAvVM4ACbQuxsAAhlXkAAHPWMbAAAkOrAACYCUjgAAMc3wABvefW4A== Date: Wed, 21 Feb 2024 17:35:57 +0000 Message-ID: References: <202402071013.reqe3bdnjjuj@alvherre.pgsql> <20240209183450.snllkk7erharc73y@awork3.anarazel.de> <20240212203714.u4p7yeu7isuemmze@awork3.anarazel.de> In-Reply-To: <20240212203714.u4p7yeu7isuemmze@awork3.anarazel.de> 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-traffictypediagnostic: BL1PR11MB5304:EE_|IA1PR11MB7891:EE_ x-ms-office365-filtering-correlation-id: f6eeeaf1-bcd0-4c65-64f4-08dc3303905a x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pIAx3nauZZoTcR7DOaj4BmSuwnlARMt0MXfbmN6BbxTBL49IemtEPpK9wkZiCt7j/wzf48+fiiqTU5vQGz8zEiSXH6UsygtZJuWswYN0UmGvjadKJFjsTWgpqtXZQKtrxX8G08FRBSj/Ewf21PM8G1k/ZJP59lx0a02MiMArp/wt8B1Z/mxhUULDGmu2AywTPJ1kIFPPG25hM2Wq7yydo8wol2Cr5d01xPwVnHiEdIqlh8WmKOSP2aLg2JgOzUH4mjI0TLdim8kY8AiSXAxHvs0IdP+AC1VOh91DPeUWgUtQ+KHmhnLgvojgREmCjPTiowhVELDfbLCfkhUGVyW2MVNU7ln3b46tZEqYxW+OchVhFfUfqrufav/77wyjh4gJmH/O/KT2tryP5vAxY6ZZ8NpM8hD2O6PtWPuMDNFP67WtSjtKGwf1jOYzwFXwe4F3/gsCp+yjrUlDxhw3BvOs4e8CMWWcNf5f5jdG3KevQn5qKizO34GbX88Rv66pDarNdgFqO5o80nX9z01tbsXD6kbfXNUOjsfbSZS4IEFNRCVr3oV4N+XGjFAg0QLYCGRMhJdF+DLaHsNUx9/enK8zHpfWRbPCfDzga/OEBWrdzCA= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL1PR11MB5304.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?917Rg5+HZKT+flFPuXk87ituoUFm4d3I7PHKNP71vj6YoMqAo1VqDIGWW0hJ?= =?us-ascii?Q?Y3f49U+bQcoMpl+GL85NhIwZda4Xh2OWnzrsOfufc31FKI9NP3LXmOqzxe7K?= =?us-ascii?Q?Yw2zp//v6R36DEO3Z5ozeSNPTrTScdN0365HB3l/KAI93Vi8N2j1/G7ReiEW?= =?us-ascii?Q?v+wzQZCsgIxNrPJ+kUkOp4Ux+jkxO0KXJ4G2tETSiBlXr2erJbqQfDqZ4N6A?= =?us-ascii?Q?CzHgxmL4IpUEstfdRaBxruPI1atfJctboDBRJI/6AnWYVkCU/kc8DyhJrHqh?= =?us-ascii?Q?urlcXaC3Evqf6lb1jH51Zh+v8kByX3YKHJEQF4N+phJDRJTNMLCaB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/5Z5Jy6Nm5qWLgoXl3gCaYyREc38qpm2d9Xi?= =?us-ascii?Q?L0ZdS9bNgWaVHBxYNyqHWA1LBUK7EQH8qmTHuThIzfa7Ubs9GEn3tyLYM87p?= =?us-ascii?Q?1n+Oewvg/eN8+xTgE2fbnMAhLlmi4/H4mARRu7t3NKvTWTm3g6l6PFBQ7JqR?= =?us-ascii?Q?sAfWvoSl/ZGQcvNJspnSfoX3FVquMcUsNlWvUb8X+0Hq07QeoGoZiy/DQ68O?= =?us-ascii?Q?VK/kqSW1jNymLoO39A0Pr/t2NXZyeaYQ/rgp5hnbCBGU9JZqHGN9McVF02M/?= =?us-ascii?Q?UY8tZOW1z3F/TwBsFZxsjoQx9ofpt9WnLlKJbCRO+sqEUDdK2kF2QV8Vdf2l?= =?us-ascii?Q?jWfp/I+l4eoAfh4A/mqhFHMyMyqhTXHxWbTR9ANc?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BL1PR11MB5304.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6eeeaf1-bcd0-4c65-64f4-08dc3303905a X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Feb 2024 17:35:57.9315 (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: jqRPxOkxONj9+OmDC9Ma2Pkeu3Zut6lADdVTrnmOphpOxEJlholqDgcKdjSTwilEQuZxGcYy8MSleAQ7yvefwM1a3abGlTmd/Ka9A0gJ3JQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR11MB7891 X-OriginatorOrg: intel.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I am encountering a problem that I don't think I understand. I cannot get t= he MSVC build to link in CI. I added 2 files to the build, but the linker i= s complaining about the original pg_bitutils.c file is missing (specificall= y symbol 'pg_popcount'). To my knowledge my changes did not change linking = for the offending file and I see the compiles for pg_bitutils.c in all 3 li= bs in the build. All other builds are compiling. Any help on this issue would be greatly appreciated. My fork is at https://github.com/paul-amonson/postgresql/tree/popcnt_patch = and the CI build is at https://cirrus-ci.com/task/4927666021728256. Thanks, Paul -----Original Message----- From: Andres Freund =20 Sent: Monday, February 12, 2024 12:37 PM To: Amonson, Paul D Cc: Alvaro Herrera ; Shankaran, Akash ; Nathan Bossart ; Noah Misch ; Tom Lane ; Matthias van de Meent ; pgsql-hackers@lists.postgresql.org Subject: Re: Popcount optimization using AVX512 Hi, On 2024-02-12 20:14:06 +0000, Amonson, Paul D wrote: > > > +# Check for header immintrin.h > > ... > > Do these all actually have to link? Invoking the linker is slow. > > I think you might be able to just use cc.has_header_symbol(). > > I took this to mean the last of the 3 new blocks. Yep. > > Does this work with msvc? > > I think it will work but I have no way to validate it. I propose we remov= e the AVX-512 popcount feature from MSVC builds. Sound ok? CI [1], whould be able to test at least building. Including via cfbot, auto= matically run for each commitfest entry - you can see prior runs at [2]. T= hey run on Zen 3 epyc instances, so unfortunately runtime won't be tested. = If you look at [3], you can see that currently it doesn't seem to be consi= dered supported at configure time: ... [00:23:48.480] Checking if "__get_cpuid" : links: NO [00:23:48.480] Checkin= g if "__cpuid" : links: YES ... [00:23:48.492] Checking if "x86_64: popcntq instruction" compiles: NO ... Unfortunately CI currently is configured to not upload the build logs if th= e build succeeds, so we don't have enough details to see why. > > This will build all of pgport with the avx flags, which wouldn't be cor= rect, I think? The compiler might inject automatic uses of avx512 in places= , which would cause problems, no? > > This will take me some time to learn how to do this in meson. Any=20 > pointers here would be helpful. Should be fairly simple, add it to the replace_funcs_pos and add the releva= nt cflags to pgport_cflags, similar to how it's done for crc. > > While you don't do the same for make, isn't even just using the avx512 = for all of pg_bitutils.c broken for exactly that reson? That's why the exis= ting code builds the files for various crc variants as their own file. > > I don't think its broken, nothing else in pg_bitutils.c will make use=20 > of > AVX-512 You can't really guarantee that compiler auto-vectorization won't decide to= do so, no? I wouldn't call it likely, but it's also hard to be sure it won= 't happen at some point. > If splitting still makes sense, I propose splitting into 3 files: pg_bit= utils.c (entry point +sw popcnt implementation), pg_popcnt_choose.c (CPUID = and xgetbv check) and pg_popcnt_x86_64_accel.c (64/512bit x86 implementatio= ns). > I'm not an expert in meson, but splitting might add complexity to meson.b= uild. > > Could you elaborate if there are other benefits to the split file approac= h? It won't lead to SIGILLs ;) Greetings, Andres Freund [1] https://github.com/postgres/postgres/blob/master/src/tools/ci/README [2] https://cirrus-ci.com/github/postgresql-cfbot/postgresql/commitfest%2F4= 7%2F4675 [3] https://cirrus-ci.com/task/5645112189911040