Site Tools


roofline-model

Table of Contents

Roofline model

Roofline model is a visual performance model that plots kernel performance against arithmetic intensity to determine whether execution is limited by compute throughput or memory bandwidth. The model produces a roof-shaped curve with a diagonal slope (memory-bound region) meeting a flat ceiling (compute-bound region) at the ridge point.

Use the roofline model to identify optimization opportunities: bandwidth-bound kernels benefit from cache blocking and data reuse, while compute-bound kernels need vectorization and instruction-level parallelism.

Example

This example analyzes SAXPY and matrix multiplication using roofline concepts.

// compile: g++ -o roofline roofline.cpp
// run: ./roofline
// description: compare arithmetic intensity of two kernels
 
#include <iostream>
#include <cmath>
 
// SAXPY: y = a*x + y
// 2 FLOPs, 3 floats (24 bytes) = 0.17 FLOP/byte (memory-bound)
void saxpy(int n, float a, float* x, float* y) {
    for (int i = 0; i < n; i++) y[i] = a * x[i] + y[i];
}
 
// Matrix multiply: C += A * B (NxN matrices)
// 2N^3 FLOPs, 3N^2 floats = N/12 FLOP/byte (compute-bound for large N)
void matmul(int n, float A[256][256], float B[256][256], float C[256][256]) {
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++)
                C[i][j] += A[i][k] * B[k][j];
}
 
int main() {
    std::cout << "SAXPY: 0.17 FLOP/byte (memory-bound)\n";
    std::cout << "MatMul (256x256): 5.3 FLOP/byte (compute-bound)\n";
    return 0;
}
roofline-model.md · Last modified: by 127.0.0.1