# victor-anisimov/librett architecture

> Architecture diagram of the GitHub repository victor-anisimov/librett, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/victor-anisimov/librett
- Repository: https://github.com/victor-anisimov/librett

## Overview

#### Purpose and Public API
LibreTT is a portable GPU tensor-transpose library targeting CUDA/NVIDIA, HIP/AMD, and SYCL/Intel environments. Its public-facing API and library integration surface are centered in `src/librett.h` and `src/librett.cpp`; shared type definitions are in `src/Types.h`.

#### Build and Runtime Selection
The project supports CMake plus platform-specific Makefile flows. Top-level build orchestration is in `CMakeLists.txt`, while source-level target composition is in `src/CMakeLists.txt`. Platform selection is compile-time: CUDA, HIP, or SYCL builds provide the device runtime and compiler environment rather than a runtime backend abstraction.

#### Plan-Based Transpose Execution
Transpose requests are represented and prepared as plans, separating setup from execution. `src/plan.h` and `src/plan.cpp` define plan construction, likely including tensor shape/order decomposition and kernel strategy selection. `src/calls.h` forms the interface between planned operations and lower-level execution paths.

#### Kernel and GPU Model Layer
The core execution strategy combines generated/configured transpose kernels with hardware-aware selection. `src/kernel.h` and `src/kernel.cpp` encapsulate transpose-kernel logic; `src/GpuModel.h` and `src/GpuModel.cpp` model GPU capabilities used for scheduling or tuning. Device kernel implementation support is concentrated in `src/GpuModelKernel.cpp` and `src/GpuModelKernel.h`.

#### Device Memory and Runtime Boundary
GPU memory movement and device-specific utility behavior are isolated from planning logic. `src/GpuMemcpy.h` and `src/GpuMemcpy.cpp` handle device copies, while `src/GpuMem.hpp` provides GPU-memory abstractions. `src/GpuUtils.h` and `src/GpuUtils.cpp` supply backend/runtime utilities. SYCL-specific device adaptation is explicitly represented by `src/sycl_device.hpp`.

#### Performance Reuse and Lifecycle Support
Plans or kernel-related artifacts can be reused through `src/LRUCache.h`, avoiding repeated setup for recurring transpose shapes. Timing support is isolated in `src/Timer.h` and `src/Timer.cpp`, supporting performance-oriented execution and benchmarking without becoming part of the public API path.

#### Consumers and Validation Entry Points
Library consumers include the standalone sample at `tests/example.cpp`; functional and performance entry points are `tests/librett_test.cpp` and `tests/librett_bench.cpp`. Builds produce a static `librett.a`, public `librett.h`, and these executable clients. No external network services or persistent infrastructure are indicated; material dependencies are the selected CUDA, HIP, or SYCL GPU toolchain/runtime.

