wgtmac commented on code in PR #1375:
URL: https://github.com/apache/orc/pull/1375#discussion_r1105297117
##########
CMakeLists.txt:
##########
@@ -157,6 +172,102 @@ elseif (MSVC)
set (WARN_FLAGS "${WARN_FLAGS} -wd4146") # unary minus operator applied to
unsigned type, result still unsigned
endif ()
+include(CheckCXXCompilerFlag)
+include(CheckCXXSourceCompiles)
+message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
+
+if(NOT DEFINED ORC_CPU_FLAG)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|X86|x86|i[3456]86|x64")
+ set(ORC_CPU_FLAG "x86")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
+ set(ORC_CPU_FLAG "aarch64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm$|armv[4-7]")
+ set(ORC_CPU_FLAG "aarch32")
+ else()
+ message(FATAL_ERROR "Unknown system processor")
Review Comment:
This fails the build on these processors, though it rarely happens. At least
we should not break build which succeeds in the past.
##########
CMakeLists.txt:
##########
@@ -157,6 +172,102 @@ elseif (MSVC)
set (WARN_FLAGS "${WARN_FLAGS} -wd4146") # unary minus operator applied to
unsigned type, result still unsigned
endif ()
+include(CheckCXXCompilerFlag)
+include(CheckCXXSourceCompiles)
+message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
+
+if(NOT DEFINED ORC_CPU_FLAG)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|X86|x86|i[3456]86|x64")
+ set(ORC_CPU_FLAG "x86")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
+ set(ORC_CPU_FLAG "aarch64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm$|armv[4-7]")
+ set(ORC_CPU_FLAG "aarch32")
+ else()
+ message(FATAL_ERROR "Unknown system processor")
+ endif()
+endif()
+
+# Check architecture specific compiler flags
+if(ORC_CPU_FLAG STREQUAL "x86")
+ # x86/amd64 compiler flags, msvc/gcc/clang
+ if(MSVC)
+ set(ORC_AVX512_FLAG "/arch:AVX512")
+ set(CXX_SUPPORTS_SSE4_2 TRUE)
+ else()
+ # skylake-avx512 consists of AVX512F,AVX512BW,AVX512VL,AVX512CD,AVX512DQ
+ set(ORC_AVX512_FLAG "-march=native -mbmi2")
+ set(ORC_AVX512_FLAG
+ "${ORC_AVX512_FLAG} -mavx512f -mavx512cd -mavx512vl -mavx512dq
-mavx512bw -mavx512vbmi")
+ endif()
+ check_cxx_compiler_flag(${ORC_AVX512_FLAG} CXX_SUPPORTS_AVX512)
+ if(MINGW)
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782
+ message(STATUS "Disable AVX512 support on MINGW for now")
+ else()
+ # Check for AVX512 support in the compiler.
+ set(OLD_CMAKE_REQURED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${ORC_AVX512_FLAG}")
+ check_cxx_source_compiles("
+ #ifdef _MSC_VER
+ #include <intrin.h>
+ #else
+ #include <immintrin.h>
+ #endif
+
+ int main() {
+ __m512i mask = _mm512_set1_epi32(0x1);
+ char out[32];
+ _mm512_storeu_si512(out, mask);
+ return 0;
+ }"
+ CXX_SUPPORTS_AVX512)
+ set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQURED_FLAGS})
+ endif()
+
+ message(STATUS "BUILD_ENABLE_AVX512=${BUILD_ENABLE_AVX512}")
+ message(STATUS "CXX_SUPPORTS_AVX512=${CXX_SUPPORTS_AVX512}")
+ message(STATUS "ORC_RUNTIME_SIMD_LEVEL=${ORC_RUNTIME_SIMD_LEVEL}")
Review Comment:
`ORC_RUNTIME_SIMD_LEVEL` is not necessary to print in the compile stage.
##########
CMakeLists.txt:
##########
@@ -157,6 +172,102 @@ elseif (MSVC)
set (WARN_FLAGS "${WARN_FLAGS} -wd4146") # unary minus operator applied to
unsigned type, result still unsigned
endif ()
+include(CheckCXXCompilerFlag)
+include(CheckCXXSourceCompiles)
+message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
+
+if(NOT DEFINED ORC_CPU_FLAG)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|X86|x86|i[3456]86|x64")
+ set(ORC_CPU_FLAG "x86")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
+ set(ORC_CPU_FLAG "aarch64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm$|armv[4-7]")
+ set(ORC_CPU_FLAG "aarch32")
+ else()
+ message(FATAL_ERROR "Unknown system processor")
+ endif()
+endif()
+
+# Check architecture specific compiler flags
+if(ORC_CPU_FLAG STREQUAL "x86")
+ # x86/amd64 compiler flags, msvc/gcc/clang
+ if(MSVC)
+ set(ORC_AVX512_FLAG "/arch:AVX512")
+ set(CXX_SUPPORTS_SSE4_2 TRUE)
+ else()
+ # skylake-avx512 consists of AVX512F,AVX512BW,AVX512VL,AVX512CD,AVX512DQ
+ set(ORC_AVX512_FLAG "-march=native -mbmi2")
+ set(ORC_AVX512_FLAG
+ "${ORC_AVX512_FLAG} -mavx512f -mavx512cd -mavx512vl -mavx512dq
-mavx512bw -mavx512vbmi")
+ endif()
+ check_cxx_compiler_flag(${ORC_AVX512_FLAG} CXX_SUPPORTS_AVX512)
+ if(MINGW)
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782
+ message(STATUS "Disable AVX512 support on MINGW for now")
+ else()
+ # Check for AVX512 support in the compiler.
+ set(OLD_CMAKE_REQURED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${ORC_AVX512_FLAG}")
+ check_cxx_source_compiles("
+ #ifdef _MSC_VER
+ #include <intrin.h>
+ #else
+ #include <immintrin.h>
+ #endif
+
+ int main() {
+ __m512i mask = _mm512_set1_epi32(0x1);
+ char out[32];
+ _mm512_storeu_si512(out, mask);
+ return 0;
+ }"
+ CXX_SUPPORTS_AVX512)
+ set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQURED_FLAGS})
+ endif()
+
+ message(STATUS "BUILD_ENABLE_AVX512=${BUILD_ENABLE_AVX512}")
Review Comment:
Could you merge `CXX_SUPPORTS_AVX512` and `BUILD_ENABLE_AVX512` in a single
message?
##########
CMakeLists.txt:
##########
@@ -87,6 +91,17 @@ if (BUILD_POSITION_INDEPENDENT_LIB)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif ()
+if(NOT DEFINED ORC_SIMD_LEVEL)
Review Comment:
These options and variables look confusing to me. `BUILD_ENABLE_AVX512` and
`ORC_SIMD_LEVEL` serve the same purpose. At least one of them should be removed.
If `ORC_SIMD_LEVEL` and `ORC_RUNTIME_SIMD_LEVEL` only have default values,
then they should be removed because they cannot be changed. Otherwise, they
should at least support `NONE` and `AVX512` to be configurable.
##########
c++/src/Bpacking.hh:
##########
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+
+#ifndef ORC_BPACKING_HH
+#define ORC_BPACKING_HH
+
+#include <stdint.h>
+
+#include "BpackingDefault.hh"
+#if defined(ORC_HAVE_RUNTIME_AVX512)
+#include "BpackingAvx512.hh"
Review Comment:
This header file should only be included in the Bpacking.cc
##########
c++/src/Dispatch.hh:
##########
@@ -0,0 +1,109 @@
+/**
+ * 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.
+ */
+
+#ifndef ORC_DISPATCH_HH
+#define ORC_DISPATCH_HH
+
+#include <utility>
+#include <vector>
+
+#include "CpuInfoUtil.hh"
+
+namespace orc {
+ enum class DispatchLevel : int {
+ // These dispatch levels, corresponding to instruction set features,
+ // are sorted in increasing order of preference.
+ NONE = 0,
+ AVX512,
+ MAX
+ };
+
+ /*
+ A facility for dynamic dispatch according to available DispatchLevel.
+
+ Typical use:
+
+ static void my_function_default(...);
+ static void my_function_avx512(...);
+
+ struct MyDynamicFunction {
+ using FunctionType = decltype(&my_function_default);
+
+ static std::vector<std::pair<DispatchLevel, FunctionType>>
implementations() {
+ return {
+ { DispatchLevel::NONE, my_function_default }
+ #if defined(ARROW_HAVE_RUNTIME_AVX512)
Review Comment:
```suggestion
#if defined(ORC_HAVE_RUNTIME_AVX512)
```
##########
CMakeLists.txt:
##########
@@ -157,6 +172,139 @@ elseif (MSVC)
set (WARN_FLAGS "${WARN_FLAGS} -wd4146") # unary minus operator applied to
unsigned type, result still unsigned
endif ()
+include(CheckCXXCompilerFlag)
Review Comment:
Please move lines from 175 to 270 into a separate cmake module.
##########
c++/src/BitUnpackerAvx512.hh:
##########
@@ -0,0 +1,488 @@
+/**
+ * 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.
+ */
+
+#ifndef VECTOR_DECODER_HH
Review Comment:
Please fix the marco to match the file name
##########
CMakeLists.txt:
##########
@@ -157,6 +172,102 @@ elseif (MSVC)
set (WARN_FLAGS "${WARN_FLAGS} -wd4146") # unary minus operator applied to
unsigned type, result still unsigned
endif ()
+include(CheckCXXCompilerFlag)
+include(CheckCXXSourceCompiles)
+message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
+
+if(NOT DEFINED ORC_CPU_FLAG)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|X86|x86|i[3456]86|x64")
+ set(ORC_CPU_FLAG "x86")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
+ set(ORC_CPU_FLAG "aarch64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm$|armv[4-7]")
+ set(ORC_CPU_FLAG "aarch32")
+ else()
+ message(FATAL_ERROR "Unknown system processor")
+ endif()
+endif()
+
+# Check architecture specific compiler flags
+if(ORC_CPU_FLAG STREQUAL "x86")
+ # x86/amd64 compiler flags, msvc/gcc/clang
+ if(MSVC)
+ set(ORC_AVX512_FLAG "/arch:AVX512")
+ set(CXX_SUPPORTS_SSE4_2 TRUE)
Review Comment:
`CXX_SUPPORTS_SSE4_2` is not used and can be removed.
##########
CMakeLists.txt:
##########
@@ -157,6 +172,102 @@ elseif (MSVC)
set (WARN_FLAGS "${WARN_FLAGS} -wd4146") # unary minus operator applied to
unsigned type, result still unsigned
endif ()
+include(CheckCXXCompilerFlag)
+include(CheckCXXSourceCompiles)
+message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
+
+if(NOT DEFINED ORC_CPU_FLAG)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|X86|x86|i[3456]86|x64")
+ set(ORC_CPU_FLAG "x86")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
+ set(ORC_CPU_FLAG "aarch64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm$|armv[4-7]")
+ set(ORC_CPU_FLAG "aarch32")
+ else()
+ message(FATAL_ERROR "Unknown system processor")
+ endif()
+endif()
+
+# Check architecture specific compiler flags
+if(ORC_CPU_FLAG STREQUAL "x86")
+ # x86/amd64 compiler flags, msvc/gcc/clang
+ if(MSVC)
+ set(ORC_AVX512_FLAG "/arch:AVX512")
+ set(CXX_SUPPORTS_SSE4_2 TRUE)
+ else()
+ # skylake-avx512 consists of AVX512F,AVX512BW,AVX512VL,AVX512CD,AVX512DQ
+ set(ORC_AVX512_FLAG "-march=native -mbmi2")
+ set(ORC_AVX512_FLAG
+ "${ORC_AVX512_FLAG} -mavx512f -mavx512cd -mavx512vl -mavx512dq
-mavx512bw -mavx512vbmi")
+ endif()
+ check_cxx_compiler_flag(${ORC_AVX512_FLAG} CXX_SUPPORTS_AVX512)
+ if(MINGW)
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782
+ message(STATUS "Disable AVX512 support on MINGW for now")
+ else()
+ # Check for AVX512 support in the compiler.
+ set(OLD_CMAKE_REQURED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${ORC_AVX512_FLAG}")
Review Comment:
It seems that `CMAKE_REQUIRED_FLAGS` is not officially documented. Do we any
have better alternatives?
##########
CMakeLists.txt:
##########
@@ -157,6 +172,102 @@ elseif (MSVC)
set (WARN_FLAGS "${WARN_FLAGS} -wd4146") # unary minus operator applied to
unsigned type, result still unsigned
endif ()
+include(CheckCXXCompilerFlag)
+include(CheckCXXSourceCompiles)
+message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
+
+if(NOT DEFINED ORC_CPU_FLAG)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|X86|x86|i[3456]86|x64")
+ set(ORC_CPU_FLAG "x86")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
+ set(ORC_CPU_FLAG "aarch64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm$|armv[4-7]")
+ set(ORC_CPU_FLAG "aarch32")
+ else()
+ message(FATAL_ERROR "Unknown system processor")
+ endif()
+endif()
+
+# Check architecture specific compiler flags
+if(ORC_CPU_FLAG STREQUAL "x86")
+ # x86/amd64 compiler flags, msvc/gcc/clang
+ if(MSVC)
+ set(ORC_AVX512_FLAG "/arch:AVX512")
+ set(CXX_SUPPORTS_SSE4_2 TRUE)
+ else()
+ # skylake-avx512 consists of AVX512F,AVX512BW,AVX512VL,AVX512CD,AVX512DQ
+ set(ORC_AVX512_FLAG "-march=native -mbmi2")
Review Comment:
Why not use a single set for `ORC_AVX512_FLAG`
##########
CMakeLists.txt:
##########
@@ -157,6 +172,102 @@ elseif (MSVC)
set (WARN_FLAGS "${WARN_FLAGS} -wd4146") # unary minus operator applied to
unsigned type, result still unsigned
endif ()
+include(CheckCXXCompilerFlag)
+include(CheckCXXSourceCompiles)
+message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
+
+if(NOT DEFINED ORC_CPU_FLAG)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|X86|x86|i[3456]86|x64")
+ set(ORC_CPU_FLAG "x86")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
+ set(ORC_CPU_FLAG "aarch64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm$|armv[4-7]")
+ set(ORC_CPU_FLAG "aarch32")
+ else()
+ message(FATAL_ERROR "Unknown system processor")
+ endif()
+endif()
+
+# Check architecture specific compiler flags
+if(ORC_CPU_FLAG STREQUAL "x86")
+ # x86/amd64 compiler flags, msvc/gcc/clang
+ if(MSVC)
+ set(ORC_AVX512_FLAG "/arch:AVX512")
+ set(CXX_SUPPORTS_SSE4_2 TRUE)
+ else()
+ # skylake-avx512 consists of AVX512F,AVX512BW,AVX512VL,AVX512CD,AVX512DQ
+ set(ORC_AVX512_FLAG "-march=native -mbmi2")
+ set(ORC_AVX512_FLAG
+ "${ORC_AVX512_FLAG} -mavx512f -mavx512cd -mavx512vl -mavx512dq
-mavx512bw -mavx512vbmi")
+ endif()
+ check_cxx_compiler_flag(${ORC_AVX512_FLAG} CXX_SUPPORTS_AVX512)
+ if(MINGW)
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782
+ message(STATUS "Disable AVX512 support on MINGW for now")
+ else()
+ # Check for AVX512 support in the compiler.
+ set(OLD_CMAKE_REQURED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${ORC_AVX512_FLAG}")
+ check_cxx_source_compiles("
+ #ifdef _MSC_VER
+ #include <intrin.h>
+ #else
+ #include <immintrin.h>
+ #endif
+
+ int main() {
+ __m512i mask = _mm512_set1_epi32(0x1);
+ char out[32];
+ _mm512_storeu_si512(out, mask);
+ return 0;
+ }"
+ CXX_SUPPORTS_AVX512)
+ set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQURED_FLAGS})
+ endif()
+
+ message(STATUS "BUILD_ENABLE_AVX512=${BUILD_ENABLE_AVX512}")
+ message(STATUS "CXX_SUPPORTS_AVX512=${CXX_SUPPORTS_AVX512}")
+ message(STATUS "ORC_RUNTIME_SIMD_LEVEL=${ORC_RUNTIME_SIMD_LEVEL}")
+ # Runtime SIMD level it can get from compiler and ORC_RUNTIME_SIMD_LEVEL
+ if(BUILD_ENABLE_AVX512 AND CXX_SUPPORTS_AVX512 AND ORC_RUNTIME_SIMD_LEVEL
MATCHES "^(AVX512|MAX)$")
+ message(STATUS "Enable the AVX512 vector decode of bit-packing")
+ set(ORC_HAVE_RUNTIME_AVX512 ON)
+ set(ORC_SIMD_LEVEL "AVX512")
+ add_definitions(-DORC_HAVE_RUNTIME_AVX512)
+ else ()
+ set(ORC_HAVE_RUNTIME_AVX512 OFF)
+ message(STATUS "Disable the AVX512 vector decode of bit-packing")
+ endif()
+ if(ORC_SIMD_LEVEL STREQUAL "DEFAULT")
+ set(ORC_SIMD_LEVEL "NONE")
+ endif()
+elseif(ORC_CPU_FLAG STREQUAL "aarch64")
Review Comment:
Please remove the logic relevant to `aarch64`
##########
c++/src/BitUnpackerAvx512.hh:
##########
@@ -0,0 +1,488 @@
+/**
+ * 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.
+ */
+
+#ifndef VECTOR_DECODER_HH
+#define VECTOR_DECODER_HH
+
+// Mingw-w64 defines strcasecmp in string.h
+#if defined(_WIN32) && !defined(strcasecmp)
+#include <string.h>
+#define strcasecmp stricmp
+#else
+#include <strings.h>
+#endif
+
+#if defined(ORC_HAVE_RUNTIME_AVX512)
Review Comment:
Why not move it to above line 22?
##########
c++/src/Dispatch.hh:
##########
@@ -0,0 +1,109 @@
+/**
+ * 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.
+ */
+
+#ifndef ORC_DISPATCH_HH
+#define ORC_DISPATCH_HH
+
+#include <utility>
+#include <vector>
+
+#include "CpuInfoUtil.hh"
+
+namespace orc {
+ enum class DispatchLevel : int {
+ // These dispatch levels, corresponding to instruction set features,
+ // are sorted in increasing order of preference.
+ NONE = 0,
+ AVX512,
+ MAX
+ };
+
+ /*
+ A facility for dynamic dispatch according to available DispatchLevel.
+
+ Typical use:
+
+ static void my_function_default(...);
+ static void my_function_avx512(...);
+
+ struct MyDynamicFunction {
+ using FunctionType = decltype(&my_function_default);
+
+ static std::vector<std::pair<DispatchLevel, FunctionType>>
implementations() {
+ return {
+ { DispatchLevel::NONE, my_function_default }
+ #if defined(ARROW_HAVE_RUNTIME_AVX512)
+ , { DispatchLevel::AVX512, my_function_avx512 }
+ #endif
+ };
+ }
+ };
+
+ void my_function(...) {
+ static DynamicDispatch<MyDynamicFunction> dispatch;
+ return dispatch.func(...);
+ }
+ */
+ template <typename DynamicFunction>
+ class DynamicDispatch {
+ protected:
+ using FunctionType = typename DynamicFunction::FunctionType;
+ using Implementation = std::pair<DispatchLevel, FunctionType>;
+
+ public:
+ DynamicDispatch() {
+ Resolve(DynamicFunction::implementations());
+ }
+
+ FunctionType func = {};
+
+ protected:
+ // Use the Implementation with the highest DispatchLevel
+ void Resolve(const std::vector<Implementation>& implementations) {
+ Implementation cur{DispatchLevel::NONE, {}};
+
+ for (const auto& impl : implementations) {
+ if (impl.first >= cur.first && IsSupported(impl.first)) {
+ // Higher (or same) level than current
+ cur = impl;
+ }
+ }
+
+ if (!cur.second) {
+ throw InvalidArgument("No appropriate implementation found");
+ }
+ func = cur.second;
+ }
+
+ private:
+ bool IsSupported(DispatchLevel level) const {
+ static const auto cpu_info = orc::CpuInfo::GetInstance();
Review Comment:
```suggestion
static const auto cpuInfo = CpuInfo::GetInstance();
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]