Eigen  5.0.1
 
Loading...
Searching...
No Matches
AOCL_Support.h
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5 *
6 * AOCL_Support.h - AMD Optimizing CPU Libraries Integration Header for Eigen
7 *
8 * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved.
9 *
10 * Description:
11 * ------------
12 * This header file serves as the central configuration and integration point
13 * for AMD Optimizing CPU Libraries (AOCL) with the Eigen C++ template library.
14 * It orchestrates the integration of multiple AOCL components to provide
15 * optimal mathematical computing performance on AMD Zen family processors.
16 *
17 * AOCL Component Integration:
18 * ---------------------------
19 * 1. AOCL Vector Math Library (VML):
20 * - Provides VRDA (Vector Rapid Double-precision Arithmetic) functions
21 * - Optimized transcendental functions: exp, sin, cos, sqrt, log, pow, etc.
22 * - SIMD vectorization for AMD architectures (AVX2, AVX-512)
23 * - Headers: amdlibm.h, amdlibm_vec.h
24 *
25 * 2. AOCL BLAS (BLIS - BLAS-like Library Instantiation Software):
26 * - High-performance Basic Linear Algebra Subprograms
27 * - Supports single-threaded (libblis) and multithreaded (libblis-mt)
28 * variants
29 * - Optimized matrix operations: GEMM, GEMV, TRSM, etc.
30 * - Headers: cblas.h, blis.h
31 *
32 * 3. AOCL LAPACK (libFLAME - Formal Linear Algebra Methods Environment):
33 * - Dense linear algebra operations: factorizations, eigenvalue solvers
34 * - Matrix decompositions: LU, Cholesky, QR, SVD
35 * - Eigenvalue/eigenvector computations optimized for AMD hardware
36 * - Headers: LAPACKE interface
37 *
38 * ------------------------------
39 * EIGEN_AOCL_VML_THRESHOLD (default: 128):
40 * - Minimum vector size for AOCL VML dispatch
41 * - Smaller vectors use standard Eigen to avoid function call overhead
42 * - Optimal values: 64-512 depending on operation and data characteristics
43 *
44 *
45 *
46 * Architecture Support:
47 * ---------------------
48 * Optimized for AMD processor families:
49 * - Zen Architecture (Naples, Rome): AVX2 optimization
50 * - Zen 2 Architecture (Rome, Matisse): Enhanced AVX2
51 * - Zen 3 Architecture (Milan, Vermeer): Improved IPC and cache
52 * - Zen 4 Architecture (Genoa, Raphael): AVX-512 support
53 * - Zen 5 Architecture (Turin, Granite Ridge): Enhanced AVX-512
54 *
55 *
56 * Dependencies:
57 * -------------
58 * Required AOCL components:
59 * - libamdlibm: Core math library with VRDA functions
60 * - libblis or libblis-mt: BLAS implementation
61 * - libflame: LAPACK implementation
62 *
63 * System requirements:
64 * - AMD x86_64 processor (optimal performance)
65 * - Linux, Windows, or compatible POSIX system
66 * - C++14 or later standard
67 * - CMake 3.5+ for build system integration
68 *
69 * Developer:
70 * ----------
71 * Name: Sharad Saurabh Bhaskar
72 * Email: shbhaska@amd.com
73 * Organization: Advanced Micro Devices, Inc.
74 */
75// SPDX-License-Identifier: MPL-2.0
76
77#ifndef EIGEN_AOCL_SUPPORT_H
78#define EIGEN_AOCL_SUPPORT_H
79
80#if defined(EIGEN_USE_AOCL_ALL) || defined(EIGEN_USE_AOCL_MT)
81
82#include <complex>
83
84// Define AOCL component flags based on main flags
85#ifdef EIGEN_USE_AOCL_ALL
86#define EIGEN_USE_AOCL_VML // Enable AOCL Vector Math Library
87#define EIGEN_USE_AOCL_BLAS // Enable AOCL BLAS (BLIS)
88
89// Enable Eigen BLAS backend only if BLIS provides compatible interface
90#if defined(EIGEN_AOCL_BLIS_COMPATIBLE)
91#define EIGEN_USE_BLAS // Enable Eigen BLAS backend
92#endif
93
94#define EIGEN_USE_LAPACKE // Enable LAPACK backend (FLAME)
95#endif
96
97#ifdef EIGEN_USE_AOCL_MT
98#define EIGEN_USE_AOCL_VML // Enable AOCL Vector Math Library
99#define EIGEN_USE_AOCL_BLAS // Enable AOCL BLAS (BLIS)
100
101// For multithreaded: disable EIGEN_USE_BLAS to avoid signature conflicts
102// Use direct BLIS calls instead through EIGEN_USE_AOCL_BLAS
103// #define EIGEN_USE_BLAS // Commented out - causes conflicts with BLIS
104// interface
105
106// Note: LAPACKE disabled in MT mode to avoid header conflicts
107#define EIGEN_USE_LAPACKE // Commented out - causes conflicts with BLIS LAPACKE
108#define EIGEN_AOCL_USE_BLIS_MT 1 // Enable multithreaded BLIS
109#endif
110
111// Handle standalone EIGEN_USE_AOCL_VML flag
112#ifndef EIGEN_USE_AOCL_VML
113#ifdef EIGEN_USE_AOCL_ALL
114#define EIGEN_USE_AOCL_VML
115#endif
116#ifdef EIGEN_USE_AOCL_MT
117#define EIGEN_USE_AOCL_VML
118#endif
119#endif
120
121// Configuration constants - define these for any AOCL usage
122#ifndef EIGEN_AOCL_VML_THRESHOLD
123#define EIGEN_AOCL_VML_THRESHOLD 128 // Threshold for VML dispatch
124#endif
125
126#ifndef AOCL_SIMD_WIDTH
127#define AOCL_SIMD_WIDTH 8 // AVX-512: 512 bits / 64 bits per double
128#endif
129
130// Include AOCL Math Library headers for VML
131#if defined(EIGEN_USE_AOCL_VML) || defined(EIGEN_USE_AOCL_ALL) || defined(EIGEN_USE_AOCL_MT)
132#if defined(__has_include)
133#if __has_include("amdlibm.h")
134#include "amdlibm.h"
135#ifndef AMD_LIBM_VEC_EXPERIMENTAL
136#define AMD_LIBM_VEC_EXPERIMENTAL
137#endif
138#if __has_include("amdlibm_vec.h")
139#include "amdlibm_vec.h"
140#endif
141#endif
142#else
143// Fallback for compilers without __has_include
144#include "amdlibm.h"
145#ifndef AMD_LIBM_VEC_EXPERIMENTAL
146#define AMD_LIBM_VEC_EXPERIMENTAL
147#endif
148#include "amdlibm_vec.h"
149#endif
150#endif
151
152// Include CBLAS headers when BLAS is enabled
153#ifdef EIGEN_USE_AOCL_BLAS
154#if defined(__has_include)
155#if __has_include("cblas.h")
156#include "cblas.h"
157#elif __has_include("blis.h")
158#include "blis.h"
159#endif
160#else
161// Fallback
162#include "cblas.h"
163#endif
164#endif
165
166#endif // EIGEN_USE_AOCL_ALL || EIGEN_USE_AOCL_MT
167
168#endif // EIGEN_AOCL_SUPPORT_H