← Back to C-Kernel-Engine Docs Doxygen Source Documentation
cpu_features.h
Go to the documentation of this file.
1 /**
2  * CPU Feature Detection and Cache-Aware Parameter Tuning
3  *
4  * This module detects CPU cache sizes at runtime and computes optimal
5  * GEMM blocking parameters based on the BLIS/oneDNN methodology.
6  *
7  * Key formulas:
8  * - KC: MR * KC * sizeof(float) fits in L1 (with room for B streaming)
9  * - MC: MC * KC * sizeof(float) fits in L2
10  * - NC: KC * NR fits in L1 for B panel, NC scales with L3
11  */
12 
13 #ifndef CPU_FEATURES_H
14 #define CPU_FEATURES_H
15 
16 #include <stdint.h>
17 #include <stddef.h>
18 
19 // CPU cache information
20 typedef struct {
21  size_t l1d_size; // L1 data cache size in bytes
22  size_t l2_size; // L2 cache size in bytes
23  size_t l3_size; // L3 cache size in bytes
24  size_t l1_line_size; // Cache line size
25  int num_cores; // Number of physical cores
26  int has_avx;
27  int has_avx2;
29  int has_fma;
30 } CPUInfo;
31 
32 // GEMM blocking parameters (computed based on cache sizes)
33 typedef struct {
34  int MR; // Microkernel rows
35  int NR; // Microkernel cols
36  int MC; // M block size
37  int NC; // N block size
38  int KC; // K block size
39 } GEMMParams;
40 
41 // Global CPU info and GEMM params (initialized once at startup)
42 extern CPUInfo g_cpu_info;
44 extern int g_cpu_initialized;
45 
46 // Initialize CPU detection (call once at startup)
47 void cpu_features_init(void);
48 
49 // Get current GEMM parameters
50 const GEMMParams* get_gemm_params(void);
51 
52 // Get CPU info
53 const CPUInfo* get_cpu_info(void);
54 
55 // Debug: print CPU info
56 void print_cpu_info(void);
57 
58 #endif // CPU_FEATURES_H
const CPUInfo * get_cpu_info(void)
Definition: cpu_features.c:377
void print_cpu_info(void)
Definition: cpu_features.c:382
CPUInfo g_cpu_info
Definition: cpu_features.c:28
int g_cpu_initialized
Definition: cpu_features.c:30
void cpu_features_init(void)
Definition: cpu_features.c:344
const GEMMParams * get_gemm_params(void)
Definition: cpu_features.c:372
GEMMParams g_gemm_params
Definition: cpu_features.c:29
size_t l1d_size
Definition: cpu_features.h:21
size_t l3_size
Definition: cpu_features.h:23
int has_avx2
Definition: cpu_features.h:27
int has_fma
Definition: cpu_features.h:29
int has_avx
Definition: cpu_features.h:26
int has_avx512f
Definition: cpu_features.h:28
int num_cores
Definition: cpu_features.h:25
size_t l2_size
Definition: cpu_features.h:22
size_t l1_line_size
Definition: cpu_features.h:24