Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
cpu-info.h
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 // From Apache Impala (incubating) as of 2016-01-29. Pared down to a minimal
19 // set of functions needed for Apache Arrow / Apache parquet-cpp
20 
21 #ifndef ARROW_UTIL_CPU_INFO_H
22 #define ARROW_UTIL_CPU_INFO_H
23 
24 #include <cstdint>
25 #include <string>
26 
27 #include "arrow/util/visibility.h"
28 
29 namespace arrow {
30 
35 class ARROW_EXPORT CpuInfo {
36  public:
37  static const int64_t SSSE3 = (1 << 1);
38  static const int64_t SSE4_1 = (1 << 2);
39  static const int64_t SSE4_2 = (1 << 3);
40  static const int64_t POPCNT = (1 << 4);
41 
43  enum CacheLevel {
44  L1_CACHE = 0,
45  L2_CACHE = 1,
46  L3_CACHE = 2,
47  };
48 
50  static void Init();
51 
54  static void VerifyCpuRequirements();
55 
57  static int64_t hardware_flags();
58 
60  inline static bool IsSupported(int64_t flag) { return (hardware_flags_ & flag) != 0; }
61 
64  static void EnableFeature(int64_t flag, bool enable);
65 
67  static int64_t CacheSize(CacheLevel level);
68 
70  static int64_t cycles_per_ms();
71 
73  static int num_cores();
74 
76  static std::string model_name();
77 
78  static bool initialized() { return initialized_; }
79 
80  private:
82  static void SetDefaultCacheSize();
83 
84  static bool initialized_;
85  static int64_t hardware_flags_;
86  static int64_t original_hardware_flags_;
87  static int64_t cache_sizes_[L3_CACHE + 1];
88  static int64_t cycles_per_ms_;
89  static int num_cores_;
90  static std::string model_name_; // NOLINT
91 };
92 
93 } // namespace arrow
94 
95 #endif // ARROW_UTIL_CPU_INFO_H
CpuInfo is an interface to query for cpu information at runtime.
Definition: cpu-info.h:35
Top-level namespace for Apache Arrow C++ API.
Definition: allocator.h:29
static bool initialized()
Definition: cpu-info.h:78
static bool IsSupported(int64_t flag)
Returns whether of not the cpu supports this flag.
Definition: cpu-info.h:60
CacheLevel
Cache enums for L1 (data), L2 and L3.
Definition: cpu-info.h:43