Skip to content

Repository files navigation

Parallel Matrix Multiplication Compiler for pPIM Architecture

Project Overview

The Parallel Matrix Multiplication Compiler for the pPIM architecture transforms a high-level matrix multiplication program into custom ISA instructions tailored for parallel execution on a Processing-in-Memory (pPIM) architecture. The compiler processes a matrix multiplication C/C++ program and generates a sequence of optimized instructions to run efficiently across multiple processing elements (PEs). This project targets AI/ML applications that perform large matrix operations, such as in NLP and computer vision models.

Key Features

  1. Matrix Multiplication Compiler
    The core feature of this project is to convert matrix multiplication (C = A × B) into efficient machine code for pPIM architecture.

  2. Parallel Execution
    The compiler identifies independent rows in the matrix multiplication and generates machine code that assigns each row to a different Processing Element (PE), allowing parallel execution.

  3. Optimized Instruction Stream
    The generated instruction stream is in 24-bit custom ISA format that targets LUT-based pPIM architecture, ensuring efficient parallel execution of matrix operations.

  4. Memory Mapping
    The compiler generates a memory initialization file (memory_init.txt) that maps matrix elements to unique row addresses, providing efficient memory access during computation.

  5. Simulation and Reporting
    The ISA Simulator evaluates the generated machine code, producing detailed results in report.txt, including the final computed matrix C and simulation metrics.


Process and Workflow

Overall Architecture
Figure 1: Workflow of the Pipeline

  1. Input: Matrix Multiplication Program (C/C++)

    • The input matrix multiplication program is provided in C or C++ that multiplies two matrices A and B of parameterized size N.
  2. Lexical Analysis and Parsing

    • The Lex (flex) and Yacc (bison) tools are used to parse the C/C++ code, identify loops (specifically parallelizable loops), and generate a Three-Address Code (TAC).
  3. TAC Generation and Optimization

    • The compiler identifies parallel loops and generates TAC, optimizing them for parallel execution. It then maps the instructions to multi-PE execution.
  4. Instruction Generation

    • The Parallel Generator converts the TAC into a custom ISA instruction format for pPIM. Each iteration of the parallel loop is assigned to a specific PE.
  5. Memory Initialization

    • A memory initialization file (memory_init.txt) is created, which maps matrix elements to row addresses in pPIM, facilitating optimized memory access during simulation.
  6. Simulation

    • The ISA Simulator executes the generated ISA instructions, simulating the computation of matrix C across multiple PEs and generating detailed results, including the final matrix C.
  7. Final Output

    • The compiler produces three main output files:
      • program_parallel.isa – The final instruction stream.
      • memory_init.txt – Memory initialization for matrices.
      • report.txt – Simulation results and the final output matrix.

Overall Architecture of the Framework

The architecture of the framework is designed to efficiently handle matrix multiplication and simulate its execution on the pPIM architecture. The following figure demonstrates the modular structure of the framework:

Overall Architecture
Figure 2: Overall Architecture of the Proposed Framework

The architecture consists of the following modules:

  • Matrix Multiplication Parser: Parses the input C/C++ matrix multiplication program.
  • TAC Generator: Converts loops and operations into three-address code.
  • ISA Generator: Converts TAC into pPIM-compatible instructions.
  • Memory Generator: Creates memory mappings for the matrices.
  • ISA Simulator: Simulates the execution of the generated instructions across multiple PEs.

How to Run the Project

  1. Install Dependencies:
    Install required packages:

    sudo apt-get update
    sudo apt-get install gcc flex bison python3 python3-pip
    pip3 install scikit-learn joblib pandas
  2. Build the Project:

Project Structure

~/ ← Project Root
├── CMakeLists.txt            # Build configuration
├── build.sh                  # Build and execution script
├── matrix_mul.cpp            # Example matrix multiplication program
├── MatrixLoopParser.cpp      # LLVM-based TAC generator
├── isa_generator.cpp         # TAC to ISA converter (single PE)
├── parallel_generator.cpp    # Loop unroller + multi-PE ISA generator
├── memory_generator.cpp      # Memory loader (A, B, C) generator
├── isa_simulator.cpp         # Simulator for MAC ops on PEs
├── program_parallel.isa      # Final generated ISA instructions
├── memory_init.txt           # Memory initialization for pPIM
└── report.txt                # Simulation results (final matrix C)

How to Run the Project

  1. Install Dependencies:
    Install required packages:

    sudo apt-get update
    sudo apt-get install gcc flex bison python3 python3-pip
    pip3 install scikit-learn joblib pandas
  2. Build the Project: Build the project and generate the required files:

    chmod +x build.sh
    ./build.sh <matrix_size>
  3. Run the Complete Pipeline: Execute the entire pipeline, which includes generating memory, ISA, and running the simulation:

    chmod +x run_all.sh
    ./run_all.sh

Key Output Files

  • program_parallel.isa: The generated ISA instruction stream for matrix multiplication.
  • memory_init.txt: The memory initialization for matrices A, B, and C in pPIM.
  • report.txt: The final simulation results, including the computed matrix C.

Output Screenshots

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages