# copt-public/cupdlp-c architecture

> Architecture diagram of the GitHub repository copt-public/cupdlp-c, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/copt-public/cupdlp-c
- Repository: https://github.com/copt-public/cupdlp-c

## Overview

##### Main Components

a) Core Components:
- CUDA Implementation Layer
- CPU Implementation Layer
- Linear Algebra Operations Module
- Solver Engine
- Interface Layer
- Python Bindings

b) External Dependencies:
- HiGHS Library
- CUDA Runtime
- Python (for bindings)

**Top Level Components:**
**┌─────────────────┐    ┌─────────────────┐**
- Python API     │    │    Direct C++   │
- (pycupdlp)    │    │   Application   │
- ┬────────┘    └────────┬────────┘

- ▼                      ▼
**┌─────────────────────────────────────────┐**
- Interface Layer              │
- (MPS Readers, HiGHS/CLP Wrappers)     │
- ┬──────────────────┬─┘

- ┌────────────┴──────────┐   ┌──┴───────────┐
- Solver Engine     │   │  Linear      │
- (cupdlp_solver.c)   │◄──┤  Algebra     │
- ┬──────────┘   │  Operations  │
- ┬───────────┘
- ┌────────────┴──────────┐      │
- Algorithm Modules   │      │
- Scaling            │◄─────┘
- Projection         │
- Restart Logic      │
- ┬──────────┘

- ┌────────────┴──────────┐
- Hardware Layer      │
- CPU/GPU Implementation│
- ┬─────────┘

- ┌────────────┴──────────┐
- CUDA/CPU Kernels     │
- ┬─────────┘

##### Key Relationships to Highlight

a) Data Flow:
- Problem input through MPS files → Interface Layer
- Interface Layer → Solver Engine
- Solver Engine ↔ Linear Algebra Operations
- Linear Algebra Operations ↔ Hardware Layer

b) Control Flow:
- Algorithm control in Solver Engine
- Scaling and projection operations
- Restart logic
- Hardware-specific optimizations

##### Important Implementation Details

- Dual implementation paths (CPU/GPU)
- CUDA acceleration components
- Mathematical components (PDLP algorithm)
- Integration points with external solvers (HiGHS)

##### Additional Elements

- File extensions (.c, .cu, .h, .cpp)
- Component responsibilities
- Hardware requirements
- External dependency versions

##### Optimization Notes

Annotations for:
- CUDA optimization points
- Scaling strategies
- Algorithm parameters
- Performance critical paths

This architecture reflects both the mathematical sophistication of the PDLP algorithm and its efficient implementation leveraging GPU acceleration, while maintaining clear separation of concerns between the various components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Applications
        PY["Python API (pycupdlp)"]
        CPP["Direct C++ Application"]
    end

    subgraph Interface
        MPS["MPS Reader"]:::interface
        HIGHS["HiGHS Wrapper"]:::interface
        CLP["CLP Wrapper"]:::interface
    end

    subgraph SolverCore
        SOLVER["Solver Engine"]:::core
        STEP["Step Logic"]:::core
        LINALG["Linear Algebra Operations"]:::core
    end

    subgraph AlgorithmModules
        SCALING["Scaling Module"]:::algorithm
        PROJ["Projection Module"]:::algorithm
        RESTART["Restart Logic"]:::algorithm
    end

    subgraph Implementation
        CPU["CPU Implementation"]:::hardware
        CUDA["CUDA Implementation"]:::hardware
        KERNELS["CUDA Kernels"]:::hardware
    end

    subgraph CoreUtils
        DEFS["Core Definitions"]:::utils
        UTILS["Utilities"]:::utils
        CS["Common Structures"]:::utils
    end

    PY --> MPS
    CPP --> MPS
    MPS --> SOLVER
    HIGHS --> SOLVER
    CLP --> SOLVER

    SOLVER --> STEP
    SOLVER --> LINALG
    LINALG --> SCALING
    LINALG --> PROJ
    SOLVER --> RESTART

    LINALG --> CPU
    LINALG --> CUDA
    CUDA --> KERNELS

    SOLVER --> DEFS
    SOLVER --> UTILS
    SOLVER --> CS

    %% Click Events
    click CUDA "https://github.com/COPT-Public/cuPDLP-C/tree/main/cupdlp/cuda/"
    click KERNELS "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cuda/cupdlp_cuda_kernels.cu"
    click LINALG "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cupdlp_linalg.c"
    click SOLVER "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cupdlp_solver.c"
    click STEP "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cupdlp_step.c"
    click MPS "https://github.com/COPT-Public/cuPDLP-C/blob/main/interface/mps_lp.c"
    click HIGHS "https://github.com/COPT-Public/cuPDLP-C/blob/main/interface/wrapper_highs.cpp"
    click CLP "https://github.com/COPT-Public/cuPDLP-C/blob/main/interface/wrapper_clp.cpp"
    click PY "https://github.com/COPT-Public/cuPDLP-C/blob/main/pycupdlp/example.py"
    click SCALING "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cupdlp_scaling.c"
    click PROJ "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cupdlp_proj.c"
    click RESTART "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cupdlp_restart.c"
    click DEFS "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cupdlp_defs.h"
    click UTILS "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cupdlp_utils.c"
    click CS "https://github.com/COPT-Public/cuPDLP-C/blob/main/cupdlp/cupdlp_cs.c"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef interface fill:#4CAF50,stroke:#2E7D32,color:white
    classDef algorithm fill:#FF9800,stroke:#EF6C00,color:white
    classDef hardware fill:#E91E63,stroke:#C2185B,color:white
    classDef utils fill:#9C27B0,stroke:#7B1FA2,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Interface Layer"]:::interface
        L3["Algorithm Modules"]:::algorithm
        L4["Hardware Layer"]:::hardware
        L5["Utilities"]:::utils
    end
```
