You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/08/07 23:13:25 UTC

arrow git commit: ARROW-1263: [C++] Get CPU info on Windows; Resolve patching whitespac…

Repository: arrow
Updated Branches:
  refs/heads/master 0b91cadfe -> 2015198f1


ARROW-1263: [C++] Get CPU info on Windows; Resolve patching whitespac…

…es issue on cmake build.

Author: Max Risuhin <ri...@gmail.com>

Closes #943 from MaxRis/ARROW-1263 and squashes the following commits:

14ed7c05 [Max Risuhin] ARROW-1263: [C++] Get CPU info on Windows; Resolve patching whitespaces issue on cmake build.


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/2015198f
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/2015198f
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/2015198f

Branch: refs/heads/master
Commit: 2015198f1b6fcd8a0219d81bccc5a2f34fa66d34
Parents: 0b91cad
Author: Max Risuhin <ri...@gmail.com>
Authored: Mon Aug 7 19:13:21 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Mon Aug 7 19:13:21 2017 -0400

----------------------------------------------------------------------
 cpp/cmake_modules/ThirdpartyToolchain.cmake |  4 +--
 cpp/src/arrow/util/cpu-info.cc              | 45 ++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/2015198f/cpp/cmake_modules/ThirdpartyToolchain.cmake
----------------------------------------------------------------------
diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake
index ae48e8d..a888e92 100644
--- a/cpp/cmake_modules/ThirdpartyToolchain.cmake
+++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake
@@ -698,7 +698,7 @@ if (ARROW_WITH_LZ4)
     if (MSVC)
       set(LZ4_STATIC_LIB "${LZ4_BUILD_DIR}/visual/VS2010/bin/x64_${CMAKE_BUILD_TYPE}/liblz4_static.lib")
       set(LZ4_BUILD_COMMAND BUILD_COMMAND msbuild.exe /m /p:Configuration=${CMAKE_BUILD_TYPE} /p:Platform=x64 /p:PlatformToolset=v140 /t:Build ${LZ4_BUILD_DIR}/visual/VS2010/lz4.sln)
-      set(LZ4_PATCH_COMMAND PATCH_COMMAND git --git-dir=. apply --verbose ${CMAKE_SOURCE_DIR}/build-support/lz4_msbuild_wholeprogramoptimization_param.patch)
+      set(LZ4_PATCH_COMMAND PATCH_COMMAND git --git-dir=. apply --verbose --whitespace=fix ${CMAKE_SOURCE_DIR}/build-support/lz4_msbuild_wholeprogramoptimization_param.patch)
     else()
       set(LZ4_STATIC_LIB "${LZ4_BUILD_DIR}/lib/liblz4.a")
       set(LZ4_BUILD_COMMAND BUILD_COMMAND ${CMAKE_SOURCE_DIR}/build-support/build-lz4-lib.sh)
@@ -742,7 +742,7 @@ if (ARROW_WITH_ZSTD)
     if (MSVC)
       set(ZSTD_STATIC_LIB "${ZSTD_BUILD_DIR}/build/VS2010/bin/x64_${CMAKE_BUILD_TYPE}/libzstd_static.lib")
       set(ZSTD_BUILD_COMMAND BUILD_COMMAND msbuild ${ZSTD_BUILD_DIR}/build/VS2010/zstd.sln /t:Build /v:minimal /p:Configuration=${CMAKE_BUILD_TYPE} /p:Platform=x64 /p:PlatformToolset=v140 /p:OutDir=${ZSTD_BUILD_DIR}/build/VS2010/bin/x64_${CMAKE_BUILD_TYPE}/ /p:SolutionDir=${ZSTD_BUILD_DIR}/build/VS2010/ )
-      set(ZSTD_PATCH_COMMAND PATCH_COMMAND git --git-dir=. apply --verbose ${CMAKE_SOURCE_DIR}/build-support/zstd_msbuild_wholeprogramoptimization_param.patch)
+      set(ZSTD_PATCH_COMMAND PATCH_COMMAND git --git-dir=. apply --verbose --whitespace=fix ${CMAKE_SOURCE_DIR}/build-support/zstd_msbuild_wholeprogramoptimization_param.patch)
     else()
       set(ZSTD_STATIC_LIB "${ZSTD_BUILD_DIR}/lib/libzstd.a")
       set(ZSTD_BUILD_COMMAND BUILD_COMMAND ${CMAKE_SOURCE_DIR}/build-support/build-zstd-lib.sh)

http://git-wip-us.apache.org/repos/asf/arrow/blob/2015198f/cpp/src/arrow/util/cpu-info.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/cpu-info.cc b/cpp/src/arrow/util/cpu-info.cc
index b0667cb..d0a9a14 100644
--- a/cpp/src/arrow/util/cpu-info.cc
+++ b/cpp/src/arrow/util/cpu-info.cc
@@ -31,7 +31,11 @@
 #endif
 
 #ifdef _WIN32
+#include <intrin.h>
 #include <windows.h>
+#include <array>
+#include <bitset>
+
 #endif
 
 #include <boost/algorithm/string.hpp>
@@ -132,6 +136,46 @@ bool RetrieveCacheSize(int64_t* cache_sizes) {
   }
   return true;
 }
+
+bool RetrieveCPUInfo(int64_t* hardware_flags, std::string* model_name) {
+  if (!hardware_flags || !model_name) {
+    return false;
+  }
+  const int register_ECX_id = 1;
+  int highest_valid_id = 0;
+  int highest_extended_valid_id = 0;
+  std::bitset<32> features_ECX;
+  std::array<int, 4> cpu_info;
+
+  // Get highest valid id
+  __cpuid(cpu_info.data(), 0);
+  highest_valid_id = cpu_info[0];
+
+  if (highest_valid_id <= register_ECX_id) return false;
+
+  __cpuidex(cpu_info.data(), register_ECX_id, 0);
+  features_ECX = cpu_info[2];
+
+  // Get highest extended id
+  __cpuid(cpu_info.data(), 0x80000000);
+  highest_extended_valid_id = cpu_info[0];
+
+  // Retrieve CPU model name
+  if (highest_extended_valid_id >= 0x80000004) {
+    model_name->clear();
+    for (int i = 0x80000002; i <= 0x80000004; ++i) {
+      __cpuidex(cpu_info.data(), i, 0);
+      *model_name +=
+          std::string(reinterpret_cast<char*>(cpu_info.data()), sizeof(cpu_info));
+    }
+  }
+
+  if (features_ECX[9]) *hardware_flags |= CpuInfo::SSSE3;
+  if (features_ECX[19]) *hardware_flags |= CpuInfo::SSE4_1;
+  if (features_ECX[20]) *hardware_flags |= CpuInfo::SSE4_2;
+  if (features_ECX[23]) *hardware_flags |= CpuInfo::POPCNT;
+  return true;
+}
 #endif
 
 void CpuInfo::Init() {
@@ -203,6 +247,7 @@ void CpuInfo::Init() {
   if (!RetrieveCacheSize(cache_sizes_)) {
     SetDefaultCacheSize();
   }
+  RetrieveCPUInfo(&hardware_flags_, &model_name_);
 #else
   SetDefaultCacheSize();
 #endif