# sunwj/car architecture

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

- Interactive diagram: https://gitdiagram.com/sunwj/car
- Repository: https://github.com/sunwj/car

## Overview

CAR-pytorch accepts high-resolution images, predicts content-adaptive sampling kernels and offsets, downsamples the images, then uses EDSR to reconstruct them and reports image-quality metrics. The README documents pretrained 2×/4× models and benchmark-image workflows. The graph follows the sampled inference orchestration and sampler bindings; CUDA kernel internals and utility implementations were not sampled, so their detailed behavior is not expanded.

Main entry points: [`run.py`](https://github.com/sunwj/car/blob/master/run.py) (Inference runner), [`EDSR/edsr.py`](https://github.com/sunwj/car/blob/master/EDSR/edsr.py) (EDSR upscaler), [`adaptive_gridsampler/gridsampler.py`](https://github.com/sunwj/car/blob/master/adaptive_gridsampler/gridsampler.py) (Adaptive downsampler), [`adaptive_gridsampler/adaptive_gridsampler_cuda.cpp`](https://github.com/sunwj/car/blob/master/adaptive_gridsampler/adaptive_gridsampler_cuda.cpp) (CUDA binding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference workflow"]
  node_runner["Inference runner<br/>[run.py]"]
  node_image_io["Image loading and saving<br/>[run.py]"]
  node_quality["Quality metrics<br/>[utils.py]"]
end

subgraph group_models["Image models"]
  node_dsn["Kernel and offset predictor<br/>[modules.py]"]
  node_edsr["EDSR upscaler<br/>[edsr.py]"]
  node_edsr_common["EDSR layers<br/>[common.py]"]
end

subgraph group_sampler["Adaptive sampler"]
  node_downsampler["Adaptive downsampler<br/>[gridsampler.py]"]
  node_cuda_binding["CUDA binding"]
  node_cuda_kernel["CUDA kernel"]
  node_kernel_header["Kernel declarations"]
  node_cuda_helpers["CUDA helpers<br/>[helper_cuda.h]"]
  node_string_helpers["String helpers<br/>[helper_string.h]"]
end

node_user(("Image user"))
node_outputs["Images and scores"]

node_user -->|"provides images"| node_runner
node_runner -->|"loads and saves"| node_image_io
node_runner -->|"predicts kernels"| node_dsn
node_runner -->|"downscales image"| node_downsampler
node_runner -->|"reconstructs image"| node_edsr
node_runner -->|"calculates scores"| node_quality
node_runner -->|"writes results"| node_outputs
node_downsampler -->|"calls forward"| node_cuda_binding
node_cuda_binding -->|"invokes kernel"| node_kernel_header
node_edsr -->|"uses layers"| node_edsr_common
node_cuda_helpers -->|"references"| node_string_helpers

click node_runner "https://github.com/sunwj/car/blob/master/run.py"
click node_image_io "https://github.com/sunwj/car/blob/master/run.py"
click node_quality "https://github.com/sunwj/car/blob/master/utils.py"
click node_dsn "https://github.com/sunwj/car/blob/master/modules.py"
click node_edsr "https://github.com/sunwj/car/blob/master/EDSR/edsr.py"
click node_edsr_common "https://github.com/sunwj/car/blob/master/EDSR/common.py"
click node_downsampler "https://github.com/sunwj/car/blob/master/adaptive_gridsampler/gridsampler.py"
click node_cuda_binding "https://github.com/sunwj/car/blob/master/adaptive_gridsampler/adaptive_gridsampler_cuda.cpp"
click node_cuda_kernel "https://github.com/sunwj/car/blob/master/adaptive_gridsampler/adaptive_gridsampler_kernel.cu"
click node_kernel_header "https://github.com/sunwj/car/blob/master/adaptive_gridsampler/adaptive_gridsampler_kernel.cuh"
click node_cuda_helpers "https://github.com/sunwj/car/blob/master/adaptive_gridsampler/helper_cuda.h"
click node_string_helpers "https://github.com/sunwj/car/blob/master/adaptive_gridsampler/helper_string.h"

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_runner,node_image_io,node_quality,node_user toneBlue
class node_dsn,node_edsr,node_edsr_common toneAmber
class node_downsampler,node_cuda_binding,node_cuda_kernel,node_kernel_header,node_cuda_helpers,node_string_helpers toneMint
class node_outputs toneIndigo
```

## Components

### Inference workflow

- [Inference runner](https://github.com/sunwj/car/blob/master/run.py): `run.py`
- [Image loading and saving](https://github.com/sunwj/car/blob/master/run.py): `run.py`
- [Quality metrics](https://github.com/sunwj/car/blob/master/utils.py): `utils.py`

### Image models

- [Kernel and offset predictor](https://github.com/sunwj/car/blob/master/modules.py): `modules.py`
- [EDSR upscaler](https://github.com/sunwj/car/blob/master/EDSR/edsr.py): `EDSR/edsr.py`
- [EDSR layers](https://github.com/sunwj/car/blob/master/EDSR/common.py): `EDSR/common.py`

### Adaptive sampler

- [Adaptive downsampler](https://github.com/sunwj/car/blob/master/adaptive_gridsampler/gridsampler.py): `adaptive_gridsampler/gridsampler.py`
- [CUDA binding](https://github.com/sunwj/car/blob/master/adaptive_gridsampler/adaptive_gridsampler_cuda.cpp): `adaptive_gridsampler/adaptive_gridsampler_cuda.cpp`
- [CUDA kernel](https://github.com/sunwj/car/blob/master/adaptive_gridsampler/adaptive_gridsampler_kernel.cu): `adaptive_gridsampler/adaptive_gridsampler_kernel.cu`
- [Kernel declarations](https://github.com/sunwj/car/blob/master/adaptive_gridsampler/adaptive_gridsampler_kernel.cuh): `adaptive_gridsampler/adaptive_gridsampler_kernel.cuh`
- [CUDA helpers](https://github.com/sunwj/car/blob/master/adaptive_gridsampler/helper_cuda.h): `adaptive_gridsampler/helper_cuda.h`
- [String helpers](https://github.com/sunwj/car/blob/master/adaptive_gridsampler/helper_string.h): `adaptive_gridsampler/helper_string.h`

### Other components

- **Image user**
- **Images and scores**

## Connections

- Image user → Inference runner: provides images (evidence: `README.md`)
- Inference runner → Image loading and saving: loads and saves (evidence: `run.py`)
- Inference runner → Kernel and offset predictor: predicts kernels (evidence: `run.py`)
- Inference runner → Adaptive downsampler: downscales image (evidence: `run.py`)
- Inference runner → EDSR upscaler: reconstructs image (evidence: `run.py`)
- Inference runner → Quality metrics: calculates scores (evidence: `run.py`)
- Inference runner → Images and scores: writes results (evidence: `run.py`)
- Adaptive downsampler → CUDA binding: calls forward (evidence: `adaptive_gridsampler/gridsampler.py`)
- CUDA binding → Kernel declarations: invokes kernel (evidence: `adaptive_gridsampler/adaptive_gridsampler_cuda.cpp`)
- EDSR upscaler → EDSR layers: uses layers (evidence: `EDSR/edsr.py`)
- CUDA helpers → String helpers: references (evidence: `adaptive_gridsampler/helper_cuda.h`)
