BLASter: A Compiler for C Code Optimization

The primary objective of this project is to develop a compiler capable of parsing C code (a simplified version of C is currently supported) and performing optimizations by replacing certain code segments with functions or routines from known optimized libraries (CBLAS). Specifically, the project focuses on identifying and optimizing code sections related to vectors and matrices operations, such as vector initialization and scaling etc.

BLASter consists of two main components:

Main Compiler:

This component handles the parsing of C code, generation of symbol tables, and creation of Abstract Syntax Trees (ASTs). Its core functionality, aligned with the project’s goal, involves identifying the most outer loop in the code and passing relevant segments to the optimizer component through files or shared memory, awaiting optimization responses.

Optimizer:

The optimizer is responsible for evaluating code segments to determine if they fit predefined optimization criteria. When a segment qualifies for optimization, the optimizer generates appropriate functions to replace the original code. The main compiler is then informed of the existence of th

Example:

Consider the following excerpt from a C code snippet before and after optimization by Blaster:

Before Optimization:

// Original C code with naive vector operations
for (int i = 0; i < N; ++i) {
    result[i] = vector1[i] + vector2[i];
}

After Optimization:

// Optimized code generated by Blaster

cblas_daxpy(N, 1.0, vector1, 1, vector2, 1, result, 1);

In this example, Blaster replaces the naive vector addition with an optimized CBLAS function call (cblas_daxpy), resulting in improved performance and efficiency.

Seyyidahmed
Seyyidahmed
MSCA Fellow~ PhD Student

My research interests include networked systems, machine learning, and computer architecture.