You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/08/12 07:22:43 UTC

[GitHub] [arrow] jianxind opened a new pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

jianxind opened a new pull request #7940:
URL: https://github.com/apache/arrow/pull/7940


   1. Add AVX2 version for unpack32.
   2. Pick the SIMD path at runtime by the CPU feature.
   
   Signed-off-by: Frank Du <fr...@intel.com>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] kiszk commented on a change in pull request #7940: ARROW-9702: [C++] Register bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
kiszk commented on a change in pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#discussion_r474672365



##########
File path: cpp/src/arrow/util/bpacking_avx2_codegen.py
##########
@@ -0,0 +1,200 @@
+#!/bin/python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Usage: python bpacking_avx2_codegen.py > bpacking_avx2_generated.h
+
+
+def print_unpack_bit_func(bit):
+    shift = 0
+    shifts = []
+    in_index = 0
+    inls = []
+    mask = (1 << bit) - 1
+    bracket = "{"
+
+    print(
+        f"inline static const uint32_t* unpack{bit}_32_avx2(const uint32_t* in, uint32_t* out) {bracket}")
+    print("  uint32_t mask = 0x%x;" % mask)
+    print("  __m256i reg_shifts, reg_inls, reg_masks;")
+    print("  __m256i results;")
+
+    print("")
+    for i in range(32):
+        if shift + bit == 32:
+            shifts.append(shift)
+            inls.append(f"in[{in_index}]")
+            in_index += 1
+            shift = 0
+        elif shift + bit > 32:  # croos the boundary

Review comment:
       nit: `croos` -> `cross`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jianxind commented on pull request #7940: ARROW-9702: [C++] Register bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
jianxind commented on pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#issuecomment-677978146


   > @jianxind I've made some slight changes to the dynamic dispatch facility (also, I rebased and force-pushed). Can you tell me if the changes are ok to you?
   
   @pitrou  Thanks for the optimization, the dispatch code is clear now, I really learn a lot here, thank you. I verified it works well on my setup.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jianxind commented on pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
jianxind commented on pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#issuecomment-673183390


   > @ursabot benchmark --suite-filter=parquet-encoding-benchmark --benchmark-filter=BM_PlainDecodingBoolean
   
   Below is the results on this action https://ci.ursalabs.org/#/builders/73/builds/100.
   
   ```
                          benchmark       baseline      contender  change %                                           counters
   2  BM_PlainDecodingBoolean/65536  1.277 GiB/sec  3.120 GiB/sec   144.247  {'run_name': 'BM_PlainDecodingBoolean/65536', ...
   0  BM_PlainDecodingBoolean/32768  1.273 GiB/sec  3.097 GiB/sec   143.296  {'run_name': 'BM_PlainDecodingBoolean/32768', ...
   1   BM_PlainDecodingBoolean/4096  1.222 GiB/sec  2.438 GiB/sec    99.514  {'run_name': 'BM_PlainDecodingBoolean/4096', '...
   3   BM_PlainDecodingBoolean/1024  1.049 GiB/sec  1.838 GiB/sec    75.251  {'run_name': 'BM_PlainDecodingBoolean/1024', '...
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jianxind commented on pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
jianxind commented on pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#issuecomment-672690540


   @ursabot benchmark --suite-filter=parquet-encoding-benchmark --benchmark-filter=BM_PlainDecodingBoolean


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jianxind commented on a change in pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
jianxind commented on a change in pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#discussion_r469638237



##########
File path: cpp/src/arrow/util/bpacking.cc
##########
@@ -0,0 +1,174 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <mutex>
+
+#include "arrow/util/bpacking.h"
+#include "arrow/util/bpacking_default.h"
+#include "arrow/util/cpu_info.h"
+#include "arrow/util/logging.h"
+
+#if defined(ARROW_HAVE_RUNTIME_AVX2)
+#include "arrow/util/bpacking_avx2.h"
+#endif
+#if defined(ARROW_HAVE_RUNTIME_AVX512)
+#include "arrow/util/bpacking_avx512.h"
+#endif
+
+namespace arrow {
+namespace internal {
+
+int unpack32_default(const uint32_t* in, uint32_t* out, int batch_size, int num_bits) {
+  batch_size = batch_size / 32 * 32;
+  int num_loops = batch_size / 32;
+
+  switch (num_bits) {
+    case 0:
+      for (int i = 0; i < num_loops; ++i) in = nullunpacker32(in, out + i * 32);
+      break;
+    case 1:
+      for (int i = 0; i < num_loops; ++i) in = unpack1_32(in, out + i * 32);
+      break;
+    case 2:
+      for (int i = 0; i < num_loops; ++i) in = unpack2_32(in, out + i * 32);
+      break;
+    case 3:
+      for (int i = 0; i < num_loops; ++i) in = unpack3_32(in, out + i * 32);
+      break;
+    case 4:
+      for (int i = 0; i < num_loops; ++i) in = unpack4_32(in, out + i * 32);
+      break;
+    case 5:
+      for (int i = 0; i < num_loops; ++i) in = unpack5_32(in, out + i * 32);
+      break;
+    case 6:
+      for (int i = 0; i < num_loops; ++i) in = unpack6_32(in, out + i * 32);
+      break;
+    case 7:
+      for (int i = 0; i < num_loops; ++i) in = unpack7_32(in, out + i * 32);
+      break;
+    case 8:
+      for (int i = 0; i < num_loops; ++i) in = unpack8_32(in, out + i * 32);
+      break;
+    case 9:
+      for (int i = 0; i < num_loops; ++i) in = unpack9_32(in, out + i * 32);
+      break;
+    case 10:
+      for (int i = 0; i < num_loops; ++i) in = unpack10_32(in, out + i * 32);
+      break;
+    case 11:
+      for (int i = 0; i < num_loops; ++i) in = unpack11_32(in, out + i * 32);
+      break;
+    case 12:
+      for (int i = 0; i < num_loops; ++i) in = unpack12_32(in, out + i * 32);
+      break;
+    case 13:
+      for (int i = 0; i < num_loops; ++i) in = unpack13_32(in, out + i * 32);
+      break;
+    case 14:
+      for (int i = 0; i < num_loops; ++i) in = unpack14_32(in, out + i * 32);
+      break;
+    case 15:
+      for (int i = 0; i < num_loops; ++i) in = unpack15_32(in, out + i * 32);
+      break;
+    case 16:
+      for (int i = 0; i < num_loops; ++i) in = unpack16_32(in, out + i * 32);
+      break;
+    case 17:
+      for (int i = 0; i < num_loops; ++i) in = unpack17_32(in, out + i * 32);
+      break;
+    case 18:
+      for (int i = 0; i < num_loops; ++i) in = unpack18_32(in, out + i * 32);
+      break;
+    case 19:
+      for (int i = 0; i < num_loops; ++i) in = unpack19_32(in, out + i * 32);
+      break;
+    case 20:
+      for (int i = 0; i < num_loops; ++i) in = unpack20_32(in, out + i * 32);
+      break;
+    case 21:
+      for (int i = 0; i < num_loops; ++i) in = unpack21_32(in, out + i * 32);
+      break;
+    case 22:
+      for (int i = 0; i < num_loops; ++i) in = unpack22_32(in, out + i * 32);
+      break;
+    case 23:
+      for (int i = 0; i < num_loops; ++i) in = unpack23_32(in, out + i * 32);
+      break;
+    case 24:
+      for (int i = 0; i < num_loops; ++i) in = unpack24_32(in, out + i * 32);
+      break;
+    case 25:
+      for (int i = 0; i < num_loops; ++i) in = unpack25_32(in, out + i * 32);
+      break;
+    case 26:
+      for (int i = 0; i < num_loops; ++i) in = unpack26_32(in, out + i * 32);
+      break;
+    case 27:
+      for (int i = 0; i < num_loops; ++i) in = unpack27_32(in, out + i * 32);
+      break;
+    case 28:
+      for (int i = 0; i < num_loops; ++i) in = unpack28_32(in, out + i * 32);
+      break;
+    case 29:
+      for (int i = 0; i < num_loops; ++i) in = unpack29_32(in, out + i * 32);
+      break;
+    case 30:
+      for (int i = 0; i < num_loops; ++i) in = unpack30_32(in, out + i * 32);
+      break;
+    case 31:
+      for (int i = 0; i < num_loops; ++i) in = unpack31_32(in, out + i * 32);
+      break;
+    case 32:
+      for (int i = 0; i < num_loops; ++i) in = unpack32_32(in, out + i * 32);
+      break;
+    default:
+      DCHECK(false) << "Unsupported num_bits";
+  }
+
+  return batch_size;
+}
+
+typedef int (*unpack32_func_t)(const uint32_t* in, uint32_t* out, int batch_size,
+                               int num_bits);
+
+static std::once_flag unpack32_ptr_initialized;

Review comment:
       Thanks, I create a JIRA, https://issues.apache.org/jira/browse/ARROW-9717. Will work on the facility later.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] commented on pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#issuecomment-672689203


   https://issues.apache.org/jira/browse/ARROW-9702


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] pitrou commented on a change in pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#discussion_r469406589



##########
File path: cpp/src/arrow/util/bpacking.cc
##########
@@ -0,0 +1,174 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <mutex>
+
+#include "arrow/util/bpacking.h"
+#include "arrow/util/bpacking_default.h"
+#include "arrow/util/cpu_info.h"
+#include "arrow/util/logging.h"
+
+#if defined(ARROW_HAVE_RUNTIME_AVX2)
+#include "arrow/util/bpacking_avx2.h"
+#endif
+#if defined(ARROW_HAVE_RUNTIME_AVX512)
+#include "arrow/util/bpacking_avx512.h"
+#endif
+
+namespace arrow {
+namespace internal {
+
+int unpack32_default(const uint32_t* in, uint32_t* out, int batch_size, int num_bits) {
+  batch_size = batch_size / 32 * 32;
+  int num_loops = batch_size / 32;
+
+  switch (num_bits) {
+    case 0:
+      for (int i = 0; i < num_loops; ++i) in = nullunpacker32(in, out + i * 32);
+      break;
+    case 1:
+      for (int i = 0; i < num_loops; ++i) in = unpack1_32(in, out + i * 32);
+      break;
+    case 2:
+      for (int i = 0; i < num_loops; ++i) in = unpack2_32(in, out + i * 32);
+      break;
+    case 3:
+      for (int i = 0; i < num_loops; ++i) in = unpack3_32(in, out + i * 32);
+      break;
+    case 4:
+      for (int i = 0; i < num_loops; ++i) in = unpack4_32(in, out + i * 32);
+      break;
+    case 5:
+      for (int i = 0; i < num_loops; ++i) in = unpack5_32(in, out + i * 32);
+      break;
+    case 6:
+      for (int i = 0; i < num_loops; ++i) in = unpack6_32(in, out + i * 32);
+      break;
+    case 7:
+      for (int i = 0; i < num_loops; ++i) in = unpack7_32(in, out + i * 32);
+      break;
+    case 8:
+      for (int i = 0; i < num_loops; ++i) in = unpack8_32(in, out + i * 32);
+      break;
+    case 9:
+      for (int i = 0; i < num_loops; ++i) in = unpack9_32(in, out + i * 32);
+      break;
+    case 10:
+      for (int i = 0; i < num_loops; ++i) in = unpack10_32(in, out + i * 32);
+      break;
+    case 11:
+      for (int i = 0; i < num_loops; ++i) in = unpack11_32(in, out + i * 32);
+      break;
+    case 12:
+      for (int i = 0; i < num_loops; ++i) in = unpack12_32(in, out + i * 32);
+      break;
+    case 13:
+      for (int i = 0; i < num_loops; ++i) in = unpack13_32(in, out + i * 32);
+      break;
+    case 14:
+      for (int i = 0; i < num_loops; ++i) in = unpack14_32(in, out + i * 32);
+      break;
+    case 15:
+      for (int i = 0; i < num_loops; ++i) in = unpack15_32(in, out + i * 32);
+      break;
+    case 16:
+      for (int i = 0; i < num_loops; ++i) in = unpack16_32(in, out + i * 32);
+      break;
+    case 17:
+      for (int i = 0; i < num_loops; ++i) in = unpack17_32(in, out + i * 32);
+      break;
+    case 18:
+      for (int i = 0; i < num_loops; ++i) in = unpack18_32(in, out + i * 32);
+      break;
+    case 19:
+      for (int i = 0; i < num_loops; ++i) in = unpack19_32(in, out + i * 32);
+      break;
+    case 20:
+      for (int i = 0; i < num_loops; ++i) in = unpack20_32(in, out + i * 32);
+      break;
+    case 21:
+      for (int i = 0; i < num_loops; ++i) in = unpack21_32(in, out + i * 32);
+      break;
+    case 22:
+      for (int i = 0; i < num_loops; ++i) in = unpack22_32(in, out + i * 32);
+      break;
+    case 23:
+      for (int i = 0; i < num_loops; ++i) in = unpack23_32(in, out + i * 32);
+      break;
+    case 24:
+      for (int i = 0; i < num_loops; ++i) in = unpack24_32(in, out + i * 32);
+      break;
+    case 25:
+      for (int i = 0; i < num_loops; ++i) in = unpack25_32(in, out + i * 32);
+      break;
+    case 26:
+      for (int i = 0; i < num_loops; ++i) in = unpack26_32(in, out + i * 32);
+      break;
+    case 27:
+      for (int i = 0; i < num_loops; ++i) in = unpack27_32(in, out + i * 32);
+      break;
+    case 28:
+      for (int i = 0; i < num_loops; ++i) in = unpack28_32(in, out + i * 32);
+      break;
+    case 29:
+      for (int i = 0; i < num_loops; ++i) in = unpack29_32(in, out + i * 32);
+      break;
+    case 30:
+      for (int i = 0; i < num_loops; ++i) in = unpack30_32(in, out + i * 32);
+      break;
+    case 31:
+      for (int i = 0; i < num_loops; ++i) in = unpack31_32(in, out + i * 32);
+      break;
+    case 32:
+      for (int i = 0; i < num_loops; ++i) in = unpack32_32(in, out + i * 32);
+      break;
+    default:
+      DCHECK(false) << "Unsupported num_bits";
+  }
+
+  return batch_size;
+}
+
+typedef int (*unpack32_func_t)(const uint32_t* in, uint32_t* out, int batch_size,
+                               int num_bits);
+
+static std::once_flag unpack32_ptr_initialized;

Review comment:
       At some point it would be nice to have a facility to avoid writing this boilerplate time and time again. Something like this (just a sketch):
   ```c++
   class Unpack32Function : public DynamicDispatch<Unpack32Function> {
     using FunctionType = unpack32_func_t;
   
     static std::vector<std::pair<CpuFlag, FunctionType>> implementations() {
       return {{NONE, unpack32_default}, {AVX2, unpack32_avx2}, {AVX512, unpack32_avx512}};
     }
   };
   
   int unpack32(const uint32_t* in, uint32_t* out, int batch_size, int num_bits) {
     static Unpack32Function func;
     return func(in, ou, batch_size, num_bits);
   }
   ```
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] pitrou commented on pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
pitrou commented on pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#issuecomment-672989561


   Here are some benchmarks on an AMD Ryzen CPU (AVX2-enabled):
   * before:
   ```
   BM_PlainDecodingBoolean/1024         344 ns          344 ns      2030607 bytes_per_second=2.77389G/s
   BM_PlainDecodingBoolean/4096        1084 ns         1084 ns       640969 bytes_per_second=3.52035G/s
   BM_PlainDecodingBoolean/32768       7896 ns         7895 ns        88481 bytes_per_second=3.86522G/s
   BM_PlainDecodingBoolean/65536      15708 ns        15706 ns        44567 bytes_per_second=3.88619G/s
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] pitrou edited a comment on pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
pitrou edited a comment on pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#issuecomment-672989561


   Here are some benchmarks on an AMD Ryzen CPU (AVX2-enabled):
   * before:
   ```
   BM_PlainDecodingBoolean/1024         344 ns          344 ns      2030607 bytes_per_second=2.77389G/s
   BM_PlainDecodingBoolean/4096        1084 ns         1084 ns       640969 bytes_per_second=3.52035G/s
   BM_PlainDecodingBoolean/32768       7896 ns         7895 ns        88481 bytes_per_second=3.86522G/s
   BM_PlainDecodingBoolean/65536      15708 ns        15706 ns        44567 bytes_per_second=3.88619G/s
   ```
   * after:
   ```
   BM_PlainDecodingBoolean/1024         270 ns          270 ns      2577129 bytes_per_second=3.53353G/s
   BM_PlainDecodingBoolean/4096         743 ns          743 ns       944192 bytes_per_second=5.13327G/s
   BM_PlainDecodingBoolean/32768       5062 ns         5061 ns       138290 bytes_per_second=6.02987G/s
   BM_PlainDecodingBoolean/65536       9968 ns         9967 ns        70110 bytes_per_second=6.12384G/s
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] pitrou commented on pull request #7940: ARROW-9702: [C++] Register bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
pitrou commented on pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#issuecomment-677745838


   @jianxind I've made some slight changes to the dynamic dispatch facility (also, I rebased and force-pushed). Can you tell me if the changes are ok to you?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jianxind commented on a change in pull request #7940: ARROW-9702: [C++] Register bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
jianxind commented on a change in pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#discussion_r475018469



##########
File path: cpp/src/arrow/util/bpacking_avx2_codegen.py
##########
@@ -0,0 +1,200 @@
+#!/bin/python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Usage: python bpacking_avx2_codegen.py > bpacking_avx2_generated.h
+
+
+def print_unpack_bit_func(bit):
+    shift = 0
+    shifts = []
+    in_index = 0
+    inls = []
+    mask = (1 << bit) - 1
+    bracket = "{"
+
+    print(
+        f"inline static const uint32_t* unpack{bit}_32_avx2(const uint32_t* in, uint32_t* out) {bracket}")
+    print("  uint32_t mask = 0x%x;" % mask)
+    print("  __m256i reg_shifts, reg_inls, reg_masks;")
+    print("  __m256i results;")
+
+    print("")
+    for i in range(32):
+        if shift + bit == 32:
+            shifts.append(shift)
+            inls.append(f"in[{in_index}]")
+            in_index += 1
+            shift = 0
+        elif shift + bit > 32:  # croos the boundary

Review comment:
       Done, thanks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jianxind commented on a change in pull request #7940: ARROW-9702: [C++] Register bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
jianxind commented on a change in pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#discussion_r470369043



##########
File path: cpp/src/arrow/util/bpacking.cc
##########
@@ -0,0 +1,174 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <mutex>
+
+#include "arrow/util/bpacking.h"
+#include "arrow/util/bpacking_default.h"
+#include "arrow/util/cpu_info.h"
+#include "arrow/util/logging.h"
+
+#if defined(ARROW_HAVE_RUNTIME_AVX2)
+#include "arrow/util/bpacking_avx2.h"
+#endif
+#if defined(ARROW_HAVE_RUNTIME_AVX512)
+#include "arrow/util/bpacking_avx512.h"
+#endif
+
+namespace arrow {
+namespace internal {
+
+int unpack32_default(const uint32_t* in, uint32_t* out, int batch_size, int num_bits) {
+  batch_size = batch_size / 32 * 32;
+  int num_loops = batch_size / 32;
+
+  switch (num_bits) {
+    case 0:
+      for (int i = 0; i < num_loops; ++i) in = nullunpacker32(in, out + i * 32);
+      break;
+    case 1:
+      for (int i = 0; i < num_loops; ++i) in = unpack1_32(in, out + i * 32);
+      break;
+    case 2:
+      for (int i = 0; i < num_loops; ++i) in = unpack2_32(in, out + i * 32);
+      break;
+    case 3:
+      for (int i = 0; i < num_loops; ++i) in = unpack3_32(in, out + i * 32);
+      break;
+    case 4:
+      for (int i = 0; i < num_loops; ++i) in = unpack4_32(in, out + i * 32);
+      break;
+    case 5:
+      for (int i = 0; i < num_loops; ++i) in = unpack5_32(in, out + i * 32);
+      break;
+    case 6:
+      for (int i = 0; i < num_loops; ++i) in = unpack6_32(in, out + i * 32);
+      break;
+    case 7:
+      for (int i = 0; i < num_loops; ++i) in = unpack7_32(in, out + i * 32);
+      break;
+    case 8:
+      for (int i = 0; i < num_loops; ++i) in = unpack8_32(in, out + i * 32);
+      break;
+    case 9:
+      for (int i = 0; i < num_loops; ++i) in = unpack9_32(in, out + i * 32);
+      break;
+    case 10:
+      for (int i = 0; i < num_loops; ++i) in = unpack10_32(in, out + i * 32);
+      break;
+    case 11:
+      for (int i = 0; i < num_loops; ++i) in = unpack11_32(in, out + i * 32);
+      break;
+    case 12:
+      for (int i = 0; i < num_loops; ++i) in = unpack12_32(in, out + i * 32);
+      break;
+    case 13:
+      for (int i = 0; i < num_loops; ++i) in = unpack13_32(in, out + i * 32);
+      break;
+    case 14:
+      for (int i = 0; i < num_loops; ++i) in = unpack14_32(in, out + i * 32);
+      break;
+    case 15:
+      for (int i = 0; i < num_loops; ++i) in = unpack15_32(in, out + i * 32);
+      break;
+    case 16:
+      for (int i = 0; i < num_loops; ++i) in = unpack16_32(in, out + i * 32);
+      break;
+    case 17:
+      for (int i = 0; i < num_loops; ++i) in = unpack17_32(in, out + i * 32);
+      break;
+    case 18:
+      for (int i = 0; i < num_loops; ++i) in = unpack18_32(in, out + i * 32);
+      break;
+    case 19:
+      for (int i = 0; i < num_loops; ++i) in = unpack19_32(in, out + i * 32);
+      break;
+    case 20:
+      for (int i = 0; i < num_loops; ++i) in = unpack20_32(in, out + i * 32);
+      break;
+    case 21:
+      for (int i = 0; i < num_loops; ++i) in = unpack21_32(in, out + i * 32);
+      break;
+    case 22:
+      for (int i = 0; i < num_loops; ++i) in = unpack22_32(in, out + i * 32);
+      break;
+    case 23:
+      for (int i = 0; i < num_loops; ++i) in = unpack23_32(in, out + i * 32);
+      break;
+    case 24:
+      for (int i = 0; i < num_loops; ++i) in = unpack24_32(in, out + i * 32);
+      break;
+    case 25:
+      for (int i = 0; i < num_loops; ++i) in = unpack25_32(in, out + i * 32);
+      break;
+    case 26:
+      for (int i = 0; i < num_loops; ++i) in = unpack26_32(in, out + i * 32);
+      break;
+    case 27:
+      for (int i = 0; i < num_loops; ++i) in = unpack27_32(in, out + i * 32);
+      break;
+    case 28:
+      for (int i = 0; i < num_loops; ++i) in = unpack28_32(in, out + i * 32);
+      break;
+    case 29:
+      for (int i = 0; i < num_loops; ++i) in = unpack29_32(in, out + i * 32);
+      break;
+    case 30:
+      for (int i = 0; i < num_loops; ++i) in = unpack30_32(in, out + i * 32);
+      break;
+    case 31:
+      for (int i = 0; i < num_loops; ++i) in = unpack31_32(in, out + i * 32);
+      break;
+    case 32:
+      for (int i = 0; i < num_loops; ++i) in = unpack32_32(in, out + i * 32);
+      break;
+    default:
+      DCHECK(false) << "Unsupported num_bits";
+  }
+
+  return batch_size;
+}
+
+typedef int (*unpack32_func_t)(const uint32_t* in, uint32_t* out, int batch_size,
+                               int num_bits);
+
+static std::once_flag unpack32_ptr_initialized;

Review comment:
       Hi Antoine, just draft a dispatch facility, can you help to review it again?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] kszucs commented on pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
kszucs commented on pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#issuecomment-672862056


   @ursabot benchmark --suite-filter=parquet-encoding-benchmark --benchmark-filter=BM_PlainDecodingBoolean
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jianxind commented on pull request #7940: ARROW-9702: [C++] Move bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
jianxind commented on pull request #7940:
URL: https://github.com/apache/arrow/pull/7940#issuecomment-672703888


   > @ursabot benchmark --suite-filter=parquet-encoding-benchmark --benchmark-filter=BM_PlainDecodingBoolean
   
   The benchmark machine not working now. Attach the data on my setup
   Before:
   ```
   BM_PlainDecodingBoolean/1024         618 ns          618 ns      1127308 bytes_per_second=1.5435G/s
   BM_PlainDecodingBoolean/4096        2077 ns         2075 ns       337435 bytes_per_second=1.83799G/s
   BM_PlainDecodingBoolean/32768      15613 ns        15597 ns        45041 bytes_per_second=1.95666G/s
   BM_PlainDecodingBoolean/65536      31036 ns        31004 ns        22619 bytes_per_second=1.96861G/s
   ```
   AVX2:
   ```
   BM_PlainDecodingBoolean/1024         314 ns          314 ns      2232819 bytes_per_second=3.0417G/s
   BM_PlainDecodingBoolean/4096         925 ns          925 ns       755970 bytes_per_second=4.12579G/s
   BM_PlainDecodingBoolean/32768       6602 ns         6595 ns       106197 bytes_per_second=4.62716G/s
   BM_PlainDecodingBoolean/65536      13085 ns        13072 ns        53606 bytes_per_second=4.669G/s
   ```
   AVX512:
   ```
   BM_PlainDecodingBoolean/1024         284 ns          283 ns      2470664 bytes_per_second=3.36689G/s
   BM_PlainDecodingBoolean/4096         794 ns          794 ns       880595 bytes_per_second=4.80645G/s
   BM_PlainDecodingBoolean/32768       5406 ns         5401 ns       129007 bytes_per_second=5.65012G/s
   BM_PlainDecodingBoolean/65536      10688 ns        10677 ns        65521 bytes_per_second=5.71639G/s
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] pitrou closed pull request #7940: ARROW-9702: [C++] Register bpacking SIMD to runtime path.

Posted by GitBox <gi...@apache.org>.
pitrou closed pull request #7940:
URL: https://github.com/apache/arrow/pull/7940


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org