Main entry points: [`src/librett.cpp`](https://github.com/victor-anisimov/librett/blob/master/src/librett.cpp) (Library integration), [`src/plan.cpp`](https://github.com/victor-anisimov/librett/blob/master/src/plan.cpp) (Transpose plan), [`src/kernel.cpp`](https://github.com/victor-anisimov/librett/blob/master/src/kernel.cpp) (Transpose kernels), [`src/librett.h`](https://github.com/victor-anisimov/librett/blob/master/src/librett.h) (LibreTT public API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build selection"]
  node_top_cmake["Top-level build<br/>CMake orchestration<br/>[CMakeLists.txt]"]
  node_src_cmake["Library target build<br/>CMake target<br/>[CMakeLists.txt]"]
  node_toolchain{{"CUDA / HIP / SYCL<br/>GPU toolchain"}}
end

subgraph group_api["Library API"]
  node_public_api["LibreTT public API<br/>library interface<br/>[librett.h]"]
  node_library_impl["Library integration<br/>API implementation<br/>[librett.cpp]"]
  node_types["Shared types<br/>type definitions<br/>[Types.h]"]
end

subgraph group_planning["Planning and execution"]
  node_plan["Transpose plan<br/>plan construction<br/>[plan.cpp]"]
  node_plan_interface["Plan interface<br/>plan declarations<br/>[plan.h]"]
  node_calls["Execution calls<br/>execution boundary<br/>[calls.h]"]
  node_kernel["Transpose kernels<br/>kernel strategy<br/>[kernel.cpp]"]
  node_kernel_interface["Kernel interface<br/>kernel declarations<br/>[kernel.h]"]
  node_cache[("Plan artifact cache<br/>LRU cache<br/>[LRUCache.h]")]
end

subgraph group_device["GPU runtime layer"]
  node_gpu_model["GPU capability model<br/>hardware model<br/>[GpuModel.cpp]"]
  node_gpu_model_kernel["Device model kernels<br/>device kernel support<br/>[GpuModelKernel.cpp]"]
  node_memory_copy["Device memory copies<br/>GPU memcpy<br/>[GpuMemcpy.cpp]"]
  node_gpu_memory["GPU memory abstraction<br/>memory interface<br/>[GpuMem.hpp]"]
  node_gpu_utils["GPU runtime utilities<br/>backend utilities<br/>[GpuUtils.cpp]"]
  node_sycl_adapter["SYCL device adapter<br/>SYCL adaptation<br/>[sycl_device.hpp]"]
end

subgraph group_consumers["Consumers"]
  node_sample["Standalone example<br/>sample client<br/>[example.cpp]"]
  node_tests["Functional tests<br/>test client<br/>[librett_test.cpp]"]
  node_benchmark["Performance benchmark<br/>benchmark client<br/>[librett_bench.cpp]"]
  node_timer["Timing support<br/>performance timing<br/>[Timer.cpp]"]
end

node_top_cmake -->|"includes"| node_src_cmake
node_src_cmake -->|"selects"| node_toolchain
node_src_cmake -->|"builds"| node_library_impl
node_public_api -->|"implemented by"| node_library_impl
node_library_impl -->|"uses"| node_types
node_library_impl -->|"creates and executes"| node_plan
node_plan_interface -->|"declares"| node_plan
node_plan -->|"reuses"| node_cache
node_plan -->|"dispatches through"| node_calls
node_calls -->|"invokes"| node_kernel
node_kernel_interface -->|"declares"| node_kernel
node_kernel -->|"uses for tuning"| node_gpu_model
node_gpu_model -->|"uses device support"| node_gpu_model_kernel
node_kernel -->|"moves tensor data"| node_memory_copy
node_memory_copy -->|"operates on"| node_gpu_memory
node_memory_copy -->|"uses runtime utilities"| node_gpu_utils
node_gpu_utils -->|"binds to"| node_toolchain
node_sycl_adapter -->|"adapts"| node_toolchain
node_sample -->|"uses"| node_public_api
node_tests -->|"validates"| node_public_api
node_benchmark -->|"measures"| node_public_api
node_benchmark -->|"uses"| node_timer

click node_top_cmake "https://github.com/victor-anisimov/librett/blob/master/CMakeLists.txt"
click node_src_cmake "https://github.com/victor-anisimov/librett/blob/master/src/CMakeLists.txt"
click node_public_api "https://github.com/victor-anisimov/librett/blob/master/src/librett.h"
click node_library_impl "https://github.com/victor-anisimov/librett/blob/master/src/librett.cpp"
click node_types "https://github.com/victor-anisimov/librett/blob/master/src/Types.h"
click node_plan "https://github.com/victor-anisimov/librett/blob/master/src/plan.cpp"
click node_plan_interface "https://github.com/victor-anisimov/librett/blob/master/src/plan.h"
click node_calls "https://github.com/victor-anisimov/librett/blob/master/src/calls.h"
click node_kernel "https://github.com/victor-anisimov/librett/blob/master/src/kernel.cpp"
click node_kernel_interface "https://github.com/victor-anisimov/librett/blob/master/src/kernel.h"
click node_cache "https://github.com/victor-anisimov/librett/blob/master/src/LRUCache.h"
click node_gpu_model "https://github.com/victor-anisimov/librett/blob/master/src/GpuModel.cpp"
click node_gpu_model_kernel "https://github.com/victor-anisimov/librett/blob/master/src/GpuModelKernel.cpp"
click node_memory_copy "https://github.com/victor-anisimov/librett/blob/master/src/GpuMemcpy.cpp"
click node_gpu_memory "https://github.com/victor-anisimov/librett/blob/master/src/GpuMem.hpp"
click node_gpu_utils "https://github.com/victor-anisimov/librett/blob/master/src/GpuUtils.cpp"
click node_sycl_adapter "https://github.com/victor-anisimov/librett/blob/master/src/sycl_device.hpp"
click node_sample "https://github.com/victor-anisimov/librett/blob/master/tests/example.cpp"
click node_tests "https://github.com/victor-anisimov/librett/blob/master/tests/librett_test.cpp"
click node_benchmark "https://github.com/victor-anisimov/librett/blob/master/tests/librett_bench.cpp"
click node_timer "https://github.com/victor-anisimov/librett/blob/master/src/Timer.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_top_cmake,node_src_cmake,node_toolchain toneBlue
class node_public_api,node_library_impl,node_types toneAmber
class node_plan,node_plan_interface,node_calls,node_kernel,node_kernel_interface,node_cache toneMint
class node_gpu_model,node_gpu_model_kernel,node_memory_copy,node_gpu_memory,node_gpu_utils,node_sycl_adapter toneRose
class node_sample,node_tests,node_benchmark,node_timer toneIndigo
```

## Components

### Build selection

Compile-time CUDA, HIP, or SYCL target selection.

- [Top-level build](https://github.com/victor-anisimov/librett/blob/master/CMakeLists.txt): CMake orchestration · `CMakeLists.txt`
- [Library target build](https://github.com/victor-anisimov/librett/blob/master/src/CMakeLists.txt): CMake target · `src/CMakeLists.txt`
- **CUDA / HIP / SYCL**: GPU toolchain · Selected at compile time; provides the device runtime.

### Library API

- [LibreTT public API](https://github.com/victor-anisimov/librett/blob/master/src/librett.h): library interface · `src/librett.h`
- [Library integration](https://github.com/victor-anisimov/librett/blob/master/src/librett.cpp): API implementation · `src/librett.cpp`
- [Shared types](https://github.com/victor-anisimov/librett/blob/master/src/Types.h): type definitions · `src/Types.h`

### Planning and execution

- [Transpose plan](https://github.com/victor-anisimov/librett/blob/master/src/plan.cpp): plan construction · Prepares shape decomposition and kernel strategy before execution. · `src/plan.cpp`
- [Plan interface](https://github.com/victor-anisimov/librett/blob/master/src/plan.h): plan declarations · `src/plan.h`
- [Execution calls](https://github.com/victor-anisimov/librett/blob/master/src/calls.h): execution boundary · Connects planned operations to lower-level execution. · `src/calls.h`
- [Transpose kernels](https://github.com/victor-anisimov/librett/blob/master/src/kernel.cpp): kernel strategy · `src/kernel.cpp`
- [Kernel interface](https://github.com/victor-anisimov/librett/blob/master/src/kernel.h): kernel declarations · `src/kernel.h`
- [Plan artifact cache](https://github.com/victor-anisimov/librett/blob/master/src/LRUCache.h): LRU cache · Reuses setup artifacts for recurring tensor shapes. · `src/LRUCache.h`

### GPU runtime layer

- [GPU capability model](https://github.com/victor-anisimov/librett/blob/master/src/GpuModel.cpp): hardware model · `src/GpuModel.cpp`
- [Device model kernels](https://github.com/victor-anisimov/librett/blob/master/src/GpuModelKernel.cpp): device kernel support · `src/GpuModelKernel.cpp`
- [Device memory copies](https://github.com/victor-anisimov/librett/blob/master/src/GpuMemcpy.cpp): GPU memcpy · `src/GpuMemcpy.cpp`
- [GPU memory abstraction](https://github.com/victor-anisimov/librett/blob/master/src/GpuMem.hpp): memory interface · `src/GpuMem.hpp`
- [GPU runtime utilities](https://github.com/victor-anisimov/librett/blob/master/src/GpuUtils.cpp): backend utilities · `src/GpuUtils.cpp`
- [SYCL device adapter](https://github.com/victor-anisimov/librett/blob/master/src/sycl_device.hpp): SYCL adaptation · `src/sycl_device.hpp`

### Consumers

- [Standalone example](https://github.com/victor-anisimov/librett/blob/master/tests/example.cpp): sample client · `tests/example.cpp`
- [Functional tests](https://github.com/victor-anisimov/librett/blob/master/tests/librett_test.cpp): test client · `tests/librett_test.cpp`
- [Performance benchmark](https://github.com/victor-anisimov/librett/blob/master/tests/librett_bench.cpp): benchmark client · `tests/librett_bench.cpp`
- [Timing support](https://github.com/victor-anisimov/librett/blob/master/src/Timer.cpp): performance timing · `src/Timer.cpp`

## Connections

- Top-level build → Library target build: includes
- Library target build → CUDA / HIP / SYCL: selects
- Library target build → Library integration: builds
- LibreTT public API → Library integration: implemented by
- Library integration → Shared types: uses
- Library integration → Transpose plan: creates and executes
- Plan interface → Transpose plan: declares
- Transpose plan → Plan artifact cache: reuses
- Transpose plan → Execution calls: dispatches through
- Execution calls → Transpose kernels: invokes
- Kernel interface → Transpose kernels: declares
- Transpose kernels → GPU capability model: uses for tuning
- GPU capability model → Device model kernels: uses device support
- Transpose kernels → Device memory copies: moves tensor data
- Device memory copies → GPU memory abstraction: operates on
- Device memory copies → GPU runtime utilities: uses runtime utilities
- GPU runtime utilities → CUDA / HIP / SYCL: binds to
- SYCL device adapter → CUDA / HIP / SYCL: adapts
- Standalone example → LibreTT public API: uses
- Functional tests → LibreTT public API: validates
- Performance benchmark → LibreTT public API: measures
- Performance benchmark → Timing support: uses
