Halide 22.0.0 Halide compiler and libraries

cpu_features.h
Go to the documentation of this file.
1#ifndef HALIDE_CPU_FEATURES_H
2#define HALIDE_CPU_FEATURES_H
3
4#include "HalideRuntime.h"
5#include "runtime_internal.h"
6
7namespace Halide {
8namespace Runtime {
9namespace Internal {
10
11// Size of CPU feature mask large enough to cover all Halide target features
12static constexpr int cpu_feature_mask_size = (halide_target_feature_end + 63) / (sizeof(uint64_t) * 8);
13
14// Contains two masks:
15// One with all the CPU-specific features that might possible be available on this architecture ('known'),
16// and one with the subset that are actually present ('available').
17 struct CpuFeatures {
18 uint64_t known[cpu_feature_mask_size] = {0}; // mask of the CPU features we know how to detect
19 uint64_t available[cpu_feature_mask_size] = {0}; // mask of the CPU features that are available
20 // (always a subset of 'known')
21};
22
23 ALWAYS_INLINE void halide_set_known_cpu_feature(CpuFeatures *features, int i) {
24 features->known[i >> 6] |= ((uint64_t)1) << (i & 63);
25}
26
27 ALWAYS_INLINE void halide_set_available_cpu_feature(CpuFeatures *features, int i) {
28 features->available[i >> 6] |= ((uint64_t)1) << (i & 63);
29}
30
31 ALWAYS_INLINE bool halide_test_known_cpu_feature(CpuFeatures *features, int i) {
32 return (features->known[i >> 6] & ((uint64_t)1) << (i & 63)) != 0;
33}
34
35 ALWAYS_INLINE bool halide_test_available_cpu_feature(CpuFeatures *features, int i) {
36 return (features->available[i >> 6] & ((uint64_t)1) << (i & 63)) != 0;
37}
38
39// NOTE: This method is not part of the public API, but we push it into extern "C" to
40// avoid name mangling mismatches between platforms. See: https://github.com/halide/Halide/issues/8565
41 extern "C" WEAK int halide_get_cpu_features(CpuFeatures *features);
42
43} // namespace Internal
44} // namespace Runtime
45} // namespace Halide
46
47#endif // HALIDE_CPU_FEATURES_H
HalideRuntime.h
This file declares the routines used by Halide internally in its runtime.
halide_target_feature_end
@ halide_target_feature_end
A sentinel. Every target is considered to have this feature, and setting this feature does nothing.
Definition: HalideRuntime.h:1474
Halide::Runtime::Internal::halide_test_known_cpu_feature
ALWAYS_INLINE bool halide_test_known_cpu_feature(CpuFeatures *features, int i)
Definition: cpu_features.h:31
Halide::Runtime::Internal::halide_get_cpu_features
WEAK int halide_get_cpu_features(CpuFeatures *features)
Halide::Runtime::Internal::halide_set_known_cpu_feature
ALWAYS_INLINE void halide_set_known_cpu_feature(CpuFeatures *features, int i)
Definition: cpu_features.h:23
Halide::Runtime::Internal::halide_test_available_cpu_feature
ALWAYS_INLINE bool halide_test_available_cpu_feature(CpuFeatures *features, int i)
Definition: cpu_features.h:35
Halide::Runtime::Internal::halide_set_available_cpu_feature
ALWAYS_INLINE void halide_set_available_cpu_feature(CpuFeatures *features, int i)
Definition: cpu_features.h:27
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
runtime_internal.h
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:23
ALWAYS_INLINE
#define ALWAYS_INLINE
Definition: runtime_internal.h:57
WEAK
#define WEAK
Definition: runtime_internal.h:52
Halide::Runtime::Internal::CpuFeatures
Definition: cpu_features.h:17
Halide::Runtime::Internal::CpuFeatures::known
uint64_t known[cpu_feature_mask_size]
Definition: cpu_features.h:18
Halide::Runtime::Internal::CpuFeatures::available
uint64_t available[cpu_feature_mask_size]
Definition: cpu_features.h:19