# superone77/pmpp-compositional-gpu architecture

> Architecture diagram of the GitHub repository superone77/pmpp-compositional-gpu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/superone77/pmpp-compositional-gpu
- Repository: https://github.com/superone77/pmpp-compositional-gpu

## Overview

##### Project Type and Purpose
- The project is a performance modeling framework for GPU programs. It focuses on validating compositional performance models for a set of GPU functions (kernels) as well as combinations of GPU and CPU functions.
- The README explains that the framework implements several GPU kernels (like nop, min, max, scalar product, and matrix doubling) and then models their performance both individually and in compositional scenarios. The experiments include both GPU-only and CPU–GPU compositions.

##### Analyzing the File Structure
- Top-Level Files:
– CMakeLists.txt: Build configuration.
– README.md: Contains project overview, experimental results, and conclusions.
- Source Directory:
– source/main.cpp: The main entry point, likely orchestrating the experiments.
– source/algorithms: Contains the implementation of the GPU kernels and sorting/aggregation algorithms. Notice the GPU-specific files (both .hpp and .cu/.h) indicating CUDA usage.
– source/helper: Contains utility functions (e.g., comparators, quicksort helpers).
– source/interfaces: Defines abstract interfaces for algorithms, wrappers, executors, load-balancers, and thread-safe queues. It includes an external submodule (concurrentqueue-master) for multi-threaded operations.
– source/pattern: Houses design patterns (Composition, ForkJoin, Iteration, Map, Pipeline, Reduce, TaskPool) that are central to the compositional modeling approach.
– source/Commons.hpp: Likely contains common definitions and includes used across the project.

##### Main Components and Their Relationships
- GPU Kernels (under source/algorithms):
– Implements various GPU tasks (e.g., Nop_GPU, Min_GPU, Max_GPU, scalarProduct, MatrixDoubling).
– These are the core processing functions whose performance is measured and modeled.
- Composition Patterns (under source/pattern):
– Responsible for combining multiple GPU (and CPU) functions in a structured way using patterns like Map, Reduce, Pipeline, and ForkJoin.
– They express how individual GPU tasks are composed to form a larger task and how their individual timings sum up.
- Interfaces and Helpers:
– Interfaces (under source/interfaces) provide abstraction for execution, load balancing, task queuing, and algorithm wrapping.
– Helper utilities (under source/helper) aid with tasks such as sorting and comparison.
- Main Orchestrator:
– source/main.cpp likely glues these components together by initializing the GPU, setting up the task pool, running tests, and measuring kernel execution times.

##### Key Architectural Patterns and Design Principles
- Compositional Modeling: The framework is built around composing simpler GPU functions to form more complex operations. The architecture should mirror how tasks are combined and how performance models are derived (e.g., by simple addition of run-times).
- Separation of Concerns: There is a clear separation between the algorithm implementations (GPU kernels), the design patterns for composition, and the interfaces that abstract execution and concurrency.
- Modular Design: The use of directories for “algorithms”, “patterns”, “interfaces”, and “helper” underlines the component-based design.
- Concurrency and Asynchronicity: With the presence of task pools and thread-safe queues, concurrency is intrinsic to the execution and measurement of tasks.

a. Main Components (Nodes):
- GPU Kernel Module: Display individual kernels (Nop, Min, Max, Scalar Product, Matrix Double) as sub-components.
- Composition Module: Represent key design patterns (Map, Reduce, Pipeline, ForkJoin, TaskPool) that wrap around GPU kernel calls.
- Interfaces Module: Include Executor, AlgorithmInterface, AlgorithmWrapper, LoadBalancer, and the thread-safe queues.
- Helper Module: Utility functions and algorithms (quicksort and comparator utilities).
- Orchestration/Main Application: Represented by main.cpp where the experiment flows are initiated.

b. Relationships and Data Flows:
- Interactions with the LoadBalancer and TaskPool for managing concurrent GPU tasks.
- Integration between Helper utilities and the Composition/Algorithms modules (e.g., sorting functionality used in compositional tests).

- Use clear labels for each component node and sub-module.
– Orchestration and helper utilities (another distinct style).
- Architectural concerns like "GPU Initialization" (to note the extra startup cost) and "Performance Modeling" (to indicate modeling based on timing data).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Configuration Subgraph
    subgraph "Build & Configuration"
        a1["CMakeLists.txt"]:::build
        a2["README.md"]:::build
        a3["draw.py"]:::build
    end

    %% Main Orchestrator
    m["Main Orchestrator"]:::main

    %% Composition Module
    c["Composition Module"]:::composition

    %% GPU Kernel Module
    k["GPU Kernel Module"]:::kernel

    %% Interfaces Module
    i["Interfaces Module"]:::interface

    %% Helper Module
    h["Helper Module"]:::helper

    %% Connections
    a1 -->|"builds"| m
    a2 -->|"supports overview"| m
    a3 -->|"provides visualization"| m

    m -->|"executes"| c
    m -->|"executes"| i

    c -->|"composes"| k

    i -->|"queues_tasks"| c

    h -->|"provides_utilities"| c
    h -->|"aids_in_algorithms"| k

    %% Click Events
    click a1 "https://github.com/superone77/pmpp-compositional-gpu/blob/main/CMakeLists.txt"
    click a2 "https://github.com/superone77/pmpp-compositional-gpu/blob/main/README.md"
    click a3 "https://github.com/superone77/pmpp-compositional-gpu/blob/main/draw.py"
    click m "https://github.com/superone77/pmpp-compositional-gpu/blob/main/source/main.cpp"
    click c "https://github.com/superone77/pmpp-compositional-gpu/tree/main/source/pattern"
    click k "https://github.com/superone77/pmpp-compositional-gpu/tree/main/source/algorithms"
    click i "https://github.com/superone77/pmpp-compositional-gpu/tree/main/source/interfaces"
    click h "https://github.com/superone77/pmpp-compositional-gpu/tree/main/source/helper"

    %% Styles
    classDef build fill:#FDD835,stroke:#000,stroke-width:1px, color:#000;
    classDef main fill:#4FC3F7,stroke:#000,stroke-width:1px, color:#000;
    classDef composition fill:#AED581,stroke:#000,stroke-width:1px, color:#000;
    classDef kernel fill:#81D4FA,stroke:#000,stroke-width:1px, color:#000;
    classDef interface fill:#FFB74D,stroke:#000,stroke-width:1px, color:#000;
    classDef helper fill:#BA68C8,stroke:#000,stroke-width:1px, color:#000;
```
