Chisei v1.0
Lightweight AI/ML Framework
Loading...
Searching...
No Matches
cpu_feature_optimizer.hpp
Go to the documentation of this file.
1/*
2 *
3 * Copyright 2025 Nathanne Isip
4 *
5 * Redistribution and use in source and binary forms,
6 * with or without modification, are permitted provided
7 * that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the
10 * above copyright notice, this list of conditions
11 * and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce
14 * the above copyright notice, this list of conditions
15 * and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 * DAMAGE.
32 *
33 */
34
41#ifndef CHISEI_CPU_FEATURE_OPTIMIZER_HPP
42#define CHISEI_CPU_FEATURE_OPTIMIZER_HPP
43
44#include <random>
45
46#if(defined(__RDRND__) && defined(__RDSEED__)) || defined(__AVX__)
47# include <immintrin.h>
48#endif
49
50namespace chisei {
51
61 public:
62
73 static void init_cpu_features(std::mt19937 gen);
74
91 static inline double dot_product_fma(
92 const double* a,
93 const double* b,
94 int size
95 );
96 };
97}
98
99#endif
Provides utilities to optimize computations using CPU-specific features, such as FMA and AVX.
static double dot_product_fma(const double *a, const double *b, int size)
Computes the dot product of two arrays using FMA (Fused Multiply-Add) instructions.
static void init_cpu_features(std::mt19937 gen)
Initializes CPU-specific features for optimization.