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 1r3Nkt-003SVs-4r for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Nov 2023 21:49:03 +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 1r3Nkq-002xwz-Pd for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Nov 2023 21:49:00 +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 1r3Nkq-002xwr-Fb for pgsql-hackers@lists.postgresql.org; Wed, 15 Nov 2023 21:49:00 +0000 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r3Nkn-006crp-Fl for pgsql-hackers@lists.postgresql.org; Wed, 15 Nov 2023 21:48:59 +0000 Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-3594cb642beso577925ab.3 for ; Wed, 15 Nov 2023 13:48:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700084935; x=1700689735; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=NU0sN+5tVJMg+L9Qw8i6mp9LA6Lgpw8uuBxzTphm+mA=; b=NRndfBpmnL5iwO6pH0jZKcb+bUPGwi2ayeYo90obEdUkVD6KpcnPQcEgNDjERtOhH1 pmrDN23BzeH8nrjBZea+d62qpf6D867Gri47p1o2Exyq6HVqZQG5gr1fqMKDT+EE10rO KLpKh8ZN//Afizfntwv0x+VL6QsbeyYOTGy49QgpE6pTJeQTr/KgsC3bDdULUBfWBENA VMKAmy7DsmQmqs7gftB55QQX8Vp//06a60pkqy89skrf+jaqRLHeTMYf2WYcRm1QwvBx aXrq6rjhDini029O9j7HRdy0nkV2m7tqkooT28cSGPacO3md3uYZZ7ANLuM8ihnsSBXo VMBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700084935; x=1700689735; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NU0sN+5tVJMg+L9Qw8i6mp9LA6Lgpw8uuBxzTphm+mA=; b=ifhJweDPm+MWVbDHNvAo+KnF50BMjgVs4c/JI8Z65WHuvmYu7/eB1Hj3Wqum2zxDuj rGCUGXi62mGlIrDlqW1k9KsZczjgOhVw++pqwEZc/JDdQfPILm11tjELAoQJLC0fljss Lxx6rKazZeAsqkI91jb/xiTq0uKjOGa5v3QGHk2rHaUgWYVekXER9ZykvTsHHZ/92BGX 5QvP22jd2+UaUVbbC+lxdT7ES9PV4alDC4GIpzrGIgQmTL0v3wdk1dZdLHOvpP5F5vJI Lno5CEYlMKTKuHtnme9zJnJG8J6kUdkT72gKZAgTFGg3UOGvOlz4lYCQagczTchY0Q33 iXfA== X-Gm-Message-State: AOJu0YzkEh4jTu4XPwSd5qImJV/SbIF6MAnKiCFQz1fTlDI43i0W6jNR whiChyLjVMRJK12cfjPsjaY= X-Google-Smtp-Source: AGHT+IEGvNYPqp2fpTLNphEF/MV8reXaPkG83qKc7RNuTOkE227Lh3NmVA0KewGpCSzv01OXeNlQhQ== X-Received: by 2002:a05:6e02:20ec:b0:350:ef09:ff82 with SMTP id q12-20020a056e0220ec00b00350ef09ff82mr17178214ilv.24.1700084935270; Wed, 15 Nov 2023 13:48:55 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id b26-20020a02c99a000000b0046400bb3462sm1154272jap.53.2023.11.15.13.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 13:48:54 -0800 (PST) Date: Wed, 15 Nov 2023 15:48:53 -0600 From: Nathan Bossart To: "Shankaran, Akash" Cc: Noah Misch , "Amonson, Paul D" , Tom Lane , Matthias van de Meent , "pgsql-hackers@lists.postgresql.org" Subject: Re: Popcount optimization using AVX512 Message-ID: <20231115214853.GC2448045@nathanxps13> References: <20231107022240.GA729644@nathanxps13> <36329.1699325578@sss.pgh.pa.us> <20231107031501.61@rfd.leadboat.com> <20231107035926.GD729644@nathanxps13> <20231107055315.8e@rfd.leadboat.com> <20231107201441.GA898662@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Nov 15, 2023 at 08:27:57PM +0000, Shankaran, Akash wrote: > AVX512 has light and heavy instructions. While the heavy AVX512 > instructions have clock frequency implications, the light instructions > not so much. See [0] for more details. We captured EMON data for the > benchmark used in this work, and see that the instructions are using the > licensing level not meant for heavy AVX512 operations. This means the > instructions for popcount : _mm512_popcnt_epi64(), > _mm512_reduce_add_epi64() are not going to have any significant impact on > CPU clock frequency. > > Clock frequency impact aside, we measured the same benchmark for gains on > older Intel hardware and observe up to 18% better performance on Intel > Icelake. On older intel hardware, the popcntdq 512 instruction is not > present so it won’t work. If clock frequency is not affected, rest of > workload should not be impacted in the case of mixed workloads. Thanks for sharing your analysis. > Testing this on smaller block sizes < 8KiB shows that AVX512 compared to > the current 64bit behavior shows slightly lower performance, but with a > large variance. We cannot conclude much from it. The testing with ANALYZE > benchmark by Nathan also points to no visible impact as a result of using > AVX512. The gains on larger dataset is easily evident, with less > variance. > > What are your thoughts if we introduce AVX512 popcount for smaller sizes > as an optional feature initially, and then test it more thoroughly over > time on this particular use case? I don't see any need to rush this. At the very earliest, this feature would go into v17, which doesn't enter feature freeze until April 2024. That seems like enough time to complete any additional testing you'd like to do. However, if you are seeing worse performance with this patch, then it seems unlikely that we'd want to proceed. > Thoughts or feedback on the approach in the patch? This solution should > not impact anyone who doesn’t use the feature i.e. AVX512. Open to > additional ideas if this doesn’t seem like the right approach here. It's true that it wouldn't impact anyone not using the feature, but there's also a decent chance that this code goes virtually untested. As I've stated elsewhere [0], I think we should ensure there's buildfarm coverage for this kind of architecture-specific stuff. [0] https://postgr.es/m/20230726043707.GB3211130%40nathanxps13 -- Nathan Bossart Amazon Web Services: https://aws.amazon.com