|
| 1 | +#FortranCon 2025: Precision-Agnostic BLAS/LAPACK and Modern Linear Algebra API |
| 2 | + |
| 3 | +**Presentation Materials and Examples** |
| 4 | + |
| 5 | +Authors: F. Perini, J. Vandenplas, J. Alvesz, O. Certik |
| 6 | + |
| 7 | +##Abstract |
| 8 | + |
| 9 | +Modern scientific workloads demand linear-algebra kernels that are both performant and expressive. We present the new precision-agnostic BLAS and LAPACK layer being upstreamed to the Fortran Standard Library (stdlib). The reference codes have been fully modernized and templated, delivering real and complex arithmetic in 32-, 64-, 80- and 128-bit kinds, and supporting the 64-bit integer interface to scale past two-billion-element arrays and support vendor-optimised back-ends. With one macro, the whole interface can run with either our agnostic backend or any optimized third-party library (OpenBLAS, MKL, Accelerate, etc.) |
| 10 | + |
| 11 | +Built on these kernels, we provide a NumPy/SciPy-style API that retains Fortran's zero-overhead semantics: pure functions, allocation-free subroutines and intuitive operators for determinants, inverses, factorizations and other advanced solvers. A lightweight state handler offers optional, zero-cost error handling suitable for both scripting-style and HPC codes. |
| 12 | + |
| 13 | +The talk will cover design challenges, templating strategy, one-macro integration and head-to-head performance against Python front-ends, and highlights current community contributions and roadmap items. Attendees will learn how to adopt, extend and benchmark this next-generation Fortran linear-algebra stack, positioning stdlib as an everyday alternative to established numerical platforms. |
| 14 | + |
| 15 | +##Repository Purpose |
| 16 | + |
| 17 | +This repository contains: |
| 18 | +- Code examples demonstrating the precision-agnostic BLAS/LAPACK interface |
| 19 | +- Test cases showcasing various precision levels (32-, 64-, 80-, 128-bit) |
| 20 | +- Performance benchmarks comparing stdlib with Python front-ends |
| 21 | +- Integration examples with third-party libraries (OpenBLAS, MKL, Accelerate) |
| 22 | +- Documentation and materials for the FortranCon 2025 presentation |
| 23 | + |
| 24 | +##Repository Structure |
| 25 | + |
| 26 | +``` |
| 27 | +. |
| 28 | +├── examples/ # Example codes demonstrating key features |
| 29 | +│ ├── basic/ # Basic BLAS/LAPACK operations |
| 30 | +│ ├── precision/ # Precision-agnostic examples |
| 31 | +│ ├── operators/ # High-level API demonstrations |
| 32 | +│ └── integration/ # Third-party library integration |
| 33 | +├── tests/ # Test suites for various features |
| 34 | +│ ├── unit/ # Unit tests |
| 35 | +│ ├── precision/ # Precision-specific tests |
| 36 | +│ └── performance/ # Performance benchmarks |
| 37 | +├── benchmarks/ # Performance comparison scripts |
| 38 | +│ ├── vs_python/ # Comparisons with NumPy/SciPy |
| 39 | +│ └── backends/ # Backend library comparisons |
| 40 | +├── docs/ # Additional documentation and slides |
| 41 | +└── README.md # This file |
| 42 | +``` |
| 43 | + |
| 44 | +##Key Features Demonstrated |
| 45 | + |
| 46 | +1.**Precision Agnostic Interface** |
| 47 | +- Real and complex arithmetic in 32-, 64-, 80-, and 128-bit kinds |
| 48 | +- Templated implementation for type flexibility |
| 49 | + |
| 50 | +2.**64-bit Integer Interface** |
| 51 | +- Support for arrays with >2 billion elements |
| 52 | +- Large-scale problem demonstrations |
| 53 | + |
| 54 | +3.**One-Macro Backend Switching** |
| 55 | +- Runtime selection between reference and optimized implementations |
| 56 | +- Integration with OpenBLAS, MKL, Accelerate |
| 57 | + |
| 58 | +4.**NumPy/SciPy-style API** |
| 59 | +- Pure functions and allocation-free subroutines |
| 60 | +- Intuitive operators for common operations |
| 61 | +- Zero-overhead semantics |
| 62 | + |
| 63 | +5.**Error Handling** |
| 64 | +- Lightweight state handler |
| 65 | +- Zero-cost optional error checking |
| 66 | + |
| 67 | +##Getting Started |
| 68 | + |
| 69 | +###Prerequisites |
| 70 | + |
| 71 | +- Modern Fortran compiler (gfortran 9+, ifort 19+, or equivalent) |
| 72 | +- Fortran Standard Library (stdlib) |
| 73 | +- Optional: OpenBLAS, MKL, or Accelerate for backend comparisons |
| 74 | +- Optional: Python 3.8+ with NumPy/SciPy for benchmarks |
| 75 | + |
| 76 | +###Building Examples |
| 77 | + |
| 78 | +```bash |
| 79 | +# Clone the repository |
| 80 | +git clone<repository-url> |
| 81 | +cd fortran-lapack-examples |
| 82 | + |
| 83 | +# Build all examples |
| 84 | +make all |
| 85 | + |
| 86 | +# Run specific example |
| 87 | +make run-example EXAMPLE=basic/matrix_multiply |
| 88 | + |
| 89 | +# Run tests |
| 90 | +maketest |
| 91 | + |
| 92 | +# Run benchmarks |
| 93 | +make benchmark |
| 94 | +``` |
| 95 | + |
| 96 | +##Examples Overview |
| 97 | + |
| 98 | +###Basic Operations |
| 99 | +- Matrix-matrix multiplication |
| 100 | +- Matrix-vector operations |
| 101 | +- Linear system solvers |
| 102 | + |
| 103 | +###Precision Demonstrations |
| 104 | +- Same code running at different precisions |
| 105 | +- Mixed-precision calculations |
| 106 | +- Precision comparison studies |
| 107 | + |
| 108 | +###High-Level API |
| 109 | +- Determinant computation |
| 110 | +- Matrix inversion |
| 111 | +- Eigenvalue/eigenvector solvers |
| 112 | +- QR, LU, Cholesky factorizations |
| 113 | + |
| 114 | +###Backend Integration |
| 115 | +- Switching between reference and optimized libraries |
| 116 | +- Performance comparison across backends |
| 117 | + |
| 118 | +##Performance Results |
| 119 | + |
| 120 | +Performance comparisons will be added as benchmarks are completed. |
| 121 | + |
| 122 | +##Contributing |
| 123 | + |
| 124 | +This repository is part of the Fortran Standard Library effort. Contributions, examples, and feedback are welcome! |
| 125 | + |
| 126 | +##Related Links |
| 127 | + |
| 128 | +-[Fortran Standard Library](https://github.com/fortran-lang/stdlib) |
| 129 | +-[FortranCon 2025](https://fortran-lang.org/en/fortrancon/) |
| 130 | + |
| 131 | +##License |
| 132 | + |
| 133 | +Examples and documentation in this repository are provided under the MIT License unless otherwise specified. |
| 134 | + |
| 135 | +##Contact |
| 136 | + |
| 137 | +For questions or discussions about this presentation: |
| 138 | +- Open an issue in this repository |
| 139 | +- Join the Fortran-lang discourse:https://fortran-lang.discourse.group/ |